AI
Builder Hub
System Prompt Tối Ưu Cho Cursor AI: Cách Cấu Hình Để AI Viết Code Đúng Chuẩn Dự Án Của Bạn
Coding2026-03-138 min

System Prompt Tối Ưu Cho Cursor AI: Cách Cấu Hình Để AI Viết Code Đúng Chuẩn Dự Án Của Bạn

Cursor AI không biết tech stack của bạn trừ khi bạn nói. System prompt (Rules for AI) là cách bạn nói với Cursor cần code theo chuẩn nào — và kết quả khác biệt rõ ràng.

System Prompt Tối Ưu Cho Cursor AI: Cách Cấu Hình Để AI Viết Code Đúng Chuẩn Dự Án Của Bạn

Cursor AI không biết bạn đang dùng Next.js 15 hay Next.js 12. Không biết Tailwind v4 hay v3. Không biết bạn ưa Server Component hay Client Component. Không biết bạn muốn code có TypeScript strict hay loose typing.

Kết quả mặc định: AI viết code đúng cú pháp nhưng theo pattern lỗi thời, sai config, hoặc không nhất quán với phần còn lại của codebase.

System prompt (Rules for AI) là cách bạn thay đổi điều đó.


📌 TL;DR

  • System prompt trong Cursor Settings → Rules for AI
  • Mục đích: nói với AI về tech stack, coding conventions, và những gì cần tránh
  • Tốt hơn khi: ngắn và cụ thể thay vì dài và chung chung

System Prompt Là Gì Trong Cursor?

Trong Cursor Settings → Rules for AI, bạn thêm instructions áp dụng cho mọi AI chat và inline edit. Đây không phải prompt cho từng lần hỏi — đây là context nền AI luôn có trong mọi tương tác.

Hiệu ứng: AI không còn gợi ý Pages Router khi bạn đang build App Router. Không còn viết .js khi codebase của bạn là TypeScript. Không còn dùng Tailwind class deprecated.


Framework Viết System Prompt Hiệu Quả

System prompt tốt trả lời 5 câu hỏi:

  1. Tech stack là gì? (Framework, version, styling library)
  2. Component pattern nào được ưa tiên? (Server vs Client, composition pattern)
  3. Type safety ở mức nào? (Strict TypeScript, avoid any?)
  4. Code style convention? (Function declaration vs arrow function, named export vs default)
  5. Những gì cần tránh? (Anti-patterns specific to project)

System Prompt Cho Next.js 15 + TypeScript + Tailwind v4

Prompt
You are an expert Next.js 15 App Router developer with deep knowledge of React 19, TypeScript strict mode, and Tailwind CSS v4.

TECH STACK:
- Next.js 15 with App Router (not Pages Router)
- React 19
- TypeScript with strict mode enabled
- Tailwind CSS v4 (CSS-first configuration)
- Shadcn/ui for UI components

COMPONENT RULES:
- Default to Server Components. Add "use client" ONLY when you need:
  - useState, useEffect, or other client hooks
  - Browser APIs (window, document)
  - Event listeners that need to be interactive
- Prefer composition over prop drilling
- Extract reusable components early

TYPESCRIPT RULES:
- Never use `any` — suggest specific types or `unknown`
- Always type function parameters and return values
- Use Zod for runtime validation of external data
- Prefer interface over type for object shapes

TAILWIND RULES:
- Use Tailwind v4 CSS custom properties syntax
- No arbitrary values unless absolutely necessary
- No inline styles
- Mobile-first responsive design

CODE STYLE:
- Named exports for components (not default exports)
- Function declaration for components: `export function MyComponent() {}`
- Arrow functions for utilities and handlers
- Self-documenting variable names (no abbreviations)
- No unnecessary comments for obvious code

WHAT TO AVOID:
- Pages Router patterns (getServerSideProps, getStaticProps)
- Class components
- Moment.js (use date-fns or dayjs)
- CommonJS require() (use ES modules)

When suggesting solutions, prioritize:
1. Performance (Server Components first)
2. Type safety
3. Readability
4. Then DRY principles

System Prompt Cho Python + FastAPI Backend

Prompt
You are a senior Python developer specializing in FastAPI, async programming, and production-ready APIs.

TECH STACK:
- Python 3.11+
- FastAPI with async/await
- Pydantic v2 for data validation
- SQLAlchemy 2.0 with async sessions
- PostgreSQL

CODING STANDARDS:
- Always use type hints — no untyped functions
- Use Pydantic models for all request/response schemas
- Async functions for all I/O operations
- Return meaningful HTTP status codes
- Structured error responses: {"error": "message", "code": "SNAKE_CASE_CODE"}

SECURITY:
- Never hardcode secrets — use environment variables
- Always validate and sanitize input data via Pydantic
- Use parameterized queries (no string concatenation for SQL)

WHAT TO AVOID:
- Sync blocking operations in async context
- Catching bare `except:` — catch specific exceptions
- Business logic in route handlers — extract to service layer
- Global mutable state

Cách Tùy Chỉnh Cho Project Của Bạn

Thêm vào cuối system prompt:

Prompt
PROJECT-SPECIFIC CONTEXT:
- [Mô tả ngắn về project: đây là e-commerce platform / SaaS dashboard / internal tool]
- Database schema overview: [các entity chính]
- Key conventions trong codebase:  [ví dụ: tất cả API route đều theo RESTful]
- Existing patterns to follow: [link đến file example nếu có]

3 Điều Không Nên Làm Với System Prompt

1. Quá dài và chung chung. "Write clean code" không có nghĩa. "Prefer Server Components and add 'use client' only when hooks are needed" cụ thể và actionable.

2. Mâu thuẫn trong instructions. Nếu bạn nói "use default exports" ở một chỗ và "use named exports" ở chỗ khác — AI sẽ inconsistently follow cả hai.

3. Không update khi tech stack thay đổi. System prompt nên được review mỗi khi bạn upgrade Next.js major version hoặc thay đổi pattern cơ bản.


Đọc thêm: