Summary
src/api/routers/community.py is the single largest file in the codebase at 1,976 lines. This violates the single responsibility principle and makes it difficult to reason about, test, and modify.
Current Structure (problematic)
The file mixes 4 distinct concerns:
- Pydantic model definitions (ChatRequest, ChatMessage, PageContext, etc.)
- Router factory logic for generating per-community endpoints
- Knowledge search and retrieval integration
- Metrics logging and cost tracking
Proposed Split
| Module |
Contents |
Approx Lines |
models.py |
Pydantic request/response models |
~150 lines |
router_factory.py |
create_community_router() factory |
~400 lines |
endpoints/ask.py |
/ask endpoint implementation |
~200 lines |
endpoints/chat.py |
/chat endpoint (SSE streaming) |
~300 lines |
endpoints/sessions.py |
Session management endpoints |
~150 lines |
Acceptance Criteria
Summary
src/api/routers/community.pyis the single largest file in the codebase at 1,976 lines. This violates the single responsibility principle and makes it difficult to reason about, test, and modify.Current Structure (problematic)
The file mixes 4 distinct concerns:
Proposed Split
models.pyrouter_factory.pyendpoints/ask.pyendpoints/chat.pyendpoints/sessions.pyAcceptance Criteria