Cursor Rules TemplatesCursor Rules Template

Cursor Rules Template: FastAPI + SQLAlchemy Delivery Generators

A Cursor Rules Template for a FastAPI + SQLAlchemy stack to generate reusable delivery templates for professional service firms, including a copyable .cursorrules block.

cursor-rulescursorrulesfastapisqlalchemypostgresqldelivery-templatestemplate-generatorprofessional-servicesarchitecturesecuritytesting

Target User

Developers building reusable delivery template generators for professional service firms

Use Cases

  • Generate client-ready delivery templates for engagements
  • Automate scoping and proposal templates
  • Standardize project delivery communications
  • Template-driven knowledge management

Markdown Template

Cursor Rules Template: FastAPI + SQLAlchemy Delivery Generators

Overview

This Cursor Rules Template targets building reusable delivery template generators on a Python stack using FastAPI with SQLAlchemy and PostgreSQL. It defines a framework context, code style, and architecture guidance tailored for professional service firms that need repeatable delivery artifacts—proposals, engagement plans, and client-ready templates—while leveraging Cursor AI for acceleration and governance.

When to Use These Cursor Rules

- When you need a repeatable delivery template generator for multiple clients and engagements.
- When standardizing project scoping, proposals, and work plans across teams.
- When you want automated scaffolding that enforces architecture and security patterns.
- When integrating Cursor AI into your CI/CD for consistent outputs.
Copyable .cursorrules Configuration

framework: python-fastapi-sqlalchemy
stack: fastapi + sqlalchemy + postgresql
role_context: Framework Engineer and Architect for Cursor AI
framework_rules:
  code_style:
    - black
    - isort
    - ruff
architecture:
  - src/app/main.py
  - src/app/api/
  - src/app/models/
  - src/app/schemas/
  - tests/
  - alembic/
authentication:
  strategy: oauth2-jwt
  token_expiry: 3600
database:
  orm: sqlalchemy
  migrations: alembic
testing:
  unit: true
  integration: true
  ci_cd: github-actions
security:
  secrets: ENV
  envs: DATABASE_URL, SECRET_KEY
prohibited_actions:
  - prisma
  - mongoose
  - drizzle
notes:
  - avoid dynamic code execution in templates
  - parameterize all DB queriesRecommended Project Structure

project/
  app/
    main.py
    api/
      templates.py
      endpoints/
    models/
    schemas/
    services/
  tests/
  config/
  migrations/
  Alembic.ini
  pyproject.tomlCore Engineering Principles

- Clear separation of concerns across API, domain, and data layers.
- Deterministic behavior with idempotent template generation.
- Strong typing and validation via Pydantic models and type hints.
- Defensible security posture by default (env vars, scoped access, and audits).
- Observability: structured logging, metrics, and tracing for templates.
- Test-driven approach for core generator logic and migrations.
- Reusability and composability of delivery components across clients.
Code Construction Rules

- Use FastAPI routers and dependency injection for clear modules.
- Model inputs/outputs with Pydantic schemas; validate all inputs.
- Persist schema changes with Alembic migrations; keep migrations as code.
- All DB access must be parameterized; avoid string concatenation in SQL.
- Do not use dynamic code execution; avoid eval/exec in templates.
- Secrets and credentials must come from environment variables only.
- Follow Black formatting, isort for imports, and Ruff for linting.
- Do not couple the template generator to a specific client; design for reuse.
Security and Production Rules

- JWT-based OAuth2 tokens with short expiry; rotate keys regularly.
- Store secrets in environment variables; never commit them.
- HTTPS in all environments; enforce secure cookies and CSRF protection for browser apps.
- Limit concurrency and use DB connection pooling; monitor for leaks.
- Sanitize all user input; encode outputs to avoid injection in templates.
- Audit logs redacting sensitive data; ensure traceability of template generation.
Testing Checklist

- Unit tests for core generator functions and utility modules.
- Integration tests validating ORM interactions and migrations.
- End-to-end tests verifying template generation outputs for sample inputs.
- Static analysis and type checking in CI (mypy/ruff).
- Security tests for token handling and input validation.
Common Mistakes to Avoid

- Overfitting templates to a single client or project.
- Directly echoing user input into templates without validation.
- Relying on non-parameterized SQL queries.
- Storing secrets in code or logs; failing to rotate keys.
- Neglecting migrations in the deployment process.
FAQ

What is a Cursor Rules Template for this stack?

A Cursor Rules Template is a copyable configuration that guides Cursor AI to generate reusable delivery templates for FastAPI + SQLAlchemy projects aimed at professional service firms, covering architecture, security, testing, and deployment practices.

How do I paste the .cursorrules block into my project?

Copy the entire block within the Copyable .cursorrules Configuration section and place it in a file named .cursorrules at your project root. Then run Cursor AI to ingest and apply the rules to your repository.

Can these rules adapt to other Python stacks or ORMs?

Yes. Replace the stack tag and ORM specifics (for example, Django ORM or SQLModel) and adjust authentication, migrations, and testing accordingly. The structure remains the same to preserve governance and reusability.

What should I include in tests for this stack?

Unit tests for generator utilities, integration tests for ORM interactions and migrations, and end-to-end tests that verify generated templates match client requirements. Include CI checks for linting and type checks.

What security considerations are included?

Use OAuth2 with JWT, store secrets in environment variables, validate inputs with Pydantic, and redact sensitive data in logs. Avoid executing dynamic code and keep secret rotation in CI/CD processes.



Related implementation resources: AI Use Case for Software Agencies Using Github Copilot To Accelerate Boilerplate Code Generation for New Client Mvps.

Overview

This Cursor Rules Template targets building reusable delivery template generators on a Python stack using FastAPI with SQLAlchemy and PostgreSQL. It defines a framework context, code style, and architecture guidance tailored for professional service firms that need repeatable delivery artifacts—proposals, engagement plans, and client-ready templates—while leveraging Cursor AI for acceleration and governance.

When to Use These Cursor Rules

  • When you need a repeatable delivery template generator for multiple clients and engagements.
  • When standardizing project scoping, proposals, and work plans across teams.
  • When you want automated scaffolding that enforces architecture and security patterns.
  • When integrating Cursor AI into your CI/CD for consistent outputs.

Copyable .cursorrules Configuration

framework: python-fastapi-sqlalchemy
stack: fastapi + sqlalchemy + postgresql
role_context: Framework Engineer and Architect for Cursor AI
framework_rules:
  code_style:
    - black
    - isort
    - ruff
architecture:
  - src/app/main.py
  - src/app/api/
  - src/app/models/
  - src/app/schemas/
  - tests/
  - alembic/
authentication:
  strategy: oauth2-jwt
  token_expiry: 3600
database:
  orm: sqlalchemy
  migrations: alembic
testing:
  unit: true
  integration: true
  ci_cd: github-actions
security:
  secrets: ENV
  envs: DATABASE_URL, SECRET_KEY
prohibited_actions:
  - prisma
  - mongoose
  - drizzle
notes:
  - avoid dynamic code execution in templates
  - parameterize all DB queries

Recommended Project Structure

project/
  app/
    main.py
    api/
      templates.py
      endpoints/
    models/
    schemas/
    services/
  tests/
  config/
  migrations/
  Alembic.ini
  pyproject.toml

Core Engineering Principles

  • Clear separation of concerns across API, domain, and data layers.
  • Deterministic behavior with idempotent template generation.
  • Strong typing and validation via Pydantic models and type hints.
  • Defensible security posture by default (env vars, scoped access, and audits).
  • Observability: structured logging, metrics, and tracing for templates.
  • Test-driven approach for core generator logic and migrations.
  • Reusability and composability of delivery components across clients.

Code Construction Rules

  • Use FastAPI routers and dependency injection for clear modules.
  • Model inputs/outputs with Pydantic schemas; validate all inputs.
  • Persist schema changes with Alembic migrations; keep migrations as code.
  • All DB access must be parameterized; avoid string concatenation in SQL.
  • Do not use dynamic code execution; avoid eval/exec in templates.
  • Secrets and credentials must come from environment variables only.
  • Follow Black formatting, isort for imports, and Ruff for linting.
  • Do not couple the template generator to a specific client; design for reuse.

Security and Production Rules

  • JWT-based OAuth2 tokens with short expiry; rotate keys regularly.
  • Store secrets in environment variables; never commit them.
  • HTTPS in all environments; enforce secure cookies and CSRF protection for browser apps.
  • Limit concurrency and use DB connection pooling; monitor for leaks.
  • Sanitize all user input; encode outputs to avoid injection in templates.
  • Audit logs redacting sensitive data; ensure traceability of template generation.

Testing Checklist

  • Unit tests for core generator functions and utility modules.
  • Integration tests validating ORM interactions and migrations.
  • End-to-end tests verifying template generation outputs for sample inputs.
  • Static analysis and type checking in CI (mypy/ruff).
  • Security tests for token handling and input validation.

Common Mistakes to Avoid

  • Overfitting templates to a single client or project.
  • Directly echoing user input into templates without validation.
  • Relying on non-parameterized SQL queries.
  • Storing secrets in code or logs; failing to rotate keys.
  • Neglecting migrations in the deployment process.

FAQ

What is a Cursor Rules Template for this stack?

A Cursor Rules Template is a copyable configuration that guides Cursor AI to generate reusable delivery templates for FastAPI + SQLAlchemy projects aimed at professional service firms, covering architecture, security, testing, and deployment practices.

How do I paste the .cursorrules block into my project?

Copy the entire block within the Copyable .cursorrules Configuration section and place it in a file named .cursorrules at your project root. Then run Cursor AI to ingest and apply the rules to your repository.

Can these rules adapt to other Python stacks or ORMs?

Yes. Replace the stack tag and ORM specifics (for example, Django ORM or SQLModel) and adjust authentication, migrations, and testing accordingly. The structure remains the same to preserve governance and reusability.

What should I include in tests for this stack?

Unit tests for generator utilities, integration tests for ORM interactions and migrations, and end-to-end tests that verify generated templates match client requirements. Include CI checks for linting and type checks.

What security considerations are included?

Use OAuth2 with JWT, store secrets in environment variables, validate inputs with Pydantic, and redact sensitive data in logs. Avoid executing dynamic code and keep secret rotation in CI/CD processes.

Related implementation resources: AI Use Case for Software Agencies Using Github Copilot To Accelerate Boilerplate Code Generation for New Client Mvps.