Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

1 Commit
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ€– AI Code Documentation Generator

A full-stack application that analyzes GitHub repositories, visualizes dependency graphs, and generates comprehensive documentation using Google Gemini AI with real-time streaming.

License Python Node FastAPI Next.js


✨ Features

πŸ“Š Repository Analysis

  • Multi-language parsing (Python, JavaScript, TypeScript)
  • Dependency graph visualization with React Flow
  • Circular dependency detection using DFS algorithm
  • Statistics dashboard showing most imported/importing files
  • Real-time filtering by search query and language

πŸ€– AI-Powered Documentation

  • Streaming documentation generation via Server-Sent Events
  • README.md generation with Chain-of-Thought prompting
  • Unit test generation for individual files
  • Real-time progress tracking with live updates
  • Syntax-highlighted code blocks and markdown rendering

🎨 Interactive UI

  • Zoom, pan, and explore dependency graphs
  • Color-coded nodes by programming language
  • Search and filter capabilities
  • Minimap navigation for large graphs
  • Responsive design optimized for desktop

πŸ”’ Production-Ready

  • Rate limiting with sliding window algorithm
  • Ephemeral storage with automatic cleanup
  • Global error handling with structured responses
  • CORS security configuration
  • Docker containerization with multi-stage builds

πŸ—οΈ Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚    Frontend (Next.js 14 + React Flow)   β”‚
β”‚  β€’ Interactive graph visualization      β”‚
β”‚  β€’ Real-time SSE streaming              β”‚
β”‚  β€’ Zustand state management             β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
              ↓ HTTP/SSE
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚       Backend (FastAPI + Python)        β”‚
β”‚  β€’ Repository cloning & parsing         β”‚
β”‚  β€’ Dependency graph construction        β”‚
β”‚  β€’ Google Gemini AI integration         β”‚
β”‚  β€’ Rate limiting & concurrency control  β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

πŸš€ Quick Start

Prerequisites

  • Python 3.11+
  • Node.js 18+
  • Git
  • Google Gemini API key (Get one here)

1. Clone Repository

git clone https://github.com/yourusername/ai-code-doc-generator.git
cd ai-code-doc-generator

2. Backend Setup

cd backend

# Create virtual environment
python -m venv venv
source venv/bin/activate  # Windows: venv\Scripts\activate

# Install dependencies
pip install -r requirements.txt

# Configure environment
cp .env.example .env
# Edit .env and add your GEMINI_API_KEY

# Create __init__.py files
touch app/{__init__,config/__init__,middleware/__init__,core/__init__,models/__init__,services/__init__,api/__init__,api/v1/__init__,api/v1/routes/__init__}.py

# Start server
python -m app.main

Backend will run at http://localhost:8000

3. Frontend Setup

cd frontend

# Install dependencies
npm install

# Configure environment
cp .env.local.example .env.local

# Start development server
npm run dev

Frontend will run at http://localhost:3000

4. Test the Application

  1. Open http://localhost:3000 in your browser
  2. Enter a GitHub repository URL (e.g., https://github.com/psf/requests)
  3. Click "Analyze" to visualize the dependency graph
  4. Switch to "Generate Docs" tab for AI-powered documentation

🐳 Docker Deployment

# Build and start both services
docker-compose up --build

# Access the application
# Backend: http://localhost:8000
# Frontend: http://localhost:3000

πŸ“– API Documentation

Analysis Endpoints

Analyze Repository Graph

POST /api/v1/analyze/graph
Content-Type: application/json

{
  "url": "https://github.com/pallets/flask"
}

Response:

{
  "nodes": [...],
  "edges": [...],
  "metadata": {
    "repository_url": "https://github.com/pallets/flask",
    "total_files": 45,
    "languages": {"python": 45},
    "analysis_time_seconds": 12.5
  },
  "statistics": {
    "most_imported": [...],
    "most_importing": [...],
    "circular_dependencies": [...]
  }
}

AI Generation Endpoints

Stream Documentation

GET /api/v1/generate/documentation/stream?url=https://github.com/pallets/flask

Response: Server-Sent Events stream with real-time progress

Generate README

POST /api/v1/generate/readme
Content-Type: application/json

{
  "url": "https://github.com/pallets/flask",
  "summary": "A lightweight WSGI web framework"
}

Generate Unit Tests

POST /api/v1/generate/unit-test
Content-Type: application/json

{
  "url": "https://github.com/pallets/flask",
  "file_path": "src/flask/app.py"
}

See API_DOCUMENTATION.md for complete API reference.


🎯 Usage Examples

Analyzing a Repository

import requests

# Analyze repository
response = requests.post(
    'http://localhost:8000/api/v1/analyze/graph',
    json={'url': 'https://github.com/pallets/flask'}
)

data = response.json()
print(f"Found {len(data['nodes'])} files")
print(f"Languages: {data['metadata']['languages']}")

Streaming Documentation

const eventSource = new EventSource(
  'http://localhost:8000/api/v1/generate/documentation/stream?url=https://github.com/pallets/flask'
);

eventSource.addEventListener('file_complete', (e) => {
  const data = JSON.parse(e.data);
  console.log('Documented:', data.file_path);
  console.log('Content:', data.documentation);
});

eventSource.addEventListener('complete', (e) => {
  const data = JSON.parse(e.data);
  console.log(`Done! ${data.total_files_documented} files in ${data.total_time_seconds}s`);
  eventSource.close();
});

βš™οΈ Configuration

Backend Environment Variables

# Required
GEMINI_API_KEY=your_gemini_api_key_here

# Optional (with defaults)
DEBUG=false
HOST=0.0.0.0
PORT=8000

# CORS
CORS_ORIGINS=["http://localhost:3000"]

# Rate Limiting
MAX_CONCURRENT_LLM_CALLS=5
GEMINI_PRO_RPM=2
GEMINI_PRO_RPD=50
GEMINI_FLASH_RPM=10
GEMINI_FLASH_RPD=250

# Timeouts
GITHUB_CLONE_TIMEOUT=300
LLM_REQUEST_TIMEOUT=120

Frontend Environment Variables

NEXT_PUBLIC_API_URL=http://localhost:8000/api/v1

πŸ§ͺ Testing

Backend Tests

cd backend

# Health check
curl http://localhost:8000/api/v1/health

# Analyze repository
curl -X POST http://localhost:8000/api/v1/analyze/graph \
  -H "Content-Type: application/json" \
  -d '{"url": "https://github.com/psf/requests"}'

Frontend Tests

cd frontend

# Run linter
npm run lint

# Type check
npx tsc --noEmit

# Build production
npm run build

End-to-End Testing

See COMPLETE_TESTING_GUIDE.md for comprehensive testing instructions.


πŸ“Š Performance

Analysis Performance

Repository Size Files Analysis Time Memory Usage
Small 10-20 3-5 seconds <100MB
Medium 50-100 8-15 seconds <300MB
Large 200+ 20-40 seconds <500MB

Documentation Generation

Repository Size Generation Time Rate Limit
Small (10-20 files) 30-60 seconds 10 RPM (Flash)
Medium (50-100 files) 2-5 minutes 10 RPM
Large (200+ files) 10-30 minutes May hit RPD

πŸ› οΈ Technology Stack

Backend

  • FastAPI - Modern async web framework
  • Google Generative AI - Gemini 2.0 Flash
  • GitPython - Repository cloning
  • Python AST - Native Python parsing
  • SSE-Starlette - Server-Sent Events streaming
  • Pydantic - Data validation

Frontend

  • Next.js 14 - React framework with App Router
  • React Flow - Graph visualization
  • Dagre - Graph layout algorithm
  • Zustand - State management
  • Tailwind CSS - Utility-first styling
  • React Markdown - Markdown rendering
  • Syntax Highlighter - Code highlighting

Infrastructure

  • Docker - Containerization
  • Uvicorn - ASGI server
  • Nginx - Reverse proxy (production)

πŸ“ Project Structure

ai-code-doc-generator/
β”œβ”€β”€ backend/
β”‚   β”œβ”€β”€ app/
β”‚   β”‚   β”œβ”€β”€ api/v1/routes/      # API endpoints
β”‚   β”‚   β”œβ”€β”€ config/             # Configuration
β”‚   β”‚   β”œβ”€β”€ core/               # Core utilities
β”‚   β”‚   β”œβ”€β”€ middleware/         # Middleware (CORS, rate limiting)
β”‚   β”‚   β”œβ”€β”€ models/             # Pydantic schemas
β”‚   β”‚   β”œβ”€β”€ services/           # Business logic
β”‚   β”‚   └── main.py             # FastAPI application
β”‚   β”œβ”€β”€ temp_repos/             # Ephemeral storage (gitignored)
β”‚   β”œβ”€β”€ requirements.txt        # Python dependencies
β”‚   └── Dockerfile              # Backend container
β”œβ”€β”€ frontend/
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”œβ”€β”€ app/                # Next.js pages
β”‚   β”‚   β”œβ”€β”€ components/         # React components
β”‚   β”‚   β”œβ”€β”€ services/           # API client
β”‚   β”‚   └── store/              # Zustand store
β”‚   β”œβ”€β”€ package.json            # Node dependencies
β”‚   └── Dockerfile              # Frontend container
β”œβ”€β”€ docker-compose.yml          # Multi-container setup
└── README.md                   # This file

πŸ” Security

  • Input Validation: All requests validated with Pydantic models
  • CORS: Configurable allowed origins
  • Rate Limiting: Sliding window algorithm prevents API abuse
  • Ephemeral Storage: Repositories automatically cleaned up
  • No Persistence: Stateless design, no data retention
  • Environment Variables: Sensitive data in environment, not code

🚦 Rate Limiting

Gemini API Limits

Model Requests/Minute Requests/Day
Gemini 2.5 Pro 2 50
Gemini 2.5 Flash 10 250

Global Concurrency

  • Max Concurrent Requests: 5 (configurable)
  • Algorithm: Sliding window with async wait
  • Behavior: Requests wait, don't fail

πŸ› Troubleshooting

"CORS Error" in Frontend

Solution: Verify backend .env includes frontend URL:

CORS_ORIGINS=["http://localhost:3000"]

"Rate Limit Exceeded"

Solution: Wait for rate limit window to reset, or reduce MAX_CONCURRENT_LLM_CALLS

Graph Not Rendering

Solution: Check browser console for errors, verify React Flow CSS loaded

Stream Disconnects

Solution: Check backend logs, verify rate limits, increase timeouts

See Troubleshooting Section for more solutions.


πŸ“š Documentation


🀝 Contributing

Contributions are welcome! Please follow these steps:

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

Development Guidelines

  • Follow PEP 8 for Python code
  • Use TypeScript for all frontend code
  • Write descriptive commit messages
  • Add tests for new features
  • Update documentation as needed

πŸ“ License

This project is licensed under the MIT License - see the LICENSE file for details.


πŸ™ Acknowledgments

  • FastAPI - For the excellent async web framework
  • Google Gemini - For powerful AI capabilities
  • React Flow - For beautiful graph visualization
  • Next.js - For the amazing React framework
  • Tailwind CSS - For utility-first styling

πŸ“§ Contact


πŸ—ΊοΈ Roadmap

Version 1.0 (Current)

  • βœ… Repository analysis
  • βœ… Dependency graph visualization
  • βœ… AI documentation generation
  • βœ… Real-time streaming
  • βœ… Statistics dashboard

πŸ“Š Stats

  • Lines of Code: ~5,000+
  • API Endpoints: 7
  • Technologies: 15+
  • Docker Containers: 2
  • Supported Languages: 3 (Python, JavaScript, TypeScript)

⭐ Star History

If you find this project useful, please consider giving it a star! ⭐


Built with ❀️ using FastAPI, Next.js, and Google Gemini AI

Report Bug Β· Request Feature Β· Documentation

About

πŸš€ Instantly analyze & document any public GitHub repo. AI-powered (Gemini) dependency graphs & docs for Python, JS, TS. Built with Next.js & FastAPI.

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages