Skip to content

refactor(backend): Split main.py into modular route files#87

Merged
DevanshuNEU merged 11 commits into
mainfrom
refactor/split-main-py
Dec 8, 2025
Merged

refactor(backend): Split main.py into modular route files#87
DevanshuNEU merged 11 commits into
mainfrom
refactor/split-main-py

Conversation

@DevanshuNEU

@DevanshuNEU DevanshuNEU commented Dec 8, 2025

Copy link
Copy Markdown
Collaborator

Summary

Refactors the monolithic main.py (826 lines) into modular route files for better maintainability and separation of concerns.

Closes #52

Changes

New Files

File Lines Purpose
dependencies.py 52 Shared service instances and helper functions
routes/health.py 17 Health check endpoint
routes/playground.py 150 Demo/playground endpoints (no auth)
routes/repos.py 218 Repository CRUD + WebSocket indexing
routes/search.py 92 Search and explain endpoints
routes/analysis.py 134 Dependency graph, impact analysis, insights
routes/api_keys.py 59 API key management + metrics

Refactored

  • main.py: 826 → 105 lines (87% reduction)
    • Now contains only: app setup, middleware, router includes, error handlers

Updated Tests

  • Updated imports from main to dependencies and routes.repos
  • All 49 tests passing ✅

Architecture

backend/
├── main.py              # App setup, middleware, router orchestration
├── dependencies.py      # Singleton services, shared helpers
└── routes/
    ├── health.py        # GET /health
    ├── auth.py          # /api/auth/* (existing)
    ├── playground.py    # /api/playground/*
    ├── repos.py         # /api/repos/*
    ├── search.py        # /api/search, /api/explain
    ├── analysis.py      # /api/repos/{id}/dependency-graph, etc.
    └── api_keys.py      # /api/keys/*, /api/metrics

Testing

  • All 49 backend tests pass
  • App imports and starts successfully
  • All 19 endpoints verified via Swagger UI
  • Docker build succeeds

Notes

- Frontend tests only run when frontend/ changes
- Backend tests only run when backend/ changes
- Vercel skips deploy if no frontend changes
- Uses dorny/paths-filter for change detection
- Replace 826 lines with 105 lines
- Import and include all routers
- Add lifespan context for startup/shutdown
- Keep middleware and error handlers
- Change imports from 'main' to 'dependencies' and 'routes.repos'
- Update file path checks to look in route modules instead of main.py
- All 49 tests passing
@vercel

vercel Bot commented Dec 8, 2025

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Preview Comments Updated (UTC)
opencodeintel Ignored Ignored Preview Dec 8, 2025 5:53am

- Fix HIGH: Path traversal in input_validator.py
  - Use os.path.normpath instead of Path.resolve()
  - Avoid filesystem access during validation
  - Safer containment check without symlink resolution

- Fix MEDIUM: Add explicit permissions to CI workflow
  - Add 'contents: read' permission block
  - Limits GITHUB_TOKEN scope per security best practices
@DevanshuNEU DevanshuNEU merged commit 436648f into main Dec 8, 2025
10 checks passed
@DevanshuNEU DevanshuNEU deleted the refactor/split-main-py branch January 5, 2026 04:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

refactor(backend): Split main.py (826 lines) into route modules

1 participant