Generate Scoped Cursor Rules for Project Architecture

Create targeted .cursorrules files that enforce strict architectural boundaries between frontend, API, and database layers to prevent code leaks.

Agent prompt for Claude and ChatGPT

Prompt

Prompt
Act as a Senior Software Architect. I need a set of strict rules for my project directory structure to enforce clean architecture. Please ask me these 3 questions first: 1. What are the main top-level directories in your project? 2. Are there specific directories that should never import from each other? 3. Do you have specific naming conventions for files in the API or database layers? Once I answer, provide a structured markdown response containing the .cursorrules content for each directory. Rules must follow these constraints: 1. Use glob patterns for all file path matching. 2. Explicitly forbid cross-tier imports for restricted directories. 3. Include a section for file naming patterns. 4. State the rules in clear, imperative sentences. Output format: For each folder, provide a code block titled with the directory name containing the rules. End with a summary of how these rules prevent common dependency cycles.

Example output

Example for: a full-stack React project with a Node.js backend and Prisma ORM.

Frontend Rules (.cursorrules for /src/components)
- glob: src/components/**
- forbid: import * from @/server/**
- forbid: import * from @/lib/db/**
- enforce: all components must be functional components
API Rules (.cursorrules for /src/server)
- glob: src/server/**
- forbid: import * from @/components/**
- enforce: all endpoints must return standard JSON response objects
- enforce: use Zod for input validation on all routes
Database Rules (.cursorrules for /src/lib/db)
- glob: src/lib/db/**
- forbid: import * from @/components/**
- forbid: import * from @/server/**
- enforce: all queries must use Prisma transactions
Summary

These rules prevent architectural drift by stopping the UI layer from directly querying the database or accessing sensitive server-side secrets. By isolating the database layer, you ensure that business logic remains in the server tier, preventing tight coupling between the database schema and the frontend UI components.

Written by AI from this prompt. Your results will vary.

Tips and common edits

Why this works

  • Forces explicit glob patterns that Cursor interprets directly for file-level constraints.
  • Uses imperative language to ensure the AI understands strict forbidden import paths.
  • Prevents circular dependencies by creating clear, one-way architectural flows.

Use this in Cursor to generate custom .cursorrules files. Paste the output into the corresponding directories to ensure the AI composer follows your architectural constraints. Supported by Cursor, Claude, and ChatGPT.

Common edits

  • Add specific file extensions if you only want to lint certain file types.
  • Adjust the forbidden import paths if your project uses different alias patterns like @core or @shared.

Reuse it: Use in a workflowAdapt in the builder

Prompt details

By
Prompts-GPT editors
Published
How prompts are written and checked

Did this prompt work?

More in Cursor

Decompose Framework Migrations into Subagent Work Batches

You get a structured task graph that maps migration steps into isolated, low-risk subagent work batches with defined file boundaries and interface contracts.

Generate Architectural Guardrails for Autonomous Code Agents

Create a strictly defined AGENTS.md file that forces autonomous coding agents like Codex to adhere to your project's specific architectural constraints and style rules.

Perform Static Call Graph Trace Before Modifying Code

Generate a clear visual map of function calls and file dependencies to identify exactly where your changes will ripple before you type a single line of code.

CodingClaude Code

Codebase Tour for a Specific Task

Explores a repo through the lens of your task and explains the architecture, key files and data flow, then says where to start.

Coding

Trace an execution path from entry to database

Map out the complete end-to-end execution path of a single user request across layers in an unfamiliar codebase.

Automation & Workflows

Compare no-code automation versus custom scripts

Decide between no-code platforms and custom code scripts for a specific workflow based on maintenance, cost, and scale.