AI Development Guide
AI Coding Agents Guide
Complete reference for AI agents building the HRMS system
AI Coding Agents Guide
This is the comprehensive guide for AI coding agents (Claude Code, Cursor, Copilot) to build a production-ready, AI-native HRMS system.
Core Philosophy
"Will this help our first 10 customers TODAY?" — Filter for all technical decisions.
This question prevents:
- Premature abstraction
- Over-engineering
- Feature creep
- Technology churn
Target Metrics
| Metric | Target |
|---|---|
| Tenants | 100 |
| Users | 10,000 |
| Database | Single PostgreSQL with RLS |
| Architecture | Next.js + NestJS monolith |
| APIs | REST (not GraphQL) |
| AI | Native from day one |
What This Guide Covers
Architecture & Stack
- Architecture Principles - Anti-patterns to avoid, patterns to embrace
- Technology Stack - Locked versions and packages
- Repository Structure - File and folder layout
Data & Implementation
- Domain Models - Core data models and relationships
- Database Schema - Complete Prisma schema
- API Reference - REST endpoints
- Service Patterns - OrgService implementation
AI Features
- AI Integration - AI tools and RAG
Development Process
- Context Management - Maintaining context across sessions
- Patterns - Code patterns to follow exactly
- Constraints - Hard rules and .cursorrules
- Workflow - Development workflow and gates
UI Reference
- UI Screenshots - Visual reference for all screens
- Design System - Design tokens, components, AI rules
Quick Reference
Key Patterns
// Every manager is an employee
interface EmployeeOrgRelations {
primaryManagerId?: string // 0..1
dottedLineManagerIds: string[] // 0..N
additionalManagerIds: string[] // 0..N
teamIds: string[] // 0..N
departmentIds: string[] // 0..N
roleIds: string[] // 0..N
}Critical Rules
ALWAYS:
├── Filter by tenantId in every query
├── Use Prisma 5.x (NOT 6.x)
├── Use REST APIs (NOT GraphQL)
├── Follow established patterns exactly
└── Complete one building block before starting next
NEVER:
├── Add microservices
├── Use event sourcing
├── Create abstract factories for < 3 implementations
├── Touch locked files without ADR
└── Suggest "better" patternsOperations Summary
// Manager operations
Org.assignPrimaryManager(empId, mgrId)
Org.addDottedLineManager(empId, mgrId)
Org.addAdditionalManager(empId, mgrId)
// Team operations
Org.addEmployeeToTeam(empId, teamId, role?)
Org.removeEmployeeFromTeam(empId, teamId)
// Department operations
Org.addEmployeeToDepartment(empId, deptId, isPrimary?)
Org.setPrimaryDepartment(empId, deptId)
// Role operations
Org.assignRole(empId, roleId, isPrimary?)
Org.setPrimaryRole(empId, roleId)
// AI operations
AI.org.explain(empId)
AI.org.validate(options)
AI.org.generateStructure(description)Before You Start
- Read Architecture Principles to understand what NOT to do
- Check Technology Stack for locked versions
- Review Domain Models for the flexible org structure
- Understand the Workflow and gate system
- Check the current building block in Implementation Plan
Session Checklist
Before every coding session:
- Read current building block specification
- Check Constraints for hard rules
- Review Patterns for code structure
- Check what files are locked
- Understand current system state
Live State Files (CRITICAL)
MANDATORY
Before EVERY coding session, these files MUST exist and be current in the code repository root.
| File | Purpose | AI Must Read |
|---|---|---|
PROJECT_STATE.md | Current progress, step-level tracking | ✅ FIRST |
WHAT_EXISTS.md | Inventory of built components | ✅ SECOND |
CLAUDE.md | Claude Code instructions | ✅ AUTO |
Session Start Ritual
Before writing ANY code:
- Read
PROJECT_STATE.md- Know current phase, step, locked files - Read
WHAT_EXISTS.md- Know what's built, patterns to copy - Check
git status- Verify clean state - State understanding: "I'm on Phase X, Step Y. I will do Z."
- WAIT for approval
After EVERY Step
Update PROJECT_STATE.md:
- Mark step ✅ with timestamp
- Update current step section
- Update progress percentage
See Live State Tracking for complete templates and protocols.
CLAUDE.md Template
Create this file at the root of the hrms code repository. Claude Code automatically reads this file at the start of every session.
# HRMS Project - AI Agent Instructions
## Project Context
Multi-tenant HRMS SaaS with flexible org structure.
- Monorepo: apps/web (Next.js 15), apps/api (NestJS 10), packages/database (Prisma 5)
- Database: PostgreSQL 17 with Row-Level Security
- Auth: Auth.js with Google SSO
## Current Phase
Check: https://hrms-docs.vercel.app/docs/15-implementation-plan
## CRITICAL RULES
### Session Start Ritual (MANDATORY)
1. Read PROJECT_STATE.md - Note current phase, step, locked files
2. Read WHAT_EXISTS.md - Note patterns to copy
3. Run: git status && git log -3 --oneline
4. State: "I'm on Phase X, Step Y. I will do Z. Pattern source: [file]."
5. WAIT for approval before any code changes
### Before Writing Code
1. Complete Pre-Code Verification (see below)
2. Confirm understanding: "I will [X]. Gate is [Y]. Proceed?"
3. Wait for approval
### After Each Step
1. Update PROJECT_STATE.md with ✅ and timestamp
2. Run gate verification
3. Report: "Gate [PASS/FAIL]: [details]"
4. Ask: "What's next?" - DO NOT auto-proceed
### Escape Hatch
If unsure about ANYTHING, ASK instead of guessing.
## PRE-CODE VERIFICATION (Before EVERY Edit)
1. Is this file in "Locked Files" list? → STOP if yes
2. Have I read the file's current contents? → Read first if no
3. Does similar file/component exist? → Search first
4. What pattern am I copying from? → Identify source file
5. What is the gate for this step? → State criteria
## CONSTRAINTS - DO NOT VIOLATE
### Architecture
- NO microservices (monolith only)
- NO GraphQL (REST only)
- NO event sourcing or message queues
- NO abstractions without 3+ implementations
### Technology
- Prisma 5.x (NOT 6.x)
- Next.js 15.x with App Router
- NestJS 10.x
- React Query (NOT Redux/MobX)
### Development
- Complete ONE vertical slice before touching anything else
- Never modify locked files without approval
- Never install packages not in tech stack
- Never suggest "improvements" to working code
## ANTI-IMPROVEMENT PLEDGE
NEVER do these without explicit request:
- "Improve" working code
- Suggest "better" alternatives
- Refactor "while we're here"
- Add "helpful" features
- "Clean up" unrelated code
- Premature optimization
- Add extra error handling
- Create abstractions for single use
If tempted, ask: "Is [X] in scope? If not, I'll continue with current task."
## Common Commands
# Development
npm run dev # Start all services
npm run db:push # Push schema changes
npm run db:studio # Open Prisma Studio
# Testing
npm test # Run tests
npm run lint # Run linter
# Build
npm run build # Build all
## Key Files
- packages/database/prisma/schema.prisma - Database schema
- apps/api/src/app.module.ts - API module registration
- apps/web/app/layout.tsx - App layout
## Anti-Patterns (From Bluewoo Lessons)
- Over-engineering for hypothetical scale
- Adding features "for later"
- Enterprise patterns for zero customers
- Shared libraries between modules
- Complex inheritance hierarchiesWhy CLAUDE.md?
From industry research:
- Claude automatically loads this file into context
- Reduces repetitive instructions
- Prevents common mistakes consistently
- Higher payoff than MCP servers for single-developer projects
Updating CLAUDE.md
Update when:
- Moving to a new phase
- Adding new constraints
- Discovering recurring mistakes
- Changing tech stack (with ADR)