Development principles for the AIProxy project.
ALWAYS UPDATE DOCUMENTATION BEFORE IMPLEMENTING CODE.
- FIRST: Update IDEA.md with the design decision
- SECOND: Get user approval of documented design
- THIRD: Implement the code
- FOURTH: Update documentation if implementation differs
- Adding libraries or dependencies
- Adding CLI flags or environment variables
- Changing file formats or schemas
- Adding features or modifying behavior
- Changing request flow or architecture
- Modifying defaults or configuration
STOP IMMEDIATELY:
- Acknowledge the mistake
- Ask user if they want to keep the implementation
- Update documentation to match (if keeping) or revert code (if not)
TESTS MUST BE WRITTEN BEFORE IMPLEMENTATION.
- FIRST: Document the feature in IDEA.md
- SECOND: Write tests defining expected behavior
- THIRD: Implement minimal code to pass tests
- FOURTH: Refactor while keeping tests green
Write tests for:
- ✅ Business logic (access control, rate limiting, deduplication)
- ✅ Security-critical code (validation, authentication, glob pattern safety)
- ✅ Complex algorithms (glob matching, rate limit calculations)
- ✅ Integration points (file I/O, rule loading, stats collection)
- ✅ Error handling and edge cases
Skip tests for:
- ❌ Trivial code (getters/setters, struct initialization)
- ❌ Third-party library behavior (framework internals)
- ❌ Standard library functionality
- ❌ Main function entry point wiring
Before marking implementation complete:
- Tests exist for all business logic
- All tests pass
- Tests cover happy path AND error cases
- Tests use table-driven patterns (where appropriate)
- Test names clearly describe scenario and expected behavior
- Tests are fast (<100ms each, except integration tests)
- Keep dependencies minimal
- Prefer standard library where possible
- Document why each dependency is necessary
- Evaluate binary size impact
Focus tests on value:
- ✅ Business logic and security-critical code
- ✅ Complex algorithms and integration points
- ❌ Trivial code or third-party library behavior
See golang-testing and golang-stretchr-testify skills for patterns.
- Use atomic writes (temp file + rename)
- Validate JSON after reading
- Handle missing files gracefully
- All directories must be pre-created (see DONT.md)
- Use environment variables for configuration
- Run as non-root user in containers
- Externalize persistent data via volume mounts
The Documentation-First rule (above) and Test-Driven Development rule are NOT guidelines — they cannot be deviated from.
The deviation policy below applies only to coding practices and project-specific practices:
These are guidelines. Deviate when:
- Strong technical reason exists (document it)
- Experimenting (mark as experimental)
- External constraints force it (document why)
Document all deviations in code comments or commit messages.