Skip to content

Commit 436648f

Browse files
authored
Merge pull request #87 from OpenCodeIntel/refactor/split-main-py
refactor(backend): Split main.py into modular route files
2 parents 2704aa6 + 96e42e2 commit 436648f

13 files changed

Lines changed: 861 additions & 854 deletions

File tree

.github/workflows/ci.yml

Lines changed: 29 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,33 @@ on:
66
pull_request:
77
branches: [ main ]
88

9+
# Explicit permissions for security (CodeQL requirement)
10+
permissions:
11+
contents: read
12+
913
jobs:
14+
# Detect which paths changed
15+
changes:
16+
runs-on: ubuntu-latest
17+
outputs:
18+
backend: ${{ steps.filter.outputs.backend }}
19+
frontend: ${{ steps.filter.outputs.frontend }}
20+
steps:
21+
- uses: actions/checkout@v4
22+
- uses: dorny/paths-filter@v3
23+
id: filter
24+
with:
25+
filters: |
26+
backend:
27+
- 'backend/**'
28+
- 'railway.json'
29+
frontend:
30+
- 'frontend/**'
31+
1032
test-backend:
1133
name: Backend Tests
34+
needs: changes
35+
if: ${{ needs.changes.outputs.backend == 'true' }}
1236
runs-on: ubuntu-latest
1337

1438
steps:
@@ -49,6 +73,8 @@ jobs:
4973
5074
test-frontend:
5175
name: Frontend Tests
76+
needs: changes
77+
if: ${{ needs.changes.outputs.frontend == 'true' }}
5278
runs-on: ubuntu-latest
5379

5480
steps:
@@ -76,12 +102,12 @@ jobs:
76102
security-scan:
77103
name: Security Scan
78104
runs-on: ubuntu-latest
79-
continue-on-error: true # Don't fail build on security warnings
105+
continue-on-error: true
80106

81107
steps:
82108
- uses: actions/checkout@v4
83109
with:
84-
fetch-depth: 0 # Full history for TruffleHog
110+
fetch-depth: 0
85111

86112
- name: Run Trivy vulnerability scanner
87113
uses: aquasecurity/trivy-action@master
@@ -93,24 +119,8 @@ jobs:
93119

94120
- name: Check for secrets
95121
uses: trufflesecurity/trufflehog@main
96-
continue-on-error: true # Don't fail on false positives
122+
continue-on-error: true
97123
with:
98124
path: ./
99125
base: main
100126
head: HEAD
101-
102-
lint:
103-
name: Lint Code
104-
runs-on: ubuntu-latest
105-
continue-on-error: true # Don't fail build on style issues
106-
107-
steps:
108-
- uses: actions/checkout@v4
109-
110-
- name: Lint Python
111-
uses: py-actions/flake8@v2
112-
continue-on-error: true
113-
with:
114-
path: "backend/services"
115-
max-line-length: "120"
116-
ignore: "E501,W503"

backend/dependencies.py

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
"""
2+
Shared dependencies and service instances.
3+
All route modules import from here to avoid circular imports.
4+
"""
5+
from fastapi import HTTPException, Depends
6+
from dotenv import load_dotenv
7+
8+
# Load env vars first
9+
load_dotenv()
10+
11+
from services.indexer_optimized import OptimizedCodeIndexer
12+
from services.repo_manager import RepositoryManager
13+
from services.cache import CacheService
14+
from services.dependency_analyzer import DependencyAnalyzer
15+
from services.style_analyzer import StyleAnalyzer
16+
from services.performance_metrics import PerformanceMetrics
17+
from services.rate_limiter import RateLimiter, APIKeyManager
18+
from services.supabase_service import get_supabase_service
19+
from services.input_validator import InputValidator, CostController
20+
21+
# Service instances (singleton pattern)
22+
indexer = OptimizedCodeIndexer()
23+
cache = CacheService()
24+
repo_manager = RepositoryManager()
25+
dependency_analyzer = DependencyAnalyzer()
26+
style_analyzer = StyleAnalyzer()
27+
metrics = PerformanceMetrics()
28+
29+
# Rate limiting and API key management
30+
rate_limiter = RateLimiter(redis_client=cache.redis if cache.redis else None)
31+
api_key_manager = APIKeyManager(get_supabase_service().client)
32+
cost_controller = CostController(get_supabase_service().client)
33+
34+
35+
def get_repo_or_404(repo_id: str, user_id: str) -> dict:
36+
"""
37+
Get repository with ownership verification.
38+
Returns 404 if not found or user doesn't own it.
39+
"""
40+
repo = repo_manager.get_repo_for_user(repo_id, user_id)
41+
if not repo:
42+
raise HTTPException(status_code=404, detail="Repository not found")
43+
return repo
44+
45+
46+
def verify_repo_access(repo_id: str, user_id: str) -> None:
47+
"""
48+
Verify user has access to repository.
49+
Raises 404 if no access.
50+
"""
51+
if not repo_manager.verify_ownership(repo_id, user_id):
52+
raise HTTPException(status_code=404, detail="Repository not found")

0 commit comments

Comments
 (0)