Skip to content

Conversation

@webcpu
Copy link
Owner

@webcpu webcpu commented Dec 29, 2025

⏺ Clean Architecture Migration

Restructure codebase into layered packages following Clean Architecture principles.

Changes

Architecture:
ClaudeUsageCore (domain) ← ClaudeUsageData (data) ← ClaudeUsage (app)

  • ClaudeUsageCore: Pure domain types, protocols, analytics (zero dependencies)
  • ClaudeUsageData: Repository, parsing, session monitoring
  • ClaudeUsage: SwiftUI presentation layer

- Add ClaudeUsageCore: domain layer with unified models and protocols
- Add ClaudeUsageData: data layer with repository and monitoring
- Add ClaudeMonitorCLI: new unified CLI using ClaudeUsageData
- Rename app from ClaudeCodeUsage to ClaudeUsage
- Unify UsageEntry, TokenCounts, SessionBlock into single definitions
- Establish clean downward dependency flow: App -> Data -> Core
- Remove ClaudeCodeUsageKit dependency from app target
- Add compatibility extensions for Kit API parity:
  - UsageEntry+Compatibility: .cost, .date, individual token fields
  - UsageStats+Compatibility: token accessors, modelCount, legacy init
- Move UsageAnalytics to Core with pure functions
- Add LiveMonitorConversion for SessionBlock/BurnRate boundary conversion
- Update UsageDataLoader to use any UsageRepository protocol
- Update SessionMonitorService to return Core types
- Update all 24 view files to import ClaudeUsageCore

Architecture now flows: App → Core/Data → [LiveMonitor at boundary]
ClaudeCodeUsageKit is no longer required by app (still used by tests)
- Opus: / → / per MTok
- Haiku: /bin/zsh.25/.25 → / per MTok
- Sonnet: unchanged at / per MTok
- Cache pricing: write=1.25x input, read=0.1x input
- Delete Sources/ClaudeCodeUsageKit/ (15 files, ~1500 lines)
- Delete Tests/ClaudeCodeUsageKitTests/ (2 test files)
- Delete Packages/TimingMacro/ (unused after Kit removal)
- Simplify Package.swift (remove Kit product, target, tests)

Architecture now:
  ClaudeUsageCore (domain) ← ClaudeUsageData (data) ← ClaudeUsage (app)
ClaudeUsageData's SessionMonitorImpl already provides the same
functionality using native ClaudeUsageCore types.

Changes:
- Update SessionMonitorService to use SessionMonitorImpl
- Delete LiveMonitorConversion.swift (no longer needed)
- Delete Packages/ClaudeLiveMonitor/ (15 files, ~1000 lines)
- Remove ClaudeLiveMonitor from Package.swift dependencies

Architecture now has zero conversion layers:
  Core (types) ← Data (impl) ← App (uses native types)
Protocols describe capabilities (use -ing/-able suffixes):
- UsageRepository → UsageDataSource
- SessionMonitor → SessionDataSource

Concrete types use clean noun names:
- UsageRepositoryImpl → UsageRepository
- SessionMonitorImpl → SessionMonitor

Per: https://www.swift.org/documentation/api-design-guidelines/
@webcpu webcpu merged commit d5461be into main Dec 29, 2025
@webcpu webcpu deleted the feat/clean-architecture branch December 30, 2025 16:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants