Skip to content

Commit 5947f04

Browse files
phernandezclaude
andauthored
refactor: composition roots, deps split, and typed API clients (#490 roadmap) (#502)
Signed-off-by: phernandez <[email protected]> Co-authored-by: Claude Opus 4.5 <[email protected]>
1 parent ba1439f commit 5947f04

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+4608
-1284
lines changed

.github/workflows/claude-code-review.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ jobs:
5454
- [ ] Unit tests for new functions/methods
5555
- [ ] Integration tests for new MCP tools
5656
- [ ] Test coverage for edge cases
57+
- [ ] **100% test coverage maintained** (use `# pragma: no cover` only for truly hard-to-test code)
5758
- [ ] Documentation updated (README, docstrings)
5859
- [ ] CLAUDE.md updated if conventions change
5960

CLAUDE.md

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -117,17 +117,38 @@ counter += 1 # track retries for backoff calculation
117117

118118
### Codebase Architecture
119119

120+
See [docs/ARCHITECTURE.md](docs/ARCHITECTURE.md) for detailed architecture documentation.
121+
122+
**Directory Structure:**
120123
- `/alembic` - Alembic db migrations
121-
- `/api` - FastAPI implementation of REST endpoints
122-
- `/cli` - Typer command-line interface
124+
- `/api` - FastAPI REST endpoints + `container.py` composition root
125+
- `/cli` - Typer CLI + `container.py` composition root
126+
- `/deps` - Feature-scoped FastAPI dependencies (config, db, projects, repositories, services, importers)
123127
- `/importers` - Import functionality for Claude, ChatGPT, and other sources
124128
- `/markdown` - Markdown parsing and processing
125-
- `/mcp` - Model Context Protocol server implementation
129+
- `/mcp` - MCP server + `container.py` composition root + `clients/` typed API clients
126130
- `/models` - SQLAlchemy ORM models
127131
- `/repository` - Data access layer
128132
- `/schemas` - Pydantic models for validation
129133
- `/services` - Business logic layer
130-
- `/sync` - File synchronization services
134+
- `/sync` - File synchronization services + `coordinator.py` for lifecycle management
135+
136+
**Composition Roots:**
137+
Each entrypoint (API, MCP, CLI) has a composition root that:
138+
- Reads `ConfigManager` (the only place that reads global config)
139+
- Resolves runtime mode via `RuntimeMode` enum (TEST > CLOUD > LOCAL)
140+
- Provides dependencies to downstream code explicitly
141+
142+
**Typed API Clients (MCP):**
143+
MCP tools use typed clients in `mcp/clients/` to communicate with the API:
144+
- `KnowledgeClient` - Entity CRUD operations
145+
- `SearchClient` - Search operations
146+
- `MemoryClient` - Context building
147+
- `DirectoryClient` - Directory listing
148+
- `ResourceClient` - Resource reading
149+
- `ProjectClient` - Project management
150+
151+
Flow: MCP Tool → Typed Client → HTTP API → Router → Service → Repository
131152

132153
### Development Notes
133154

@@ -146,6 +167,7 @@ counter += 1 # track retries for backoff calculation
146167
- CI runs SQLite and Postgres tests in parallel for faster feedback
147168
- Performance benchmarks are in `test-int/test_sync_performance_benchmark.py`
148169
- Use pytest markers: `@pytest.mark.benchmark` for benchmarks, `@pytest.mark.slow` for slow tests
170+
- **Coverage must stay at 100%**: Write tests for new code. Only use `# pragma: no cover` when tests would require excessive mocking (e.g., TYPE_CHECKING blocks, error handlers that need failure injection, runtime-mode-dependent code paths)
149171

150172
### Async Client Pattern (Important!)
151173

0 commit comments

Comments
 (0)