flowchart TD
P["User Request / Feature Prompt"] --> R["1. REQUIREMENT
(Gate 1: Khảo sát & Impact Map)"]
R --> D["2. DESIGN + MEMORY
(Hiến pháp .erp-rules.md, Skills, Domain Rules)"]
D --> PL["3. PLAN
(Kế hoạch chi tiết, Zod schemas, DB Safety)"]
PL --> I["4. IMPLEMENT + SKILLS
(Viết code theo Design Tokens, safeUpsert, TDD)"]
I --> V["5. VERIFY (Auto-Verify Loop)
(typecheck, server, lint, lint:css)"]
V --> T["6. TEST
(Vitest 100% Pass, E2E Guards)"]
T -->|Auto Retry / Fix Loop| V
T --> REV["7. REVIEW & GATEKEEPER
(AI_CHECKLIST.md & Human Gate Sign-off)"]
classDef primary fill:#e0f2fe,stroke:#0284c7,stroke-width:2px,color:#0f172a;
classDef success fill:#dcfce7,stroke:#16a34a,stroke-width:2px,color:#0f172a;
classDef warning fill:#fef3c7,stroke:#d97706,stroke-width:2px,color:#0f172a;
classDef danger fill:#fee2e2,stroke:#dc2626,stroke-width:2px,color:#0f172a;
class P,R,D,PL primary;
class I warning;
class V,T danger;
class REV success;