Skip to content

feat(api): Add centralized API versioning system (#55)#88

Merged
DevanshuNEU merged 5 commits into
OpenCodeIntel:mainfrom
DevanshuNEU:feature/issue-55-api-versioning
Dec 8, 2025
Merged

feat(api): Add centralized API versioning system (#55)#88
DevanshuNEU merged 5 commits into
OpenCodeIntel:mainfrom
DevanshuNEU:feature/issue-55-api-versioning

Conversation

@DevanshuNEU

Copy link
Copy Markdown
Collaborator

Summary

Implements centralized API versioning with single source of truth pattern across all layers.

Closes #55

Architecture

To upgrade to v2: Change API_VERSION = "v2" in 3 config files. All routes update automatically.

  • backend/config/api.py - Backend config
  • frontend/src/config/api.ts - Frontend config
  • mcp-server/config.py - MCP server config

Changes

Backend

  • Created backend/config/api.py as single source of truth
  • main.py: Apply API_PREFIX to all routers
  • Route files: Remove hardcoded /api, use relative paths
  • Tests updated to use config

Frontend

  • Created frontend/src/config/api.ts with same pattern
  • Updated 8 files to use versioned API_URL

MCP Server

  • Created mcp-server/config.py
  • Updated server.py to use versioned URLs

Final Routes

/health                     → root (no versioning)
/api/v1/auth/*              → versioned
/api/v1/repos/*             → versioned  
/api/v1/search              → versioned
/api/v1/ws/index/{repo_id}  → versioned WebSocket

Testing

  • All 13 backend tests passing
  • Frontend builds successfully
  • TypeScript compilation passes

- Create backend/config/api.py as single source of truth
- API_VERSION constant controls all route prefixes
- API_PREFIX auto-derived: /api/v1
- LEGACY_API_PREFIX for backward compatibility: /api
- Deprecation headers support for legacy routes
- Helper functions for version management

Part of OpenCodeIntel#55
- main.py: import API_PREFIX, apply to all routers
- Route files: remove hardcoded /api, use relative paths
  - auth.py: /api/auth → /auth
  - repos.py: /api/repos → /repos
  - search.py: /api → (empty)
  - analysis.py: /api/repos → /repos
  - api_keys.py: /api → (empty)
  - playground.py: /api/playground → /playground
- WebSocket endpoint now versioned: /api/v1/ws/index/{repo_id}
- Health endpoint stays at root: /health (no versioning)
- Tests: import API_PREFIX, all paths now use config

All 13 tests passing.

Part of OpenCodeIntel#55
- API_VERSION constant controls all frontend API paths
- API_PREFIX auto-derived: /api/v1
- API_URL combines base URL + prefix
- WS_URL for WebSocket connections (versioned)
- Helper functions: buildApiUrl(), buildWsUrl()
- LEGACY_API_URL for backward compatibility

Mirrors backend/config/api.py pattern.

Part of OpenCodeIntel#55
- Remove hardcoded /api/ from all fetch calls
- API_URL now includes /api/v1 prefix from config
- Updated 8 files:
  - components/PerformanceDashboard.tsx
  - components/ImpactAnalyzer.tsx
  - components/SearchPanel.tsx
  - components/dashboard/CommandPalette.tsx
  - components/dashboard/DashboardHome.tsx
  - hooks/useCachedQuery.ts
  - pages/LandingPage.tsx
  - pages/Playground.tsx

Before: ${API_URL}/api/repos
After:  ${API_URL}/repos

Part of OpenCodeIntel#55
- Create mcp-server/config.py as single source of truth
- API_VERSION = 'v1', API_PREFIX = '/api/v1'
- server.py: import API_PREFIX, construct BACKEND_API_URL with version
- Remove hardcoded /api/ from all 6 API calls:
  - /search
  - /repos
  - /repos/{id}/dependencies
  - /repos/{id}/style-analysis
  - /repos/{id}/impact
  - /repos/{id}/insights

Mirrors backend/config/api.py and frontend/config/api.ts pattern.

Part of OpenCodeIntel#55
@vercel

vercel Bot commented Dec 8, 2025

Copy link
Copy Markdown

@DevanshuNEU is attempting to deploy a commit to the Dev's projects Team on Vercel.

A member of the Team first needs to authorize it.

@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 9:21pm

@DevanshuNEU DevanshuNEU merged commit 4f62787 into OpenCodeIntel:main Dec 8, 2025
6 checks passed
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.

feat(backend): Add API versioning (/api/v1/)

1 participant