Cursor Rules TemplatesCursor Rules Template

Quality Control Inspections Cursor Rules Template for a QC Platform

Cursor Rules Template for a Python FastAPI based quality control platform focusing on inspections, defects, root cause analysis, and AI generated reports.

.cursorrules templatecursor rules templatequality controlinspectionsdefectsroot cause analysisai reportspython fastapisqlalchemypostgresqlcursor ai rules

Target User

Backend engineers and SREs building a QC platform with inspections and AI reports

Use Cases

  • Define rule-driven data capture for inspections
  • Model defects and root cause associations
  • Automate AI-generated inspection reports
  • Audit and compliance of inspection data

Markdown Template

Quality Control Inspections Cursor Rules Template for a QC Platform

cursor_rules:
  framework_role: 'You are Cursor AI assistant configured to implement a Python FastAPI QC platform.'
  context: 'Quality control platform for inspections, defects, root cause analysis, and AI generated reports'
  code_style: 
    - 'Black'
    - 'isort'
    - 'Pydantic'
    - 'mypy'
  architecture_and_directories:
    - 'backend/app/main.py'
    - 'backend/app/api/v1/routers/inspection.py'
    - 'backend/app/models/inspection.py'
    - 'backend/app/services/inspection_service.py'
  authentication_and_security:
    jwt: true
    roles: [ 'inspector', 'supervisor', 'manager', 'admin' ]
    access_control: 'RBAC at router level'
  database_and_orm:
    orm: 'SQLAlchemy 2.0'
    dialect: 'PostgreSQL'
    models: [ 'Inspection', 'Defect', 'RootCause', 'Report' ]
  testing_and_ci:
    tests: [ 'pytest', 'pytest -k unit', 'pytest -k integration' ]
    linters: [ 'black --check', 'isort --check', 'flake8' ]
    ci: 'GitHub Actions workflow for tests and lint'
  prohibited_actions:
    - 'Disable migrations during deployment'
    - 'Use dynamic SQL without parameters'
    - 'Log PII data'
    - 'Skip input validation'

Overview

Cursor rules configuration for a quality control platform built with Python FastAPI, PostgreSQL, and SQLAlchemy. It covers inspections, defects tracking, root cause analysis, and AI generated reports using Cursor AI rules. This Cursor Rules Template provides a ready-to-paste .cursorrules instruction block you can drop into your project root. This Cursor rules template is designed to be pasted into a Python FastAPI QC project to accelerate rule-based encoding of your QA workflows.

When to Use These Cursor Rules

  • When modeling inspections data and defect records for traceability
  • When enforcing RBAC and secure API boundaries for QA personnel
  • When standardizing data formats for AI report generation
  • When integrating SQLAlchemy ORM patterns with Alembic migrations
  • When validating test and deployment pipelines for a QC platform

Copyable .cursorrules Configuration

cursor_rules:
  framework_role: 'You are Cursor AI assistant configured to implement a Python FastAPI QC platform.'
  context: 'Quality control platform for inspections, defects, root cause analysis, and AI generated reports'
  code_style: 
    - 'Black'
    - 'isort'
    - 'Pydantic'
    - 'mypy'
  architecture_and_directories:
    - 'backend/app/main.py'
    - 'backend/app/api/v1/routers/inspection.py'
    - 'backend/app/models/inspection.py'
    - 'backend/app/services/inspection_service.py'
  authentication_and_security:
    jwt: true
    roles: [ 'inspector', 'supervisor', 'manager', 'admin' ]
    access_control: 'RBAC at router level'
  database_and_orm:
    orm: 'SQLAlchemy 2.0'
    dialect: 'PostgreSQL'
    models: [ 'Inspection', 'Defect', 'RootCause', 'Report' ]
  testing_and_ci:
    tests: [ 'pytest', 'pytest -k unit', 'pytest -k integration' ]
    linters: [ 'black --check', 'isort --check', 'flake8' ]
    ci: 'GitHub Actions workflow for tests and lint'
  prohibited_actions:
    - 'Disable migrations during deployment'
    - 'Use dynamic SQL without parameters'
    - 'Log PII data'
    - 'Skip input validation'

Recommended Project Structure

backend/
  app/
    main.py
    api/
      v1/
        routers/
          inspection.py
          defect.py
          root_cause.py
          report.py
    core/
      config.py
      security.py
    models/
      inspection.py
      defect.py
      root_cause.py
      report.py
    services/
      inspection_service.py
      defect_service.py
      root_cause_service.py
      report_service.py
    schemas/
      inspection_schema.py
      defect_schema.py
      root_cause_schema.py
      report_schema.py
  alembic/
  migrations/
  requirements.txt

Core Engineering Principles

  • Single source of truth for data models and API contracts
  • Explicit, typed interfaces across layers (schemas, services, handlers)
  • Principled security with RBAC and audit logs
  • Deterministic behavior through deterministic data flows and tests
  • Observable software with structured logging and metrics

Code Construction Rules

  • Define ORM models using SQLAlchemy declarative base with relationships that reflect inspections, defects, and root causes
  • Use Pydantic models for input validation and response schemas
  • All DB access must use parameterized queries through SQLAlchemy session
  • Endpoints must enforce authentication and role-based access control
  • Avoid circular imports by isolating domain logic into services
  • Do not store binary large objects in the DB; store references or files in blob storage

Security and Production Rules

  • Use JWTs with short-lived access tokens and refresh tokens
  • Enforce RBAC for all mutation endpoints (inspections, defects, root cause updates)
  • Sanitize all inputs and validate data against schemas before persistence
  • Enable CSRF protection for state-changing requests where applicable
  • Encrypt sensitive fields at rest and in transit; log only non-sensitive metadata

Testing Checklist

  • Unit tests for models, services, and utilities
  • Integration tests covering end-to-end inspection workflows
  • Migration tests for Alembic change scripts
  • Linting and type-checking in CI (Black, isort, Flake8, mypy)
  • Static analysis for security (dependency checks, secret scanning)

Common Mistakes to Avoid

  • Skipping input validation leading to injection risks
  • Hard-coding IDs or secrets in code or configs
  • Mixing business logic with route handlers
  • Relying on dynamic SQL without parameterization
  • Neglecting migrations or breaking schema compatibility

Related Cursor rules templates

Explore adjacent Cursor rules templates for similar stacks, workflows, and production constraints.

FAQ

What is the purpose of this Cursor Rules Template?

This Cursor rules template provides a concrete configuration for building a Python FastAPI QC platform. It encodes best practices for data models, API layers, authentication, and AI-generated reports, enabling teams to paste a ready set of rules into their project and iterate safely.

Which stack targets this template?

The template targets a Python FastAPI backend with PostgreSQL and SQLAlchemy. It defines RBAC, ORM patterns, and a workflow for inspections, defects, root cause analysis, and AI report generation using Cursor AI.

What should I paste into the Copyable block?

The block defines framework role, context, style, architecture, authentication, database patterns, tests, and prohibited actions. It is designed to be dropped into the repository as a high-fidelity guide for implementing the QC workflow and AI reporting.

How should I structure the project for a QC platform?

Follow the recommended project structure in the template: a Python FastAPI backend with clear modules for API routers, models, services, schemas, and a migrations folder. Separate concerns to ensure testability and maintainability of inspections, defects, root cause analysis, and AI reports.

How do I handle security and data access?

Use JWT-based authentication with role-based access control, enforce authorization at the router level, validate all inputs, and avoid logging sensitive data. Use encrypted fields for sensitive information and separate audit trails for changes to inspections and defects.