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
Never use try-catch blocks that swallow errors without logging or re-throwing.
Provide user-friendly error messages in UI-facing code
Provide user-friendly error messages in UI-facing code
Error messages shown to users should be clear, actionable, and non-technical.
Log detailed error context on the server side
Log detailed error context on the server side
Include stack traces, request IDs, user context, and other debugging information.
Never silently swallow errors
Never silently swallow errors
Even if you can’t handle an error, at minimum log it before continuing.
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):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
Use PROACTIVELY for new features, enforces write-tests-first
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
Secrets include API keys, passwords, tokens, private keys, connection strings.
ALWAYS use environment variables or a secret manager
ALWAYS use environment variables or a secret manager
Load secrets from
.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
Fail fast if critical secrets are missing rather than failing later with cryptic errors.
Rotate any secrets that may have been exposed
Rotate any secrets that may have been exposed
If a secret is accidentally committed, immediately rotate it and invalidate the old one.
Security Response Protocol
If security issue found:Patterns
Skeleton Projects
When implementing new functionality:Search for battle-tested skeleton projects
Look for well-maintained templates with good documentation
Use parallel agents to evaluate options
- Security assessment
- Extensibility analysis
- Relevance scoring
- Implementation planning
Repository Pattern
Encapsulate data access behind a consistent interface:Define standard operations
Define standard operations
findAll, findById, create, update, delete
Concrete implementations handle storage details
Concrete implementations handle storage details
Database, API, file, in-memory, etc.
Business logic depends on the abstract interface
Business logic depends on the abstract interface
Not the storage mechanism
Benefits
Benefits
Enables easy swapping of data sources and simplifies testing with mocks
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
Attribution disabled globally via ~/.claude/settings.json.
Pull Request Workflow
When creating PRs:Hooks
Hook Types
PreToolUse
Before tool execution (validation, parameter modification)
PostToolUse
After tool execution (auto-format, checks)
Stop
When session ends (final verification)
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
Related
TypeScript Rules
TypeScript-specific extensions
Python Rules
Python-specific extensions
Go Rules
Go-specific extensions