Architecture overview
GitRead uses a multi-service architecture to transform GitHub repositories into professional README files. The system combines Next.js for the frontend and API layer, a Python microservice for repository ingestion, and AI models for content generation.Request flow
Here’s what happens when you generate a README:User submits repository URL
The user enters a GitHub repository URL in the frontend and clicks Generate.The frontend performs basic validation and checks the user’s credit balance before proceeding.
app/page.tsx
API validates request
The Next.js API route (The API verifies:
/api/generate) receives the request and performs security checks:app/api/generate/route.ts
- User authentication via Clerk
- Valid GitHub URL format
- Sufficient credit balance
- Rate limiting and queue position
Repository ingestion
The API calls a Python microservice hosted at The Python service uses the
https://gitread-api.onrender.com/ingest.app/api/generate/route.ts
gitingest library to:- Clone the repository
- Analyze the directory structure
- Extract and summarize file contents
- Estimate token counts
scripts/git_ingest.py
AI generation
The processed repository data is sent to Google’s Gemini model via OpenRouter.The AI analyzes the repository structure, code patterns, and documentation to generate a comprehensive README.
app/api/generate/route.ts
Credit deduction and storage
After successful generation, the system updates the user’s credits and saves the README:The README is saved to the user’s history:
app/api/generate/route.ts
app/utils/supabase.ts
Core components
Frontend (Next.js + React)
The main application page (app/page.tsx) handles:
- User interface and interaction
- Form submission and validation
- Credit management UI
- README history display
- Markdown editing and preview
app/page.tsx
API layer (Next.js API Routes)
Key API endpoints:POST /api/generate
POST /api/generate
Main endpoint for README generation.Request:Response:
GET/POST /api/credits
GET/POST /api/credits
Manages user credit balance.GET Response:
GET/POST /api/readme-history
GET/POST /api/readme-history
Retrieves and saves README history.GET Response:
Python ingestion service
The ingestion service runs independently and provides:- Repository cloning and analysis
- File content extraction
- Token estimation
- Size and complexity limits
Database (Supabase)
GitRead uses three main tables: user_creditsQueue management
GitRead implements a simple in-memory queue to handle concurrent requests:app/api/generate/route.ts
Error handling
Comprehensive error handling at each layer:Performance optimizations
- Token estimation - Calculate tokens before AI generation to avoid unnecessary API calls
- Credit caching - Refresh credits every 30 seconds instead of on every action
- Temporary files - Use system temp directory for repository processing
- Response streaming - Large README content is handled efficiently
- Queue system - Prevents server overload during high traffic
Security measures
Authentication
- Clerk-based user authentication
- Session validation on every API request
- Secure token handling
URL validation
- Strict GitHub URL format checking
- Path traversal prevention
- Query parameter blocking
API keys
- Environment variable storage
- Service role separation
- API key authentication for microservices
Rate limiting
- Per-user cooldown periods
- Queue-based request throttling
- Maximum concurrent request limits
Next steps
Local development
Set up GitRead for local development and testing
API reference
Detailed API documentation and integration guides
Environment variables
Complete guide to configuration options
Deployment
Deploy your own instance of GitRead