Cursor Rules Template for AI Bookkeeping with Python FastAPI & PostgreSQL
Cursor rules template for building an AI bookkeeping assistant using Python FastAPI and PostgreSQL. A copyable Cursor rules configuration to guide transaction categorization and monthly reporting.
Target User
Developers building AI bookkeeping assistants using Python FastAPI and PostgreSQL with Cursor AI
Use Cases
- Classify transactions into categories (income, expense, tax) with vendor recognition
- Generate monthly financial reports (P&L, balance sheet, cash flow)
- Maintain an auditable transaction log
- Export categorized data to CSV/Parquet
- Provide API endpoints for ingestion and reporting
- Validate data quality and highlight anomalies
Markdown Template
Cursor Rules Template for AI Bookkeeping with Python FastAPI & PostgreSQL
Framework Role & Context
You are a Cursor AI assistant specialized for building a Python FastAPI backend with PostgreSQL. You will implement an AI driven bookkeeping assistant that categorizes transactions and generates monthly reports. Your role is to produce precise, testable code, safe prompts, and deterministic results.
Code Style and Style Guides
Follow PEP 8 with type hints. Use black and isort formatting. Document public APIs with docstrings. Do not rely on dynamic eval.
Architecture & Directory Rules
Project root contains src/app with modules for api, models, schemas, services, and tests. Use SQLAlchemy models in src/app/db/models and a separate services layer for business logic. Migrations via Alembic in alembic/
Authentication & Security Rules
JWT based authentication for API endpoints. Secrets loaded from environment variables. Do not log secrets. Use OAuth2 if available. Use HTTPS in production.
Database and ORM patterns
SQLAlchemy models with declarative_base. Session management via sessionmaker. Use migrations for schema changes. Keep transactions wrapped in context managers to ensure rollback on errors.
Testing & Linting Workflows
Use pytest with pytest-asyncio for async calls. Include unit tests for categorization logic and integration tests for endpoints. Run linting via flake8 and type checking via mypy in CI.
Prohibited Actions and Anti-patterns for the AI
Do not generate raw SQL that concatenates user input. Do not bypass ORM in critical paths. Do not rely on runtime configuration values that can be manipulated. Do not access network resources from production prompts without validation.Overview
The Cursor rules configuration is a copyable .cursorrules block that guides Cursor AI when building an AI bookkeeping assistant for a Python FastAPI and PostgreSQL stack. It defines roles, constraints, and workflow for transaction categorization and monthly report generation.
When to Use These Cursor Rules
- Starting a new AI bookkeeping project using Python FastAPI and PostgreSQL
- Seeking a reusable, testable, auditable Cursor AI prompt suite
- Need consistent transaction categorization and monthly reports across environments
Copyable .cursorrules Configuration
Framework Role & Context
You are a Cursor AI assistant specialized for building a Python FastAPI backend with PostgreSQL. You will implement an AI driven bookkeeping assistant that categorizes transactions and generates monthly reports. Your role is to produce precise, testable code, safe prompts, and deterministic results.
Code Style and Style Guides
Follow PEP 8 with type hints. Use black and isort formatting. Document public APIs with docstrings. Do not rely on dynamic eval.
Architecture & Directory Rules
Project root contains src/app with modules for api, models, schemas, services, and tests. Use SQLAlchemy models in src/app/db/models and a separate services layer for business logic. Migrations via Alembic in alembic/
Authentication & Security Rules
JWT based authentication for API endpoints. Secrets loaded from environment variables. Do not log secrets. Use OAuth2 if available. Use HTTPS in production.
Database and ORM patterns
SQLAlchemy models with declarative_base. Session management via sessionmaker. Use migrations for schema changes. Keep transactions wrapped in context managers to ensure rollback on errors.
Testing & Linting Workflows
Use pytest with pytest-asyncio for async calls. Include unit tests for categorization logic and integration tests for endpoints. Run linting via flake8 and type checking via mypy in CI.
Prohibited Actions and Anti-patterns for the AI
Do not generate raw SQL that concatenates user input. Do not bypass ORM in critical paths. Do not rely on runtime configuration values that can be manipulated. Do not access network resources from production prompts without validation.
Recommended Project Structure
project-root/
├─ src/
│ ├─ app/
│ │ ├─ main.py
│ │ ├─ api/
│ │ │ └─ v1/
│ │ │ ├─ endpoints/
│ │ │ │ ├─ transactions.py
│ │ │ │ └─ reports.py
│ │ ├─ core/
│ │ │ ├─ config.py
│ │ │ └─ security.py
│ │ ├─ db/
│ │ │ ├─ base.py
│ │ │ └─ models/
│ │ │ ├─ account.py
│ │ │ └─ transaction.py
│ │ ├─ services/
│ │ │ ├─ categorization.py
│ │ │ └─ reporting.py
│ │ └─ schemas/
│ │ ├─ transaction.py
│ │ └─ report.py
│ ├─ tests/
│ │ ├─ test_transactions.py
│ │ └─ test_reports.py
│ └─ alembic/
├─ .env
├─ requirements.txt
├─ Dockerfile
Core Engineering Principles
- Single source of truth for rule sets and category mappings
- Deterministic, testable AI decisions with clear prompts
- Security by default and least privilege access
- Strong typing and strict linting
- Auditable transaction categorization and reporting
- CI/CD with automated tests and quality gates
Code Construction Rules
Implement the stack with explicit typing and error handling. Use SQLAlchemy for ORM, Pydantic for schemas, and FastAPI for endpoints. Ensure the .cursorrules configuration enforces the exact workflow for categorization and monthly report generation.
Security and Production Rules
Environment based configuration, secrets management, and secure defaults. No secrets in code, rotate credentials, and enforce TLS in production. Validate inputs at API boundaries and apply role based access controls.
Testing Checklist
- Unit tests for categorization logic including edge cases
- Integration tests for API endpoints and DB interactions
- End-to-end tests for producing a full monthly report
- Static type checking in CI and linting
Common Mistakes to Avoid
- Overly broad transaction categorization rules that cause mislabeling
- Skipping migrations or direct DB schema changes in production
- Not handling time zones in monthly report generation
- Using raw SQL without parameterization
Related Cursor rules templates
Explore adjacent Cursor rules templates for similar stacks, workflows, and production constraints.
- Cursor Rules Template: IoT Water Monitoring with FastAPI & PostgreSQL
- Cursor Rules Template: Personal AI OS with Notes, Tasks, Calendar, Memory and Chat (FastAPI + PostgreSQL)
- Cursor Rules Template: Python FastAPI LangChain Postgres AI Research Assistant
- Cursor Rules Template — Real Estate Dashboard with Cash Flow, ROI, and Analytics
FAQ
What is a Cursor rules template for AI bookkeeping?
A Cursor rules template provides a copyable .cursorrules configuration that guides Cursor AI to implement a stack specific AI bookkeeping assistant. It defines roles, architecture, data flows, tests, and security rules for a Python FastAPI plus PostgreSQL setup.
Which stack does this Cursor Rules Template cover?
This template targets a Python FastAPI backend with PostgreSQL via SQLAlchemy, using Cursor AI to classify transactions and generate monthly financial reports.
Can I customize transaction categorization rules in this template?
Yes. The template defines how to extend and customize category mappings, vendor matching, and rule based fallbacks while preserving a safe AI inference path and auditability.
How do I validate the AI output before production?
The template includes unit tests, data validation rules, and integration checks that exercise categorization, reporting generation, and API endpoints using real or synthetic data.
What security considerations are included?
The template enforces JWT based authentication, least privilege access, parameterized queries, and environment based configurations to minimize secrets exposure in production.