Skip to content

refactor: modularize dashboard into SOLID modules with DI and testability#5

Merged
sleipi merged 3 commits into
mainfrom
refactor/dashboard-solid
May 11, 2026
Merged

refactor: modularize dashboard into SOLID modules with DI and testability#5
sleipi merged 3 commits into
mainfrom
refactor/dashboard-solid

Conversation

@sleipi
Copy link
Copy Markdown
Owner

@sleipi sleipi commented May 10, 2026

Summary

  • Extract 1131-line dashboard.ts monolith into 16 focused modules under src/dashboard/
  • Introduce dependency injection via DashboardDeps and MaintenanceDeps patterns (consistent with plugin.ts)
  • Separate concerns: pure template functions, repo-backed services, route handlers, server wrapper
  • Add 67 new unit tests covering all extracted modules (121 total, all passing)

Architecture

src/dashboard/
  services/     - SessionStatsService, DailyTokensService, MaintenanceService (all DI'd via Repos)
  templates/    - Pure render functions (data in -> HTML out), extracted CSS
  routes/       - RouteHandler interface with stats + page routes
  server.ts     - Bun.serve wrapper
  index.ts      - Composition root
src/dashboard.ts - Backward-compatible shim (re-exports for existing tests/symlinks)

Key Changes

  • SRP: Each module has exactly one responsibility
  • DI: All services depend on Repos interface, not SQLite; MaintenanceService has injectable probability/interval config
  • Testability: Templates are pure functions; services/routes fully stubable; maintenance scheduling is deterministic in tests
  • Fault tolerance: All error-swallowing behavior preserved and explicitly tested
  • Zero behavior change: HTTP contract (/, /api/stats) unchanged; existing e2e tests unaffected

sleipi added 3 commits May 10, 2026 22:09
…lity

Extract 1131-line monolith into 16 focused modules:
- services/ (session-stats, daily-tokens, maintenance) with Repos DI
- templates/ (pure render functions, separated CSS)
- routes/ (RouteHandler interface, stats + page routes)
- composition root with DashboardDeps pattern (matching plugin.ts)

Add 67 new unit tests covering all extracted modules.
dashboard.ts remains as backward-compatible shim.
…cy highlighting into refactored dashboard modules

- Resolve merge conflict in src/dashboard.ts keeping shim
- Add directory filter support to SessionStatsService, routes, and templates
- Add /api/directories route
- Add session card recency highlighting (active/recent/idle)
- Add directory filter dropdown with CSS styling
- Update client script for directory filter state persistence
- Add 8 new unit tests (132 total, all passing)
- E2e tests passing
@sleipi sleipi merged commit 7c0af73 into main May 11, 2026
3 checks passed
@sleipi sleipi deleted the refactor/dashboard-solid branch May 11, 2026 08:17
@sleipi sleipi added the enhancement New feature or request label May 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant