Skip to content

[Phase 2] Server audit and refactor - routes delegating to core modules #322

@frankbria

Description

@frankbria

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/ and codeframe/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 result

4. 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

References

  • docs/V2_STRATEGIC_ROADMAP.md - Phase 2 requirements
  • docs/CLI_WIREFRAME.md - CLI command → module mapping

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestphase-2Phase 2: Server Layer as Thin Adapter

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions