Cursor Rules Template: Manufacturing Execution Dashboard (NestJS + PostgreSQL)
Cursor rules template for a manufacturing execution dashboard (MES) stack using NestJS backend with PostgreSQL, TypeORM, and React frontend. Provides a copyable .cursorrules configuration and stack-specific guidance.
Target User
Developers building manufacturing execution dashboards with a NestJS backend and PostgreSQL data layer
Use Cases
- Backend data model for MES (machines, jobs, downtime, quality checks)
- API endpoints for production analytics
- Data access patterns with TypeORM in PostgreSQL
- Secure, testable, and maintainable Cursor AI guidance for MES
Markdown Template
Cursor Rules Template: Manufacturing Execution Dashboard (NestJS + PostgreSQL)
framework: NestJS + PostgreSQL
context: You are an AI software engineer building a Manufacturing Execution Dashboard (MES) with machines, jobs, downtime, quality checks, and production analytics. Target stack: NestJS backend with PostgreSQL using TypeORM and a React frontend. Generate back-end skeletons, data models, and safe API patterns. Ensure testability and security by default.
# Framework Role & Context
role: Backend Architect for MES
domains: manufacturing, MES, data modeling, API design
# Code Style and Style Guides
language: TypeScript
lint: ESLint + Prettier
standards: airbnb-typescript, explicit any forbidden, strictNullChecks, noImplicitAny
naming: camelCase variables, PascalCase for classes, DTOs for inputs
# Architecture & Directory Rules
projectLayout: monorepo
backendDir: backend/src
frontendDir: frontend/src
modules: machine, job, downtime, quality, analytics
controllers: RESTful endpoints for read/write
services: business logic separated from controllers
repositories: data access via TypeORM repositories
migrations: backend/src/migrations
# Authentication & Security Rules
auth: jwt with access & refresh tokens
guards: jwt-auth.guard.ts on protected routes
security: CSRF-protected API interactions for SPA; httpOnly cookies for tokens; environment-based secrets; TLS in prod
validation: class-validator with DTOs
secrets: use vault or env vars, do not hardcode
# Database and ORM patterns
db: PostgreSQL
orm: TypeORM with Data Mapper; migrations enabled; entities in backend/src/entities; repositories in backend/src/repositories
queries: parameterized; avoid string concatenation; prepared statements where needed
indexes: create indexes on machineId, jobId, timestamp, productionLine
# Testing & Linting Workflows
tests: Jest unit & integration; test data builders; CI runs on pull requests
linting: ESLint with autofix; Prettier formatting on commit
coverage: minimum 80% for critical paths
# Prohibited Actions and Anti-patterns for the AI
doNot: generate raw SQL inline; bypass DI; create circular dependencies; bypass authentication; access production secrets; assume frontend can access DB directly
practice: always rely on DTO validations; use repositories; keep business logic in servicesOverview
This Cursor rules template provides a complete, copyable .cursorrules configuration for building a Manufacturing Execution Dashboard (MES) stack. It targets a NestJS backend with PostgreSQL (TypeORM) and a React frontend for real-time machine status, jobs, downtime logging, quality checks, and production analytics. The rules define roles, architecture, data access, and safe AI-assisted development patterns to keep the project maintainable and secure.
Direct answer: This Cursor rules template instructs Cursor AI to generate a NestJS + PostgreSQL MES backend with well-structured modules, a clean data model, and production-ready rules that align with secure, testable development practices.
When to Use These Cursor Rules
- You are building an MES dashboard that tracks machines, jobs, downtime, quality checks, and production analytics.
- You need a repeatable pattern for backend modules, data models, and API endpoints that can scale with plant floor data.
- You want Cursor AI to generate consistent code scaffolding while enforcing security, testing, and linting standards.
- You require a clear directory structure and ORM usage for PostgreSQL without relying on non-relevant ORMs.
Copyable .cursorrules Configuration
framework: NestJS + PostgreSQL
context: You are an AI software engineer building a Manufacturing Execution Dashboard (MES) with machines, jobs, downtime, quality checks, and production analytics. Target stack: NestJS backend with PostgreSQL using TypeORM and a React frontend. Generate back-end skeletons, data models, and safe API patterns. Ensure testability and security by default.
# Framework Role & Context
role: Backend Architect for MES
domains: manufacturing, MES, data modeling, API design
# Code Style and Style Guides
language: TypeScript
lint: ESLint + Prettier
standards: airbnb-typescript, explicit any forbidden, strictNullChecks, noImplicitAny
naming: camelCase variables, PascalCase for classes, DTOs for inputs
# Architecture & Directory Rules
projectLayout: monorepo
backendDir: backend/src
frontendDir: frontend/src
modules: machine, job, downtime, quality, analytics
controllers: RESTful endpoints for read/write
services: business logic separated from controllers
repositories: data access via TypeORM repositories
migrations: backend/src/migrations
# Authentication & Security Rules
auth: jwt with access & refresh tokens
guards: jwt-auth.guard.ts on protected routes
security: CSRF-protected API interactions for SPA; httpOnly cookies for tokens; environment-based secrets; TLS in prod
validation: class-validator with DTOs
secrets: use vault or env vars, do not hardcode
# Database and ORM patterns
db: PostgreSQL
orm: TypeORM with Data Mapper; migrations enabled; entities in backend/src/entities; repositories in backend/src/repositories
queries: parameterized; avoid string concatenation; prepared statements where needed
indexes: create indexes on machineId, jobId, timestamp, productionLine
# Testing & Linting Workflows
tests: Jest unit & integration; test data builders; CI runs on pull requests
linting: ESLint with autofix; Prettier formatting on commit
coverage: minimum 80% for critical paths
# Prohibited Actions and Anti-patterns for the AI
doNot: generate raw SQL inline; bypass DI; create circular dependencies; bypass authentication; access production secrets; assume frontend can access DB directly
practice: always rely on DTO validations; use repositories; keep business logic in services
Recommended Project Structure
backend/
src/
app.module.ts
main.ts
entities/
machine.entity.ts
job.entity.ts
downtime.entity.ts
quality_check.entity.ts
production_analytics.entity.ts
repositories/
machine.repository.ts
job.repository.ts
downtime.repository.ts
quality.repository.ts
analytics.repository.ts
services/
machine.service.ts
job.service.ts
downtime.service.ts
quality.service.ts
analytics.service.ts
controllers/
machine.controller.ts
job.controller.ts
downtime.controller.ts
quality.controller.ts
analytics.controller.ts
modules/
machine.module.ts
job.module.ts
downtime.module.ts
quality.module.ts
analytics.module.ts
config/
typeorm.config.ts
frontend/
src/
pages/
dashboard.tsx
components/
DashboardCard.tsx
MachineStatus.tsx
JobList.tsx
hooks/
useDashboardData.ts
public/
index.html
Core Engineering Principles
- Explicit data models: machines, jobs, downtime, quality checks, and analytics in PostgreSQL with TypeORM.
- Strong separation of concerns: modules, services, controllers, and repositories clearly partition responsibilities.
- Security by default: JWT auth, minimal privileges, validated inputs, and encrypted secrets management.
- Testable code: DTOs, mockable services, and Jest-based unit/integration tests; CI checks for coverage.
- Maintainable Cursor AI guidance: deterministic scaffolds, non-destructive changes, and clear TODOs for human review.
Code Construction Rules
- Use DTOs for all inputs/outputs; validate with class-validator; fail fast on invalid payloads.
- Entities reflect MES domain: Machine, Job, Downtime, QualityCheck, ProductionAnalytics; define relations (OneToMany, ManyToOne) with proper cascade settings.
- Repository pattern for data access; avoid raw queries in services; use query builders for complex joins.
- Endpoints follow REST conventions; versioned routes; consistent error handling and error payloads.
- Authentication: protect sensitive endpoints; tokens stored in httpOnly cookies or secure storage; rotate refresh tokens.
- Logging and telemetry: structured logs, correlate by requestId, and emit metrics for dashboards.
Security and Production Rules
- Use TLS everywhere; enforce secure cookies and sameSite policies for SPA authentication flows.
- Store secrets in a vault or environment management system; never commit secrets to code.
- Limit API rate to prevent abuse; implement IP-based throttling for production endpoints.
- Input validation and output encoding to prevent injection attacks; keep ORM usage to avoid SQL injection.
- Regular dependency audits and vulnerability scanning; pin dependencies with exact versions in production.
Testing Checklist
- Unit tests for each service and validator
- Integration tests for repositories and database interactions with an isolated test DB
- End-to-end tests for the dashboard data flow (mocked frontend vs API)
- Linting and formatting as part of CI
- Migration integrity tests to ensure schema compatibility
Common Mistakes to Avoid
- Rushing database schema changes without migrations or rollback plans
- Embedding business logic in controllers instead of services
- Exposing raw database errors to clients
- Ignoring token rotation and refresh token security considerations
- Hardcoding environment-specific values in code; use configs and env vars
Related Cursor rules templates
Explore adjacent Cursor rules templates for similar stacks, workflows, and production constraints.
- Cursor Rules Template: LMS with Courses, Lessons, Quizzes, Certificates, Payments, and Admin Dashboard
- KPI Dashboard Builder — Cursor Rules Template for Cursor AI
- Cursor Rules Template: ERP Dashboard with Next.js, PostgreSQL, Prisma, Clerk and Shadcn UI
- Cursor Rules Template: Python FastAPI API Monitoring
FAQ
What makes this Cursor Rules Template suitable for a MES dashboard?
The template defines a NestJS + PostgreSQL MES stack with explicit data models for machines, jobs, downtime, quality checks, and analytics. It includes a copyable .cursorrules block and a stack-specific project layout to ensure secure, testable code generation by Cursor AI.
Which stack is targeted and why?
The targeted stack is a NestJS backend with PostgreSQL using TypeORM, paired with a React frontend. This aligns with common MES patterns and provides strong type safety, robust migrations, and efficient data access for dashboards and analytics.
How do I adapt the .cursorrules block to a different MES layout?
What security considerations are baked into these rules?
Rules enforce JWT-based authentication, protected routes, parameterized queries, validation, and secrets management. They also advocate least privilege and secure token handling to prevent data leakage and unauthorized access.
How should I structure migrations in the recommended project layout?
Place TypeORM migrations under backend/src/migrations and run them as part of the deployment. Maintain a consistent naming convention, review migrations in PRs, and ensure rollback strategies exist for each change.
Can Cursor AI generate frontend scaffolding as part of this template?
Yes. The template focuses on a robust backend and the data layer, with guidance to structure frontend components for a MES dashboard. Cursor AI can extend scaffolds for React components that consume the API endpoints and visualise production analytics.