-
Notifications
You must be signed in to change notification settings - Fork 1
backend
BrunoV21 edited this page Apr 11, 2025
·
1 revision
The Git Recap backend is built using FastAPI and provides RESTful API endpoints along with WebSocket support for real-time updates.
- API Structure
- Core Services
- Authentication Flow
- Environment Variables
- Deployment
- Rate Limiting
- Error Handling
-
GitHub OAuth:
/external-signupendpoint handles OAuth callback -
PAT Authentication:
/patendpoint for Personal Access Token auth - Session Management: JWT-based session tokens with 5-minute expiration
| Endpoint | Method | Description |
|---|---|---|
/repos |
GET | Lists available repositories |
/actions |
GET | Retrieves Git activity data |
/ws/{session_id} |
WebSocket | Real-time LLM response streaming |
- CORS: Configured for frontend integration
- Rate Limiting: Global request throttling
- Request Validation: Pydantic models for input validation
- Manages LLM sessions and configurations
- Handles message trimming and token counting
- Provides simulated responses for testing
- Key methods:
-
generate_response(): Processes user queries -
trim_messages(): Ensures token limits -
count_tokens(): Estimates token usage
-
- Stores and manages Git provider fetchers
- Handles session expiration (5-minute TTL)
- Provides access to repository data
- Supported providers:
- GitHub (via PyGithub)
- GitLab (via python-gitlab)
- Azure DevOps (via azure-devops)
sequenceDiagram
participant Frontend
participant Backend
participant GitProvider
Frontend->>Backend: Initiate OAuth/PAT auth
alt OAuth Flow
Backend->>GitProvider: Redirect to auth page
GitProvider-->>Frontend: User authorization
Frontend->>Backend: Authorization code
Backend->>GitProvider: Exchange code for token
else PAT Flow
Frontend->>Backend: Submit PAT
Backend->>GitProvider: Verify token
end
GitProvider-->>Backend: Return token
Backend->>Frontend: Return session_id (JWT)
# Required
VITE_FRONTEND_HOST= # Frontend origin for CORS
VITE_GITHUB_CLIENT_ID= # GitHub OAuth app ID
VITE_GITHUB_CLIENT_SECRET= # GitHub OAuth secret
SECRET_KEY= # JWT signing key
# Optional
RATE_LIMIT=30 # Requests per window (default: 30)
WINDOW_SECONDS=3 # Rate limit window (default: 3s)
SESSION_TTL=300 # Session timeout in seconds (default: 300)
DEBUG=false # Enable debug modedocker-compose up --builduvicorn main:app --host 0.0.0.0 --port 8000- Use Gunicorn with Uvicorn workers
- Configure HTTPS via reverse proxy (Nginx)
- Set up proper secret management
- Monitor with Prometheus/Grafana
- Global rate limit applied to all endpoints
- Configurable via environment variables
- Returns
429 Too Many Requestswith headers:-
X-RateLimit-Limit: Total allowed requests -
X-RateLimit-Remaining: Remaining requests -
X-RateLimit-Reset: Window reset time
-
Standard error responses include:
{
"detail": "Error message",
"status": "error",
"code": 400
}Common error codes:
-
400: Bad request -
401: Unauthorized -
403: Forbidden -
404: Not found -
429: Rate limited -
500: Server error