Cursor Rules Template: AdonisJS Edge Lucid ORM
Cursor Rules Template for AdonisJS Edge with Lucid ORM to generate a copyable .cursorrules configuration for Cursor AI.
Target User
Developers building APIs with AdonisJS Edge and Lucid ORM who want a copyable .cursorrules configuration for Cursor AI
Use Cases
- API development with AdonisJS Edge and Lucid ORM
- Database modeling with Lucid ORM
- Secure API endpoints with proper auth and validation
Markdown Template
Cursor Rules Template: AdonisJS Edge Lucid ORM
// Cursor Rules: AdonisJS Edge Lucid ORM
Framework: AdonisJS
Runtime: Node.js 18+
Stack: Edge ORM Lucid
Context: You are a Cursor AI editor for AdonisJS apps using Edge templates and Lucid ORM. Provide safe, tested, code blocks for model, controller, and route generation.
CodeStyle:
Language: TypeScript
StyleGuide: Prettier ESLint
Rules:
semi: true
quotes: single
noImplicitAny: true
noUnusedLocals: true
maxLineLength: 120
Architecture:
DirectoryRules:
- app/Controllers/Http
- app/Models
- app/Middlewares
- database/migrations
- database/seeders
- start
Authentication:
Strategy: AdonisJS Auth with session cookies
CSRF: enabled
Cookies: Secure in production
DatabaseORM:
ORM: Lucid
ModelsDir: app/Models
MigrationsDir: database/migrations
Queries: use Lucid query builder; parameterize inputs
Testing:
Runner: Japa
UnitTests: test/unit/**/*.spec.ts
IntegrationTests: test/integration/**/*.spec.ts
Linting: npm run lint
Prohibited:
- Do not use raw string interpolation for user input
- Do not bypass validation or authorization checks
- Do not commit secrets in code
- Do not use eval or dynamic code executionOverview
Direct answer: This Cursor rules template provides a ready to paste .cursorrules configuration for AdonisJS Edge with Lucid ORM to guide Cursor AI in repository scaffolding, code edits, and safe AI-assisted development. It targets AdonisJS apps using Edge templates and Lucid ORM migrations and models.
The Cursor rules configuration defines scope for framework role, architecture, security, and testing patterns specific to this stack. Use this template to lock Cursor AI behavior around AdonisJS endpoints, Lucid models, and edge route generation.
When to Use These Cursor Rules
- Starting a new AdonisJS API that uses Edge views and Lucid models.
- Establishing a consistent code style across controllers, models, and migrations.
- Guiding Cursor AI to scaffold endpoints with proper validation and security in AdonisJS.
- Ensuring safe ORM usage and parameterized queries for all data access.
- Automating tests and linting in CI for AdonisJS projects.
Copyable .cursorrules Configuration
// Cursor Rules: AdonisJS Edge Lucid ORM
Framework: AdonisJS
Runtime: Node.js 18+
Stack: Edge ORM Lucid
Context: You are a Cursor AI editor for AdonisJS apps using Edge templates and Lucid ORM. Provide safe, tested, code blocks for model, controller, and route generation.
CodeStyle:
Language: TypeScript
StyleGuide: Prettier ESLint
Rules:
semi: true
quotes: single
noImplicitAny: true
noUnusedLocals: true
maxLineLength: 120
Architecture:
DirectoryRules:
- app/Controllers/Http
- app/Models
- app/Middlewares
- database/migrations
- database/seeders
- start
Authentication:
Strategy: AdonisJS Auth with session cookies
CSRF: enabled
Cookies: Secure in production
DatabaseORM:
ORM: Lucid
ModelsDir: app/Models
MigrationsDir: database/migrations
Queries: use Lucid query builder; parameterize inputs
Testing:
Runner: Japa
UnitTests: test/unit/**/*.spec.ts
IntegrationTests: test/integration/**/*.spec.ts
Linting: npm run lint
Prohibited:
- Do not use raw string interpolation for user input
- Do not bypass validation or authorization checks
- Do not commit secrets in code
- Do not use eval or dynamic code execution
Recommended Project Structure
adonis-app/
├── app/
│ ├── Controllers/
│ │ └── Http/
│ ├── Models/
│ │ └── *.ts
│ ├── Middlewares/
│ ├── Validators/
│ └── Policies/
├── config/
├── database/
│ ├── migrations/
│ └── seeders/
├── start/
└── tests/
├── unit/
└── functional/
Core Engineering Principles
- Type safety and explicit interfaces across API surfaces.
- Security by default with validated inputs and sanitized outputs.
- Idempotent migrations and deterministic seeding for repeatable deployments.
- Separation of concerns between controllers, services, and models.
- Test-driven patterns with clear unit and integration tests.
Code Construction Rules
- Use Lucid models for all database entities and define relations in model files.
- Access the database via Lucid query builder, avoid raw SQL when possible.
- Validate inputs with AdonisJS validators and transform data in a predictable way.
- TypeScript preferred for controllers, services, and models; configure tsconfig accordingly.
- Routes, controllers, and validations must be covered by unit tests and integration tests.
- Follow the project’s Prettier and ESLint rules; run lint before commits.
Security and Production Rules
- Enable CSRF protection and secure cookies in production.
- Store secrets in environment variables; do not commit to repository.
- Use parameterized queries and input validation to prevent injection attacks.
- Enforce authentication on sensitive endpoints; use role-based access where needed.
- Audit logs and error handling should not leak stack traces in production.
Testing Checklist
- Unit tests cover models and services with mocked dependencies.
- Integration tests verify API endpoints and Lucid relationships.
- End-to-end tests simulate real user flows via HTTP requests.
- CI runs lint, test, and type checking on PRs.
Common Mistakes to Avoid
- Skipping validation and relying on client-side checks.
- Mixing concerns in controllers; ignore business logic in controllers.
- Using raw SQL queries without parameterization.
- Neglecting TypeScript types for entities and DTOs.
FAQ
What is this Cursor Rules Template for AdonisJS?
This Cursor Rules Template provides a ready to paste .cursorrules configuration tailored for AdonisJS Edge with Lucid ORM. It defines stack specific rules for architecture, authentication, ORM usage, testing, and security to guide Cursor AI edits within this stack.
Which stack does this cover?
The template targets AdonisJS with Edge and Lucid ORM. It specifies file structure, controllers, models, migrations, and test patterns unique to this stack so Cursor AI can assist without deviating from the framework conventions.
How do I apply the .cursorrules block?
Copy the code block from the Copyable section and paste into a file named .cursorrules at the repository root. Run your usual dev workflow and let Cursor AI guide edits within the safe rules defined by this template.
Can I customize for other databases?
Yes. The template emphasizes Lucid ORM patterns. For other databases, adjust models and migrations accordingly while preserving validation and parameterized queries to prevent SQL injection.
What should I test after applying?
Test model relations, API endpoints, request validation, and authentication flow. Verify migrations run cleanly and seeds populate required data. Include unit and integration tests and run lint in CI.