-
Notifications
You must be signed in to change notification settings - Fork 5
Closed
Labels
enhancementNew feature or requestNew feature or requestphase-2Phase 2: Server Layer as Thin AdapterPhase 2: Server Layer as Thin Adapter
Description
Overview
Audit the existing FastAPI server and refactor all routes to delegate logic to core.* modules. The server should be a thin adapter, not contain business logic.
Background
Per the v2 architecture principle:
CLI (typer) ─┬── core.* ─── adapters.*
│
Server (fastapi) ─┘
Server and CLI are siblings, both calling core. This ensures:
- No duplicate logic between CLI and server
- Server can be optional (CLI-first philosophy)
- Easier testing (test core once, not twice)
Deliverables
1. Route Audit
- Inventory all routes in
codeframe/server/andcodeframe/ui/routers/ - For each route, document: current logic location, target core module
- Identify routes with inline business logic that needs extraction
2. Core Module Mapping
Ensure each CLI command has a corresponding core function that the server can also call:
| CLI Command | Core Module | Server Route |
|---|---|---|
cf init |
core.workspace |
POST /api/workspaces |
cf prd add |
core.prd |
POST /api/projects/{id}/prd |
cf prd generate |
core.prd_discovery |
POST /api/projects/{id}/prd/generate |
cf tasks generate |
core.tasks |
POST /api/projects/{id}/tasks/generate |
cf work start |
core.runtime |
POST /api/tasks/{id}/start |
cf work follow |
core.streaming |
GET /api/tasks/{id}/stream |
cf blocker answer |
core.blockers |
POST /api/blockers/{id}/answer |
| ... | ... | ... |
3. Refactor Pattern
For each route:
# Before (inline logic)
@router.post("/tasks/{task_id}/start")
async def start_task(task_id: str):
task = db.get_task(task_id)
task.status = "IN_PROGRESS"
db.save(task)
return {"status": "started"}
# After (delegate to core)
@router.post("/tasks/{task_id}/start")
async def start_task(task_id: str):
from codeframe.core import runtime
result = await runtime.start_task_run(task_id)
return result4. Route Consistency
- One route per CLI command (1:1 mapping)
- Consistent URL patterns:
/api/{resource}/{id}/{action} - Consistent response formats
Acceptance Criteria
- All routes delegate to
core.*modules - No business logic in route handlers (only request parsing, response formatting)
- Route audit document created
- Integration tests pass with refactored routes
Related Issues
- [Phase 2] Complete OpenAPI documentation for all endpoints #119 - OpenAPI documentation (depends on route consistency)
- [Phase 2] Add API pagination support for large datasets #118 - API pagination
- [Phase 2] Implement API Rate Limiting for Security #167 - Rate limiting
References
docs/V2_STRATEGIC_ROADMAP.md- Phase 2 requirementsdocs/CLI_WIREFRAME.md- CLI command → module mapping
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or requestphase-2Phase 2: Server Layer as Thin AdapterPhase 2: Server Layer as Thin Adapter