fetch_ml/internal/api
Jeremie Fraeys db7fbbd8d5
refactor: Phase 5 - split API package into focused files
Reorganized internal/api/ package to follow single-concern principle:

- api/factory.go (new file, 257 lines)
  - Extracted component initialization from server.go
  - initializeComponents(), setupLogger(), initExperimentManager()
  - initTaskQueue(), initDatabase(), initDatabaseSchema()
  - initSecurity(), initJupyterServiceManager(), initAuditLogger()

- api/middleware.go (new file, 31 lines)
  - Extracted wrapWithMiddleware() - security middleware chain
  - Centralized auth, rate limiting, CORS, security headers

- api/server.go (reduced from 446 to 212 lines)
  - Now focused on Server lifecycle: NewServer, Start, WaitForShutdown, Close
  - Removed initialization logic (moved to factory.go)
  - Removed middleware wrapper (moved to middleware.go)

- api/metrics_middleware.go (existing, 64 lines)
  - Already had wrapWithMetrics(), left in place

Lines redistributed: ~180 lines from monolithic server.go
Build status: Compiles successfully
2026-02-17 13:11:02 -05:00
..
helpers refactor: Phase 3 - fix config/storage boundaries 2026-02-17 12:49:53 -05:00
factory.go refactor: Phase 5 - split API package into focused files 2026-02-17 13:11:02 -05:00
handlers.go refactor: improve API structure and WebSocket protocol 2026-02-16 20:38:12 -05:00
health.go feat(api): refactor websocket handlers; add health and prometheus middleware 2026-01-05 12:31:07 -05:00
metrics_middleware.go feat(api): refactor websocket handlers; add health and prometheus middleware 2026-01-05 12:31:07 -05:00
middleware.go refactor: Phase 5 - split API package into focused files 2026-02-17 13:11:02 -05:00
monitoring_config.go feat(api): refactor websocket handlers; add health and prometheus middleware 2026-01-05 12:31:07 -05:00
protocol.go feat(core): API, worker, queue, and manifest improvements 2026-02-12 12:05:17 -05:00
server.go refactor: Phase 5 - split API package into focused files 2026-02-17 13:11:02 -05:00
server_config.go feat(core): API, worker, queue, and manifest improvements 2026-02-12 12:05:17 -05:00
ws_datasets.go refactor: improve API structure and WebSocket protocol 2026-02-16 20:38:12 -05:00
ws_handler.go refactor: improve API structure and WebSocket protocol 2026-02-16 20:38:12 -05:00
ws_jobs.go refactor: Phase 3 - fix config/storage boundaries 2026-02-17 12:49:53 -05:00
ws_jupyter.go refactor: improve API structure and WebSocket protocol 2026-02-16 20:38:12 -05:00
ws_protocol.go refactor: improve API structure and WebSocket protocol 2026-02-16 20:38:12 -05:00
ws_tls_auth.go feat(api): refactor websocket handlers; add health and prometheus middleware 2026-01-05 12:31:07 -05:00
ws_validate.go refactor: Phase 3 - fix config/storage boundaries 2026-02-17 12:49:53 -05:00