|
| 1 | +--- |
| 2 | +name: "[P1A] Routerization Complete - Final 4 Endpoints" |
| 3 | +about: Complete routerization by moving remaining 4 endpoints to system_router |
| 4 | +title: "[P1A] Routerization Complete - System Router (4 endpoints)" |
| 5 | +labels: type:refactor, risk:low, area:api, milestone:P1-Foundation |
| 6 | +assignees: '' |
| 7 | +--- |
| 8 | + |
| 9 | +## 🎯 Objective |
| 10 | + |
| 11 | +Complete routerization by moving the final 4 endpoints from `main.py` to `system_router.py`: |
| 12 | +- `/` - Root endpoint |
| 13 | +- `/health` - Health check |
| 14 | +- `/api/status` - System status |
| 15 | +- `/api/validators/metrics` - Validation metrics |
| 16 | + |
| 17 | +## 📋 Scope |
| 18 | + |
| 19 | +**Move-only refactoring** - No logic changes, only code organization. |
| 20 | + |
| 21 | +### Target: |
| 22 | +- Create `backend/api/routers/system_router.py` with 4 endpoints |
| 23 | +- Update `main.py` to include system_router |
| 24 | +- Update `backend/api/routers/__init__.py` |
| 25 | +- Update README.md |
| 26 | + |
| 27 | +## ✅ Acceptance Criteria |
| 28 | + |
| 29 | +1. **All 42 endpoints still work** - No breaking changes |
| 30 | +2. **OpenAPI docs unchanged** - All routes visible at `/docs` |
| 31 | +3. **Pytest passes** - No new test failures introduced |
| 32 | +4. **Code organization** - `main.py` reduced to ~1900 lines (from 2817) |
| 33 | +5. **No linter errors** - Clean code, no `# type: ignore` |
| 34 | + |
| 35 | +## 🔍 Evidence & Self-Critique |
| 36 | + |
| 37 | +### Current State: |
| 38 | +- **File**: `backend/api/main.py` |
| 39 | +- **Lines**: ~1899 (after previous routerization) |
| 40 | +- **Remaining endpoints**: 4 (root, health, status, validators/metrics) |
| 41 | + |
| 42 | +### Endpoint Distribution: |
| 43 | +- ✅ Chat: 4 endpoints → `chat_router.py` |
| 44 | +- ✅ Learning: 19 endpoints → `learning_router.py` |
| 45 | +- ✅ RAG: 4 endpoints → `rag_router.py` |
| 46 | +- ✅ Tiers: 5 endpoints → `tiers_router.py` |
| 47 | +- ✅ SPICE: 6 endpoints → `spice_router.py` |
| 48 | +- ⏳ System: 4 endpoints → `system_router.py` (NEW) |
| 49 | + |
| 50 | +### Assumptions: |
| 51 | +1. ✅ **Move-only is safe** - No logic changes = minimal risk |
| 52 | +2. ✅ **FastAPI routers work** - Standard pattern, well-tested |
| 53 | +3. ⚠️ **Global state access** - Routers need access to global services (rag_retrieval, etc.) - using dependency injection pattern |
| 54 | + |
| 55 | +### Risks & Mitigation: |
| 56 | +- **Risk**: Breaking API contracts |
| 57 | + - **Mitigation**: Move-only, no logic changes, verify endpoints work |
| 58 | +- **Risk**: Import errors |
| 59 | + - **Mitigation**: Test imports, verify all dependencies available |
| 60 | +- **Rollback**: Single commit revert (move-only = easy rollback) |
| 61 | + |
| 62 | +## 🧪 How to Verify |
| 63 | + |
| 64 | +### Manual Testing: |
| 65 | +```bash |
| 66 | +# 1. Start server |
| 67 | +python -m uvicorn backend.api.main:app --reload |
| 68 | + |
| 69 | +# 2. Check OpenAPI docs |
| 70 | +curl http://localhost:8000/docs |
| 71 | + |
| 72 | +# 3. Test system endpoints |
| 73 | +curl http://localhost:8000/ |
| 74 | +curl http://localhost:8000/health |
| 75 | +curl http://localhost:8000/api/status |
| 76 | +curl http://localhost:8000/api/validators/metrics |
| 77 | +``` |
| 78 | + |
| 79 | +### Automated Testing: |
| 80 | +```bash |
| 81 | +# Run all tests |
| 82 | +pytest tests/ -v |
| 83 | + |
| 84 | +# Check for linter errors |
| 85 | +# (No # type: ignore allowed) |
| 86 | +``` |
| 87 | + |
| 88 | +## 📝 Implementation Plan |
| 89 | + |
| 90 | +1. ✅ Create `backend/api/routers/system_router.py` with 4 endpoints |
| 91 | +2. ✅ Update `main.py` to include system_router |
| 92 | +3. ✅ Update `backend/api/routers/__init__.py` |
| 93 | +4. ✅ Update README.md |
| 94 | +5. ⏳ Verify all endpoints work |
| 95 | +6. ⏳ Run pytest |
| 96 | +7. ⏳ Check linter errors |
| 97 | + |
| 98 | +## 🔄 Rollback Plan |
| 99 | + |
| 100 | +If issues arise: |
| 101 | +```bash |
| 102 | +git revert <commit-hash> |
| 103 | +# Or manually revert main.py and delete system_router.py |
| 104 | +``` |
| 105 | + |
| 106 | +Single commit revert is sufficient (move-only refactoring). |
| 107 | + |
| 108 | +## 📊 Expected Results |
| 109 | + |
| 110 | +- **main.py**: Reduced from ~1899 to ~1850 lines |
| 111 | +- **Total routers**: 6 (chat, learning, rag, tiers, spice, system) |
| 112 | +- **All 42 endpoints**: Fully routerized |
| 113 | +- **Code quality**: No linter errors, no `# type: ignore` |
| 114 | + |
0 commit comments