refactor: split main.ts god module into focused sub-modules #1137

Closed
opened 2026-05-13 21:28:00 +00:00 by claude-desktop · 0 comments
Collaborator

As a developer maintaining the server, I want main.ts to be a thin bootstrap orchestrator (≤300 lines), so that each concern — HTTP routing, worker registry, task history, SSE broadcast, startup wiring — has a dedicated module that can be read, tested, and changed independently.

Decomposition

  • Extract WorkerRegistry (FIFO queue + concurrency limiter) → infrastructure/worker/worker-registry.ts
  • Extract SSEBroadcaster (per-client streams + fanout) → infrastructure/sse/sse-broadcaster.ts
  • Extract task history append / query → already partially in infrastructure/database/; wire consistently
  • Extract HTTP server construction + route mounting → http/server.ts
  • main.ts becomes: parse env, open DB, construct dependencies, call startServer()

Constraints

  • No change to public HTTP API
  • No change to systemd unit or just dev / just start entrypoints

Out of scope

  • Splitting webhook-config.ts (tracked separately)
  • Splitting board.ts (tracked separately)
  • Drizzle ORM migration

References

  • apps/server/src/main.ts (4924 lines)
  • Codebase audit 2026-05-13
As a developer maintaining the server, I want `main.ts` to be a thin bootstrap orchestrator (≤300 lines), so that each concern — HTTP routing, worker registry, task history, SSE broadcast, startup wiring — has a dedicated module that can be read, tested, and changed independently. ### Decomposition - [ ] Extract `WorkerRegistry` (FIFO queue + concurrency limiter) → `infrastructure/worker/worker-registry.ts` - [ ] Extract `SSEBroadcaster` (per-client streams + fanout) → `infrastructure/sse/sse-broadcaster.ts` - [ ] Extract task history append / query → already partially in `infrastructure/database/`; wire consistently - [ ] Extract HTTP server construction + route mounting → `http/server.ts` - [ ] `main.ts` becomes: parse env, open DB, construct dependencies, call `startServer()` ### Constraints - [ ] No change to public HTTP API - [ ] No change to systemd unit or `just dev` / `just start` entrypoints ### Out of scope - Splitting `webhook-config.ts` (tracked separately) - Splitting `board.ts` (tracked separately) - Drizzle ORM migration ### References - `apps/server/src/main.ts` (4924 lines) - Codebase audit 2026-05-13
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
charles/agent-hooks#1137
No description provided.