You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Clean Architecture with DDD: Implement Domain-Driven Design principles with clear separation between domain, application, and infrastructure layers.
Modular Monolith: Structure code as a modular monolith, poised for future transition to microservices if needed.
Mono-repo: Use a mono-repo approach to ensure consistent versioning and dependency management across modules.
Code Quality & Generation
Linter: Use golangci-lint v2 for all Go code, always applying the --fix flag.
Interface Mocking: Annotate every interface with //go:generate mockgen -source=$GOFILE -destination=../mock/$GOFILE_mock.go to ensure consistent mock generation.
Swagger: Ensure all HTTP handlers include @Summary, @Description, and @Router Swagger annotations.
SQL Generation: Use sqlc to generate type-safe database code from SQL queries defined in the /sql/queries directory.
Verification: After making changes, execute: go generate ./... && golangci-lint run --fix ./... && go clean -testcache && go test -v -race ./... to verify code correctness and quality.
File Organization
SQL Structure: Organize SQL code in /sql/queries (for sqlc files) and /sql/migrations (for migrations).
Domain Structure: Each domain should contain:
/interface: Domain interfaces and contracts
/handler: HTTP handlers with Swagger docs
/usecase: Business logic with dependency injection
/repository: Data access using sqlc-generated code
/sqlc: Auto-generated SQL code
/mock: Generated mock implementations
Database
Selection:
PostgreSQL 18+ for large-scale deployments
MariaDB 11+ for small/medium projects
FerretDB 2.5+ for document stores
Valkey 9+ for key-value storage
Access: Interact with SQL databases using sqlc for type-safe queries and manage migrations with golang-migrate/migrate.
IDs: Use UUIDv7 for unique identifiers throughout the system.
Transactions: Handle database transactions in the repository layer using sqlc-generated code.
Dependencies
DI Container: Use samber/do for dependency injection.
Utilities: Use samber/lo for sync helpers and samber/ro for stream processing utilities.
Auth: Implement authentication with golang-jwt/jwt (primary) or zitadel/oidc (alternative).
Mocking: Use uber-go/mock and DATA-DOG/go-sqlmock for mocking dependencies in tests.
Security & Performance
Security: Enforce rate limiting, input validation, HTTPS, and structured error handling in all services.
Performance: Follow patterns from goperf.dev for optimal performance.
Monitoring: Implement metrics and health check endpoints for observability.
Configuration: Use environment variables for configuration, ensuring proper validation.
Testing & Deployment
Coverage: Maintain high test coverage across all architectural layers.
Container Support: Ensure all services are compatible with container environments.
Graceful Shutdown: Implement mechanisms for graceful shutdown of services.
CI/CD: Integrate automated testing, quality checks, security scanning, and container deployment within your CI/CD pipeline.
Development Workflow
Write SQL queries with sqlc comments in /sql/queries.
Run go generate ./... to regenerate mocks and SQL code.
Run golangci-lint run --fix ./... to fix linting issues.
Run go clean -testcache to clear the test cache.
Run go test -v -race ./... to execute tests with race detection enabled.
Ambiguity Handling
When the task or provided inputs are ambiguous, ask targeted clarification questions before proceeding rather than guessing.
Tool Boundaries & Argument Validation
Use only tools and utilities specified in these rules. Validate arguments against required formats or tool interfaces before usage. If needed arguments are missing or unclear, request them explicitly rather than making assumptions.
Spec-Driven Development emphasizes intent-driven development where specifications define the "what" before the "how." Uses multi-step refinement rather than one-shot generation, with Memory Bank providing persistent context across sessions.