Skip to Content
Engineering Practice3. Cursor RulesIntroduction

Introduction

Keep AI-generated code within controllable boundaries

In previous chapters, we completed tool setup, tech stack selection, and scaffolding. Now that the project skeleton is in place, itโ€™s time to make AI understand and follow your project standards.

Core Concept: Rules as Constraints

Cursor Rules are the โ€œcontractโ€ between you and AI. Through clear rule definitions, you can:

GoalWithout RulesWith Rules
Code StyleAI randomly chooses stylesConsistently follows project standards
ArchitectureCode may be misplacedAutomatically placed in correct directories
Tech ChoicesMay use wrong librariesUses specified tech stack
Best PracticesDifferent implementations each timeConsistent implementation patterns

Chapter Goals

Through this chapter, you will master:

  • Writing principles and best practices for Cursor Rules
  • What rules to write at different stages of project development
  • Using meta prompts to quickly generate rule frameworks

Layered Rule Design

A complete rule system typically includes the following layers:

.cursor/rules/ โ”œโ”€โ”€ global-rules.mdc # ๐ŸŒ Global Rules (always active) โ”‚ # Tech stack, directory structure, TypeScript standards โ”‚ โ”œโ”€โ”€ routing-rules.mdc # ๐Ÿ›ฃ๏ธ Routing Rules (active for pages/**) โ”‚ # Page structure, route protection, auth flow โ”‚ โ”œโ”€โ”€ api-rules.mdc # ๐Ÿ”Œ API Rules (active for clients/**) โ”‚ # HTTP client, data fetching, error handling โ”‚ โ””โ”€โ”€ ui-rules.mdc # ๐ŸŽจ UI Rules (active for *.tsx) # Component usage, icon system, theme config

Chapter Contents

Reference Rule Sets

Weโ€™ve collected some verified rule examples that can serve as references for writing your rules:

Next Steps

Ready? Letโ€™s start with How Rules Work to understand how rules influence AI behavior.

Last updated on: