Cursor Rules TemplatesCursor Rules Template

Cursor Rules Template: Packaging Quality Inspection with Defect Images & Rejection Logs

Copyable Cursor Rules Template for building packaging quality inspection AI apps using defect images and rejection logs. Includes a full .cursorrules block and stack-specific project guidance.

cursor-rules-templatecursor-rulespackaging-qaquality-inspectiondefect-detectionrejection-logspython-fastapiopencvpytorchpostgresqlsqlalchemy

Target User

Backend engineers and AI engineers building packaging QA apps

Use Cases

  • Defect image classification and detection
  • Auto-triage using rejection logs
  • Audit-friendly automated QC
  • Model evaluation with defect datasets

Markdown Template

Cursor Rules Template: Packaging Quality Inspection with Defect Images & Rejection Logs

framework: Python FastAPI + PyTorch/OpenCV stack
role: Cursor AI assisting the engineering team to implement a packaging QA app using defect images and rejection logs
context: Your job is to produce reliable, maintainable code ideas and rules for this stack, not to write end-user UI content.
style-guides: PEP8, Black, isort, and mypy
architecture:
  base_dir: src
  modules:
    - api
    - data
    - models
    - services
    - workers
  directory_rules:
    - src/api/v1/
    - src/data/
    - src/models/
auth-security:
  method: OAuth2 with JWT tokens
  token_expiry: 15m
  tls: true
database:
  orm: SQLAlchemy
  database_url_env: DATABASE_URL
  strategy: PostgreSQL
patterns:
  model_infers:
    - defect_classifier
    - defect_detector
data_pipelines:
  ingestion:
    - images/defects/
    - logs/rejections.csv
  storage: S3-compatible or local blob storage
testing:
  unit: true
  integration: true
  linting: true
lints:
  pre_commit: true
anti_patterns:
  - Do not access local image files directly from business logic without a defined data layer.
  - Do not bypass authentication checks in API handlers.
  - Do not hardcode secrets or credentials in code or rules.
security:
  substrate: JWT + OAuth2
  secrets_manager: AWS Secrets Manager / Vault
prohibited_actions:
  - No GUI-only rules; avoid UI thinking in AI decisions.
  - Do not enable insecure endpoints or permissive CORS in prod.

Overview

Cursor rules configuration for building packaging quality inspection apps that use defect images and rejection logs. This Cursor Rules Template targets a Python FastAPI + OpenCV/PyTorch stack with PostgreSQL via SQLAlchemy and defines a repeatable guardrail for AI-assisted QA on manufacturing lines.

Direct answer: This Cursor Rules Template provides a complete, copyable .cursorrules block and stack-specific guidance to build an AI-powered packaging quality inspection app that analyzes defect images and logs rejections, enforced by Cursor AI rules.

When to Use These Cursor Rules

  • When building an AI-powered quality inspection system that ingests defect images from packaging lines.
  • When rejection logs must drive AI decisions and audit trails.
  • When you require reproducible architecture, security controls, and CI/CD for ML components.

Copyable .cursorrules Configuration

framework: Python FastAPI + PyTorch/OpenCV stack
role: Cursor AI assisting the engineering team to implement a packaging QA app using defect images and rejection logs
context: Your job is to produce reliable, maintainable code ideas and rules for this stack, not to write end-user UI content.
style-guides: PEP8, Black, isort, and mypy
architecture:
  base_dir: src
  modules:
    - api
    - data
    - models
    - services
    - workers
  directory_rules:
    - src/api/v1/
    - src/data/
    - src/models/
auth-security:
  method: OAuth2 with JWT tokens
  token_expiry: 15m
  tls: true
database:
  orm: SQLAlchemy
  database_url_env: DATABASE_URL
  strategy: PostgreSQL
patterns:
  model_infers:
    - defect_classifier
    - defect_detector
data_pipelines:
  ingestion:
    - images/defects/
    - logs/rejections.csv
  storage: S3-compatible or local blob storage
testing:
  unit: true
  integration: true
  linting: true
lints:
  pre_commit: true
anti_patterns:
  - Do not access local image files directly from business logic without a defined data layer.
  - Do not bypass authentication checks in API handlers.
  - Do not hardcode secrets or credentials in code or rules.
security:
  substrate: JWT + OAuth2
  secrets_manager: AWS Secrets Manager / Vault
prohibited_actions:
  - No GUI-only rules; avoid UI thinking in AI decisions.
  - Do not enable insecure endpoints or permissive CORS in prod.

Recommended Project Structure

project-root/
  src/
    api/
      v1/
        endpoints/
        routers/
        schemas/
    data/
      defects/
      logs/
      images/
    models/
    services/
  tests/
  scripts/

Core Engineering Principles

  • Single source of truth for data, models, and rules; clear ownership of defects and rejections.
  • Deterministic behavior; rule-driven decisions with explicit fallbacks.
  • Explicit data validation and typed interfaces (pydantic models).
  • Secure by default: least privilege, secrets management, and encrypted transport.
  • Observability: structured logging, metrics, and tracing for model inferences.

Code Construction Rules

  • Use SQLAlchemy ORM for DefectImage and RejectionLog models; keep image metadata in DB and store images in object storage with URIs.
  • API endpoints under src/api/v1; use FastAPI with dependency injection for auth and DB sessions.
  • Model inferences run in a background task; separate inference service from request handlers.
  • Define strict pydantic schemas for input data (defect samples, logs) and outputs (QA verdicts).
  • Tests cover unit, integration, and end-to-end flows including image ingestion and rejection correlation.
  • Do not bypass data validation or error handling in endpoints.

Security and Production Rules

  • Enable TLS everywhere; require OAuth2 with JWT tokens for API access.
  • Store secrets in a managed vault or AWS Secrets Manager; rotate credentials regularly.
  • Isolate ML services in a separate network; use RBAC to restrict access to data stores.
  • Audit logs and model inference events; redact sensitive fields in logs where appropriate.

Testing Checklist

  • Unit tests for data models, validators, and inference helpers.
  • Integration tests for API endpoints including authentication, data ingestion, and DB writes.
  • Inference tests with sample defect images to validate detector outputs.
  • End-to-end tests that simulate defect pipelines and rejection log correlations.
  • Static analysis and lint checks in CI; run pytest with coverage reporting.

Common Mistakes to Avoid

  • Hard-coding secrets in code or rules; rely on secrets managers.
  • Mixing data access with business logic; maintain a clear data layer.
  • Neglecting input validation; allow only validated defect data and logs.

Related implementation resources: AI Agent Use Case for Packaging Manufacturers Using Quality Inspection Images to Detect Defects Before Shipment and How skill files accelerate AI development without sacrificing quality.

FAQ

What is this Cursor Rules Template for packaging QA?

A concrete, copyable Cursor rules configuration and engineering guide to build AI-based defect detection and rejection-log driven QA for packaging lines.

Which stack does this template assume?

A Python FastAPI backend, PostgreSQL via SQLAlchemy, OpenCV for image processing, and PyTorch-based models for defect detection; Cursor AI enforces rules across data, auth, and CI workflows.

Can I paste the .cursorrules block into my project root?

Yes. The block is designed to be copy-pasted into a top-level .cursorrules file and customizable to your packaging QA workflow.

How does this handle defects images and rejection logs?

The rules guide ingestion of defect images, linking with rejection logs, and applying Cursor AI decisions to trigger automated quality actions and audit trails.

What security patterns are recommended?

Use OAuth2 with JWT, HTTPS, secrets management, and role-based access; avoid hard-coded credentials in the rules.