Cursor Rules Template: Django Payroll Dashboard with Timesheets, Deductions, Approvals and Exportable Reports
Cursor Rules Template for Django payroll dashboard with timesheets, deductions, approvals and exportable reports. Includes a copyable .cursorrules block and stack-specific guidance.
Target User
Backend engineers and full-stack developers building payroll dashboards with Django and PostgreSQL
Use Cases
- Payroll dashboard with timesheets
- Deductions and benefits calculation
- Manager and HR approvals workflow
- Exportable reports (CSV/Excel)
Markdown Template
Cursor Rules Template: Django Payroll Dashboard with Timesheets, Deductions, Approvals and Exportable Reports
.cursorrules
Framework Role & Context
- You are a Django backend assistant tasked with implementing a payroll dashboard with timesheets, deductions, approvals, and exportable reports. The project uses Python 3.11+ with Django ORM and PostgreSQL. Provide production-ready patterns and safe AI-assisted edits.
Code Style and Style Guides
- Follow PEP8, Black, and isort. Use type hints where appropriate. Document public APIs with docstrings. Adhere to Django’s style conventions for models, views, and templates.
Architecture & Directory Rules
- Project layout: Django project with apps/payroll and apps/reports. Core logic lives in payroll.models, payroll.views, and reports.exporters. Use Django settings modules per environment. Avoid mixing app responsibilities.
Authentication & Security Rules
- Leverage Django's authentication and permissions. Enforce object-level permissions for payroll records. Do not bypass CSRF protections. Store secrets in environment variables; avoid hard-coding credentials. Audit logs for sensitive actions.
Database and ORM patterns
- Use Django ORM, models with ForeignKeys, and proper indexing. Favor select_related and prefetch_related to minimize queries. Use transactions for payroll calculations and batch exports.
Testing & Linting Workflows
- Use pytest-django or Django’s test framework. Include unit tests for models, views, and serializers. Run linting with flake8 and formatting with Black in CI. Ensure tests run in isolation with a test database.
Prohibited Actions and Anti-patterns for the AI
- Do not generate raw SQL outside of parameterized queries. Do not perform operations that bypass ORM safety nets. Do not log PII. Do not skip migrations or rely on ephemeral schemas. Avoid N+1 query patterns and unsafe data exports without validation.Overview
The Cursor rules configuration provides a concrete, copyable setup for building a Django-based payroll dashboard featuring timesheets, deductions, approvals, and exportable reports. It targets a Django + PostgreSQL stack and includes a ready-to-paste .cursorrules block, project structure guidance, and stack-specific constraints to ensure safe, production-oriented AI guidance.
Direct answer: This template yields a complete Cursor AI instruction set and project layout you can paste into your repo to accelerate secure, maintainable payroll dashboard development.
When to Use These Cursor Rules
- When implementing a payroll dashboard in Django with timesheets, deductions, and approvals.
- When you need exportable reports in CSV/Excel formats for payroll cycles.
- When enforcing strict security and role-based access for payroll data.
- When you want a reproducible project structure and CI-friendly testing workflow.
Copyable .cursorrules Configuration
.cursorrules
Framework Role & Context
- You are a Django backend assistant tasked with implementing a payroll dashboard with timesheets, deductions, approvals, and exportable reports. The project uses Python 3.11+ with Django ORM and PostgreSQL. Provide production-ready patterns and safe AI-assisted edits.
Code Style and Style Guides
- Follow PEP8, Black, and isort. Use type hints where appropriate. Document public APIs with docstrings. Adhere to Django’s style conventions for models, views, and templates.
Architecture & Directory Rules
- Project layout: Django project with apps/payroll and apps/reports. Core logic lives in payroll.models, payroll.views, and reports.exporters. Use Django settings modules per environment. Avoid mixing app responsibilities.
Authentication & Security Rules
- Leverage Django's authentication and permissions. Enforce object-level permissions for payroll records. Do not bypass CSRF protections. Store secrets in environment variables; avoid hard-coding credentials. Audit logs for sensitive actions.
Database and ORM patterns
- Use Django ORM, models with ForeignKeys, and proper indexing. Favor select_related and prefetch_related to minimize queries. Use transactions for payroll calculations and batch exports.
Testing & Linting Workflows
- Use pytest-django or Django’s test framework. Include unit tests for models, views, and serializers. Run linting with flake8 and formatting with Black in CI. Ensure tests run in isolation with a test database.
Prohibited Actions and Anti-patterns for the AI
- Do not generate raw SQL outside of parameterized queries. Do not perform operations that bypass ORM safety nets. Do not log PII. Do not skip migrations or rely on ephemeral schemas. Avoid N+1 query patterns and unsafe data exports without validation.
Recommended Project Structure
PayrollProject/
├── manage.py
├── payroll_dashboard/
│ ├── __init__.py
│ ├── settings.py
│ ├── urls.py
│ └── wsgi.py
├── apps/
│ ├── payroll/
│ │ ├── __init__.py
│ │ ├── models.py
│ │ ├── views.py
│ │ ├── urls.py
│ │ ├── templates/
│ │ │ └── payroll/
│ │ │ ├── dashboard.html
│ │ │ ├── timesheets.html
│ │ │ └── deductions.html
│ │ └── migrations/
│ └── reports/
│ ├── __init__.py
│ ├── exporters.py
│ └── templates/
├── requirements.txt
├── .env
├── tests/
│ ├── test_models.py
│ ├── test_views.py
│ └── __init__.py
Core Engineering Principles
- Explicit, auditable data flows for payroll calculations.
- Idempotent Cursor AI guidance with clear boundaries between rules and code.
- Separation of concerns: keep business logic in Django apps, not in AI prompts.
- Testable by design: unit, integration, and end-to-end tests for payroll cycles.
- Security-first: enforce strict access controls and protect PII in logs and exports.
Code Construction Rules
- Use Django ORM for all data operations; avoid raw SQL unless parameterized and audited.
- Wrap writes to payroll data in atomic transactions to ensure consistency.
- Define clear model constraints (unique_together, check constraints) for payroll validation.
- Adopt Django form/serializer patterns for data input and export pipelines.
- Keep business logic out of views; place in services or model methods with clean interfaces.
Security and Production Rules
- Use Django’s authentication and permissions to restrict payroll access by role.
- Store secrets in environment variables; rotate keys and audit access logs.
- Validate all inputs and escapes in exports to prevent injection vulnerabilities.
- Enable CSRF protection for state-changing endpoints; disable hard-coded credentials.
- Regularly back up the database and implement access-controlled export pipelines.
Testing Checklist
- Unit tests for models and payroll calculation logic.
- Integration tests for timesheet, deduction, and approval workflows.
- End-to-end tests simulating a payroll cycle including report export.
- Static analysis with Flake8/Black; type checking with Mypy where applicable.
- CI pipeline runs migrations, tests, and linting on push/PR.
Common Mistakes to Avoid
- Relying on raw SQL that bypasses ORM safety and migrations.
- Storing PII in logs or in insecure export processes.
- Introducing N+1 queries in payroll calculation paths.
- Overloading views with business logic or skipping tests for critical paths.
- Hard-coding environment-specific settings; avoid embedding secrets in code.
Related Cursor rules templates
Explore adjacent Cursor rules templates for similar stacks, workflows, and production constraints.
- Cursor Rules Template: Django Subscription Box Platform
- Cursor Rules Template for Fitness Trainer SaaS
- Cursor Rules Template: ERP Dashboard with Next.js, PostgreSQL, Prisma, Clerk and Shadcn UI
- Cursor Rules Template: Manufacturing Execution Dashboard (NestJS + PostgreSQL)
FAQ
What is a Cursor Rules Template for a Django payroll dashboard?
A Cursor Rules Template provides a copyable .cursorrules block and stack-specific guidance to implement a Django-based payroll dashboard. It covers timesheets, deductions, approvals, and exportable reports, plus project structure and security practices tailored to the Django + PostgreSQL stack.
How do I customize timesheet and deduction mappings in this template?
Modify the Django models (Timesheet and Deduction) and their related forms/serializers to reflect your payroll schema. Ensure field mappings align with your export formats and reporting requirements, and run migrations after changes.
How can I export payroll reports from this setup?
Implement export endpoints using Django views that query related payroll data and generate CSV or Excel files. Use streaming responses for large exports and validate data integrity before writing files to ensure accurate reports for payroll cycles.
Is this safe for production use in a multi-tenant environment?
The template emphasizes Django's authentication and permissions, strict data access controls, and secure export workflows. For multi-tenant deployments, layer on isolated schemas or row-level security and enforce tenant scoping in ORM queries.
What tests should I add to verify payroll calculations?
Write unit tests for the calculation logic (hours, deductions, tax withholdings) and integration tests for the full payroll cycle, including approvals and report generation. Ensure deterministic inputs and cover edge cases like payroll period boundaries.