A FastAPI backend service that supports analyzing code repositories with Google Gemini and providing text and voice explanations with Bland.
- Repository management:
- Clone Git/GitHub repositories
- Upload ZIP repositories
- Analyze repository structure and files
- Integration with Google Gemini:
- Ask questions about code
- Get detailed explanations with code snippets and references
- Voice response generation:
- Convert text explanations to audio
- Calls you like a senior developer would, carefully explaining concepts, and allowing you to "rubber-duck" with AI
- API endpoints for easy integration with Next.js frontend
- Python 3.9+
- Git (for cloning repositories)
- Google Gemini API key
- Bland API key
- Clone this repository:
git clone https://github.com/yourusername/ai-code-explainer-backend.git
cd ai-code-explainer-backend- Create a virtual environment:
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate- Install dependencies:
pip install -r requirements.txt- Create a
.envfile from the example:
cp .env.example .env- Update the
.envfile with your configuration, especially your Gemini API key.
Start the FastAPI server:
uvicorn app.main:app --reloadThe API will be available at http://localhost:8000
You can access the Swagger UI documentation at http://localhost:8000/docs
POST /api/repositories/: Create a new repositoryGET /api/repositories/: List all repositoriesGET /api/repositories/{repository_id}: Get a specific repositoryGET /api/repositories/{repository_id}/files: List files in a repositoryGET /api/repositories/{repository_id}/files/{file_path}: Get file contentDELETE /api/repositories/{repository_id}: Delete a repository
POST /api/questions/: Ask a question about codeGET /api/questions/{question_id}: Get a specific question and its responseGET /api/questions/repository/{repository_id}: Get all questions for a repository
POST /api/audio/generate: Generate audio from textGET /api/audio/files/{filename}: Get an audio fileDELETE /api/audio/files/{filename}: Delete an audio file
See the provided examples for how to integrate this backend with a Next.js frontend:
api.js: API client for making requests to the backendCodeExplainer.js: Example React component for the code explainer UI
/ai-code-explainer-backend
/app
/api
__init__.py
/endpoints
__init__.py
repositories.py
questions.py
audio.py
/core
__init__.py
config.py
security.py
/services
__init__.py
gemini_service.py
voice_service.py
repository_service.py
/models
__init__.py
repository.py
question.py
response.py
/utils
__init__.py
audio_utils.py
code_utils.py
main.py
/tests
__init__.py
/api
/services
requirements.txt
README.md
Contributions are welcome! Please feel free to submit a Pull Request.
This project is licensed under the MIT License - see the LICENSE file for details.