Commit Graph

23 Commits

Author SHA1 Message Date
cbd2ae7c0e feat(auth): magic-link request + consume HTTP handlers (ADR-0028 Phase A.4)
Adds the two passwordless-auth endpoints behind /api/v1/auth/:
  POST /magic-link/request   — body {email}; always 200 (no enumeration leak)
  GET  /magic-link/consume   — ?token=...; signs in (signup-on-first-link)

Sign-up flow: first consume for an unknown email creates the user with a
random unguessable bcrypt-hashed password — keeps the schema NOT NULL
constraint while permanently locking the password endpoints out.

Failure modes (missing/expired/already-consumed) collapse to a single
401 to prevent attackers distinguishing them. DB persist failures on
request silently degrade to the generic 200 to avoid leaking internal
state.

Config:
  auth.magic_link.ttl       (default 15m, env DLC_AUTH_MAGIC_LINK_TTL)
  auth.magic_link.base_url  (default http://localhost:8080)

Tests: 11 unit tests against fakes (repo, user service, sender) cover
happy path (new + existing user), normalization, bad JSON, persist
failure, missing/unknown/expired/consumed token, URL builder.
2026-05-05 11:31:48 +02:00
ef32e750ed feat(email): pkg/email + Mailpit docker-compose service (ADR-0029 Phase A.1) (#59)
All checks were successful
CI/CD Pipeline / Build Docker Cache (push) Successful in 13s
CI/CD Pipeline / CI Pipeline (push) Successful in 4m3s
CI/CD Pipeline / Trigger Docker Push (push) Successful in 4s
Co-authored-by: Gabriel Radureau <arcodange@gmail.com>
Co-committed-by: Gabriel Radureau <arcodange@gmail.com>
2026-05-05 10:47:03 +02:00
46df1f6170 🔧 chore(config): defense-in-depth for WatchAndApply test race (Q-038) (#50)
Some checks failed
CI/CD Pipeline / Build Docker Cache (push) Successful in 14s
CI/CD Pipeline / Trigger Docker Push (push) Has been cancelled
CI/CD Pipeline / CI Pipeline (push) Has been cancelled
Co-authored-by: Gabriel Radureau <arcodange@gmail.com>
Co-committed-by: Gabriel Radureau <arcodange@gmail.com>
2026-05-05 09:45:14 +02:00
f97b6874c9 🐛 fix(config): remove racy log.Info in WatchAndApply cancel goroutine (#48)
Some checks failed
CI/CD Pipeline / Build Docker Cache (push) Successful in 11s
CI/CD Pipeline / Trigger Docker Push (push) Has been cancelled
CI/CD Pipeline / CI Pipeline (push) Has been cancelled
Co-authored-by: Gabriel Radureau <arcodange@gmail.com>
Co-committed-by: Gabriel Radureau <arcodange@gmail.com>
2026-05-05 09:40:03 +02:00
3d9746ed65 🐛 fix(ci): remove dollar-double-brace expression from comment that still gets interpolated (#47)
All checks were successful
CI/CD Pipeline / Build Docker Cache (push) Successful in 10s
CI/CD Pipeline / CI Pipeline (push) Successful in 3m44s
CI/CD Pipeline / Trigger Docker Push (push) Successful in 5s
Co-authored-by: Gabriel Radureau <arcodange@gmail.com>
Co-committed-by: Gabriel Radureau <arcodange@gmail.com>
2026-05-05 09:34:00 +02:00
3c73ca39d6 feat(auth): JWT TTL hot-reload + fix hardcoded 24h bug (ADR-0023 Phase 2) (#44)
Some checks failed
CI/CD Pipeline / Build Docker Cache (push) Successful in 23s
CI/CD Pipeline / CI Pipeline (push) Failing after 5m23s
CI/CD Pipeline / Trigger Docker Push (push) Has been skipped
Co-authored-by: Gabriel Radureau <arcodange@gmail.com>
Co-committed-by: Gabriel Radureau <arcodange@gmail.com>
2026-05-05 09:09:22 +02:00
b33ad236e1 feat(config): hot-reload Phase 1 — logging.level (ADR-0023) (#42)
Some checks failed
CI/CD Pipeline / Build Docker Cache (push) Successful in 59s
CI/CD Pipeline / CI Pipeline (push) Failing after 4m3s
CI/CD Pipeline / Trigger Docker Push (push) Has been skipped
Co-authored-by: Gabriel Radureau <arcodange@gmail.com>
Co-committed-by: Gabriel Radureau <arcodange@gmail.com>
2026-05-05 08:45:19 +02:00
358e3df38b feat(cache): add in-memory cache service (ADR-0022 Phase 1 part 2) (#23)
All checks were successful
CI/CD Pipeline / Build Docker Cache (push) Successful in 50s
CI/CD Pipeline / CI Pipeline (push) Successful in 4m22s
CI/CD Pipeline / Trigger Docker Push (push) Successful in 6s
Phase 1 part 2 of ADR-0022 (companion to PR #22 rate-limit). In-memory cache service via go-cache, used by /api/version (60s TTL).

6/6 unit tests pass. ~95% Mistral autonomous via ICM workspace, cost €2.50 stages 01-02 (50% reduction vs T5 thanks to pre-extracted snippets in shared/).

Co-authored-by: Gabriel Radureau <arcodange@gmail.com>
Co-committed-by: Gabriel Radureau <arcodange@gmail.com>
2026-05-03 13:24:17 +02:00
54dd0cc80f feat(server): add per-IP rate limit middleware on /api/v1/greet (#22)
All checks were successful
CI/CD Pipeline / Build Docker Cache (push) Successful in 1m3s
CI/CD Pipeline / CI Pipeline (push) Successful in 4m4s
CI/CD Pipeline / Trigger Docker Push (push) Successful in 6s
Phase 1 of ADR-0022. In-memory per-IP rate limiter on golang.org/x/time/rate. Returns 429 with Retry-After when exceeded. 7 unit tests pass. BDD scenario @skip until testserver rework. Closes #13.

~95% Mistral Vibe autonomous via ICM workspace. Cost ~6.5€ (T5 + resume + trainer commit/PR).

Co-authored-by: Gabriel Radureau <arcodange@gmail.com>
Co-committed-by: Gabriel Radureau <arcodange@gmail.com>
2026-05-03 13:16:29 +02:00
c17fb4f9b4 🐛 fix: emit all config-loading logs in correct JSON format from the start (#16)
Some checks failed
CI/CD Pipeline / Build Docker Cache (push) Successful in 10s
CI/CD Pipeline / CI Pipeline (push) Failing after 4m14s
CI/CD Pipeline / Trigger Docker Push (push) Has been skipped
## Summary

Closes #15

When `logging.json: true` (or `DLC_LOGGING_JSON=true`), the logger was unconditionally initialised to console/text format at the top of `LoadConfig()`, so early log lines — most visibly **"Config file loaded"** — were always written as human-readable text regardless of configuration.

## Root cause

Classic chicken-and-egg: the format flag lives inside the config that is being loaded. The format-switch block only ran *after* `v.Unmarshal()`, too late for the config-file log.

## Changes

### `pkg/config/config.go`
- Add `peekJSONLogging()`: resolves the JSON flag **before** any log is emitted by (1) checking `DLC_LOGGING_JSON` directly via `os.Getenv`, then (2) doing a minimal throwaway Viper pre-read of the config file for the `logging.json` key. This mirrors Viper's own priority order without parsing the full config twice.
- Apply the resolved format immediately and emit **"Logging configured"** as the very first log line.
- Remove the now-redundant format-switch block that ran after `Unmarshal()`.

### `scripts/start-server.sh`, `test-graceful-shutdown.sh`, `test-opentelemetry.sh`
- Replace hardcoded `PROJECT_DIR` path with a dynamic `SCRIPTS_DIR=$(dirname $(realpath ${BASH_SOURCE[0]}))` derivation so scripts work from any worktree or clone location.

## Test plan
- [x] `go test ./pkg/...` — all pass
- [x] `scripts/test-graceful-shutdown.sh` — all JSON valid, all startup logs present
- [x] Manual smoke test: first line is `{"level":"info",...,"message":"Logging configured"}`, every line is valid JSON

Reviewed-on: #16
Co-authored-by: Gabriel Radureau <arcodange@gmail.com>
Co-committed-by: Gabriel Radureau <arcodange@gmail.com>
2026-04-12 23:28:35 +02:00
5eec64e5e8 🧪 test: add JWT secret rotation BDD scenarios and step implementations (#12)
All checks were successful
CI/CD Pipeline / Build Docker Cache (push) Successful in 9s
CI/CD Pipeline / CI Pipeline (push) Successful in 4m15s
CI/CD Pipeline / Trigger Docker Push (push) Has been skipped
 merge: implement JWT secret rotation with BDD scenario isolation

- Implement JWT secret rotation mechanism (closes #8)
- Add per-scenario state isolation for BDD tests (closes #14)
- Validate password reset workflow via BDD tests (closes #7)
- Fix port conflicts in test validation
- Add state tracer for debugging test execution
- Document BDD isolation strategies in ADR 0025
- Fix PostgreSQL configuration environment variables

Generated by Mistral Vibe.
Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
Co-authored-by: Gabriel Radureau <arcodange@gmail.com>
Co-committed-by: Gabriel Radureau <arcodange@gmail.com>
2026-04-11 17:56:45 +02:00
c1e628f339 📝 docs: update comprehensive documentation and project infrastructure
Documentation Updates:
- Enhanced AGENTS.md with user authentication details
- Updated README.md with authentication API documentation
- Added CONTRIBUTING.md guidelines for BDD testing
- Version management guide improvements
- Local CI/CD testing documentation

Project Infrastructure:
- Updated .gitignore for new file patterns
- Enhanced git hooks documentation
- YAML linting configuration
- Script improvements and organization
- Configuration management updates

API Enhancements:
- Greet service integration with authentication
- Server middleware for JWT validation
- Telemetry improvements
- Version management utilities

Generated by Mistral Vibe.
Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
2026-04-09 00:26:15 +02:00
157d8e2d19 🔧 chore: update all references from DanceLessonsCoach to dance-lessons-coach
Some checks failed
CI/CD Pipeline / CI Pipeline (push) Failing after 4m0s
2026-04-06 17:27:07 +02:00
a5344d6ed8 📝 docs: add comprehensive version management and CLI documentation 2026-04-05 11:28:11 +02:00
9336178d73 📝 docs: add ADR for staged-only Git hooks formatting
- Add ADR-0012 documenting the decision to format only staged Go files
- Update ADR README.md with new entry
- Document rationale, alternatives, and verification results
- Include future considerations for monitoring and CI/CD integration

Generated by Mistral Vibe.
Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
2026-04-04 21:36:57 +02:00
875eb09fb7 feat: implement API v2 with feature flag control
- Added /api/v2/greet POST endpoint with JSON request/response

- Implemented ServiceV2 with Hello my friend <name>! greeting format

- Added api.v2_enabled feature flag (default: false)

- Extended BDD tests to cover v2 scenarios

- Maintained full backward compatibility with v1 API

- Added DLC_API_V2_ENABLED environment variable support

- Created ADR 0010-api-v2-feature-flag.md

- Updated configuration system to support API versioning
2026-04-04 20:39:46 +02:00
3c1aaea789 🔧 refactor: move log output setup to config package and change server logs to Trace level 2026-04-04 14:05:06 +02:00
25d8940db4 🔧 config: add log output file configuration and cleanup example files 2026-04-04 13:54:59 +02:00
00e796c608 Enhance build system and logging configuration
- Add scripts/build.sh to compile binaries into bin/ directory

- Move all zerolog setup logic from cmd/server/main.go to pkg/config

- Add log level configuration support (trace, debug, info, warn, error, fatal, panic)

- Simplify cmd/server/main.go from 57 to 27 lines (53% reduction)

- Update .gitignore to use bin/ directory instead of individual files

- Document build process and bin directory in AGENTS.md

- Maintain backward compatibility with all existing functionality
2026-04-04 13:24:33 +02:00
Mistral Vibe
36f0b79b90 Add OpenTelemetry instrumentation with middleware-only approach 2026-04-04 12:19:48 +02:00
Gabriel Radureau
7c5e61c386 Implement comprehensive graceful shutdown with JSON logging
- Added signal.NotifyContext for modern signal handling in cmd/server/main.go
- Implemented BaseContext for proper context propagation to HTTP handlers
- Added readiness drain delay before shutdown for graceful degradation
- Fixed PID detection in start-server.sh to target actual server process
- Added Logging.JSON configuration option with DLC_LOGGING_JSON environment variable
- Created comprehensive test script that validates entire server lifecycle
- Updated documentation with JSON logging configuration examples
- All shutdown logs now appear correctly in JSON format
- Server terminates gracefully on SIGTERM with proper log flushing

The graceful shutdown implementation follows VictoriaMetrics best practices:
1. Catches termination signals (SIGTERM, SIGINT)
2. Stops accepting new requests but allows ongoing requests to complete
3. Waits for active requests to finish within configured timeout
4. Releases resources and performs cleanup
5. Logs all shutdown steps for observability

Test script validates:
- Server startup and API functionality
- Graceful shutdown sequence
- JSON log format validation
- Complete log sequence verification
- Proper signal handling and context propagation

Generated by Mistral Vibe.
Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
2026-04-03 19:23:23 +02:00
Gabriel Radureau
eaaa63d74e Add flexible configuration with custom file path support
\n- Add DLC_CONFIG_FILE environment variable for custom config paths\n- Update config.go to support both default and custom config file locations\n- Update README.md and AGENTS.md with configuration documentation\n- Remove /Users/gabrielradureau/.dancelessonscoach/ directory approach\n- Add os import to config.go\n- Test all configuration scenarios
2026-04-03 15:50:18 +02:00
Gabriel Radureau
8103f64db9 Add configuration management with Viper
- Implement pkg/config package with Viper integration
- Support environment variables with DLC_ prefix
- Add configurable server host, port, and shutdown timeout
- Update server to use configuration values
- Add config.example.yaml template file
- Update AGENTS.md with configuration documentation
- Maintain backward compatibility with default values

Configuration options:
- DLC_SERVER_HOST (default: 0.0.0.0)
- DLC_SERVER_PORT (default: 8080)
- DLC_SHUTDOWN_TIMEOUT (default: 30s)
2026-04-03 13:53:57 +02:00