Whenever I request a complex task or code change:
- Do not write the code immediately.
- Enter Plan Mode and present a technical summary of what you intend to do.
- Required refinement: If the task can be done in different ways, stop and ask 2 or 3 strategic questions to validate the approach (e.g. "Should we use NATS or PostgreSQL for this event?"), use the ask_user tool if available.
- Wait for my confirmation or adjustment before proceeding with the implementation.
Secrets is a lightweight secrets manager designed for simplicity and security. It provides envelope encryption, transit encryption, API authentication, and cryptographic audit logs. While inspired by HashiCorp Vault, it is intentionally simpler and focuses on ease of use and deployment.
- Language: Go 1.25
- Web Framework: Gin
- Databases: PostgreSQL 12+ and MySQL 8.0+ (driver-agnostic)
- Cryptography:
- Envelope Encryption:
Master Key → KEK → DEK → Secret Data - Algorithms: AES-GCM and ChaCha20-Poly1305
- KMS Support: Google Cloud KMS, AWS KMS, Azure Key Vault, HashiCorp Vault (via
gocloud.dev) - Password Hashing: Argon2id
- Audit Log Signing: HMAC-SHA256
- Envelope Encryption:
- Observability: OpenTelemetry metrics with Prometheus export
- CLI Framework:
urfave/cli/v3
The project follows a Modular Clean Architecture (inspired by DDD) located in the internal/ directory. Each module (e.g., auth, secrets, transit, tokenization) is organized into:
domain/: Core entities and repository interfaces.usecase/: Application logic and business rules.service/: Domain-specific services.repository/: Persistence implementation (MySQL/PostgreSQL).http/: Web handlers and middleware.
- Build:
make build(creates binary inbin/app) - Run Server:
make run-server - Run Migrations:
make migrate-up - Test:
make test(unit tests, fast),make test-integration(DB tests),make test-with-db(DB tests with lifecycle),make test-all(complete suite) - Lint:
make lint(runsgolangci-lintwithgosec+govulncheckfor security scanning) - Docker:
make docker-build
Configuration is managed via environment variables (see internal/config/config.go and .env.example). Key variables include:
DB_DRIVER:postgresormysqlDB_CONNECTION_STRING: Database URLKMS_PROVIDER: KMS provider nameKMS_KEY_URI: URI for the master key in KMSAUTH_TOKEN_EXPIRATION_SECONDS: Token TTL
- Standard Go Layout: CLI commands in
cmd/app, core logic ininternal/. - Error Handling: Custom error package in
internal/errors. - Validation: Uses
github.com/jellydator/validationfor request validation. - Mocks: Interface mocks are generated using
mockery(runmake mocks).
Two-Tier Testing Strategy:
- Unit Tests: Fast, in-memory tests (run in parallel, no external dependencies)
- Integration Tests: Database-dependent tests tagged with
//go:build integration
Quick Reference:
make test- Unit tests only (fast feedback)make test-integration- Integration tests only (requires running databases)make test-with-db- Integration tests with automatic DB lifecyclemake test-all- Complete suite (unit + integration)
Build Tags:
- All database-dependent repository tests require
//go:build integrationas first line - Applies to:
internal/*/repository/{postgresql,mysql}/*_test.goandtest/integration/*_test.go
Test Organization:
- Integration tests in
test/integration/are split by feature area (auth_flow, kms_flow, secrets_flow, tokenization_flow, transit_flow, etc.) - Each uses shared
helpers_test.gofor common setup utilities
Critical Requirements:
- Repository: Every new method MUST have tests in BOTH MySQL and PostgreSQL test files with
//go:build integrationtag - HTTP Handlers: Every new handler MUST have unit tests in its
..._handler_test.go - DTOs: Every new mapping function MUST have unit tests for payload accuracy
- Usecases: Every new method MUST have unit tests in its
..._usecase_test.go
CI: Unit tests run first (fast feedback), then integration tests (comprehensive validation). See docs/contributing.md for complete testing guide.
- ADRs: Major architectural decisions are documented as Architecture Decision Records in
docs/adr/. - Documentation: Maintain concise, reference-oriented documentation in the
docs/directory following the Diátaxis framework principles. Avoid lengthy paragraphs in favor of bullet points, tables, and centralized code examples. CRITICAL CI RULES:- Changelog: Every new version MUST be added to the high-level
CHANGELOG.mdin the root directory. - Main Version: The
versionvariable incmd/app/main.goMUST be updated to match the new release version. - Docs Linting: The command
make docs-lintMUST be executed and all issues resolved. - OpenAPI Spec: Any new API handler or configuration change MUST be reflected in
docs/openapi.yaml.
- Changelog: Every new version MUST be added to the high-level
- Migrations: New database changes must include both
upanddownSQL scripts for both MySQL and PostgreSQL.
- Linting:
golangci-lintis mandatory (includesgosecfor security checks). - Security Scanning:
gosecruns viagolangci-lintfor static security analysisgovulncheckscans for known vulnerabilities in dependencies- Both run automatically in
make lintand CI (required to pass before merge) - Auto-installs
govulncheckif not present
- Formatting: Standard
go fmt. - CI/CD: GitHub Actions are used for CI (
.github/workflows/ci.yml).