Coding Style
Immutability (CRITICAL)
File Organization
MANY SMALL FILES > FEW LARGE FILES
- High cohesion, low coupling
- 200-400 lines typical, 800 max
- Extract utilities from large modules
- Organize by feature/domain, not by type
Error Handling
ALWAYS handle errors comprehensively:Handle errors explicitly at every level
Handle errors explicitly at every level
Provide user-friendly error messages in UI-facing code
Provide user-friendly error messages in UI-facing code
Log detailed error context on the server side
Log detailed error context on the server side
Never silently swallow errors
Never silently swallow errors
Input Validation
ALWAYS validate at system boundaries:- Validate all user input before processing
- Use schema-based validation where available
- Fail fast with clear error messages
- Never trust external data (API responses, user input, file content)
Code Quality Checklist
Before marking work complete:- Code is readable and well-named
- Functions are small (<50 lines)
- Files are focused (<800 lines)
- No deep nesting (>4 levels)
- Proper error handling
- No hardcoded values (use constants or config)
- No mutation (immutable patterns used)
Testing
Minimum Test Coverage: 80%
Test Types (ALL required):Unit Tests
Integration Tests
E2E Tests
Test-Driven Development
MANDATORY workflow:Troubleshooting Test Failures
- Use tdd-guide agent
- Check test isolation
- Verify mocks are correct
- Fix implementation, not tests (unless tests are wrong)
Agent Support
tdd-guide
Security
Mandatory Security Checks
Before ANY commit:- No hardcoded secrets (API keys, passwords, tokens)
- All user inputs validated
- SQL injection prevention (parameterized queries)
- XSS prevention (sanitized HTML)
- CSRF protection enabled
- Authentication/authorization verified
- Rate limiting on all endpoints
- Error messages don’t leak sensitive data
Secret Management
NEVER hardcode secrets in source code
NEVER hardcode secrets in source code
ALWAYS use environment variables or a secret manager
ALWAYS use environment variables or a secret manager
.env files (not committed) or a secret management service.Validate that required secrets are present at startup
Validate that required secrets are present at startup
Rotate any secrets that may have been exposed
Rotate any secrets that may have been exposed
Security Response Protocol
If security issue found:STOP immediately
Use security-reviewer agent
Fix CRITICAL issues before continuing
Rotate any exposed secrets
Review entire codebase for similar issues
Patterns
Skeleton Projects
When implementing new functionality:Search for battle-tested skeleton projects
Use parallel agents to evaluate options
- Security assessment
- Extensibility analysis
- Relevance scoring
- Implementation planning
Clone best match as foundation
Iterate within proven structure
Repository Pattern
Encapsulate data access behind a consistent interface:Define standard operations
Define standard operations
Concrete implementations handle storage details
Concrete implementations handle storage details
Business logic depends on the abstract interface
Business logic depends on the abstract interface
Benefits
Benefits
API Response Format
Use a consistent envelope for all API responses:- Include a success/status indicator
- Include the data payload (nullable on error)
- Include an error message field (nullable on success)
- Include metadata for paginated responses (total, page, limit)
Git Workflow
Commit Message Format
Pull Request Workflow
When creating PRs:Analyze full commit history
Use git diff [base-branch]...HEAD
Draft comprehensive PR summary
Include test plan with TODOs
Push with -u flag if new branch
Hooks
Hook Types
PreToolUse
PostToolUse
Stop
Auto-Accept Permissions
TodoWrite Best Practices
Use TodoWrite tool to:- Track progress on multi-step tasks
- Verify understanding of instructions
- Enable real-time steering
- Show granular implementation steps
- Out of order steps
- Missing items
- Extra unnecessary items
- Wrong granularity
- Misinterpreted requirements