A production-ready backend API that analyzes GitHub repository languages, computes total usage, stores historical snapshots, and serves publicly accessible endpoints. Built with FastAPI, MongoDB Atlas, and deployed on Render.
This backend project:
- Fetches all repositories of a GitHub user
- Aggregates language usage across all repos
- Computes bytes + percentage usage
- Caches results for 24 hours using MongoDB
- Stores full historical snapshots over time
- Exposes clean API endpoints with Pydantic models
- Runs asynchronously using FastAPI + httpx
- Fully deployed online and globally accessible
Perfect for:
- Developer dashboards
- Portfolio projects
- GitHub analytics tools
- Resume enhancement
- Learning full backend engineering
| Layer | Technology |
|---|---|
| Backend Framework | FastAPI |
| HTTP Client | httpx (async) |
| Database | MongoDB Atlas |
| Driver | Motor (async) |
| Deployment | Render |
| Config | python-dotenv |
| Data Models | Pydantic |
github-stats/
โโโ app/
โ โโโ main.py
โ โโโ github_api.py
โ โโโ stats_service.py
โ โโโ database.py
โ โโโ models.py
โโโ requirements.txt
โโโ .env
โโโ .gitignore
โโโ README.md
Frontend Coming Soon .....
https://githubstats-gqcp.onrender.com/
https://githubstats-gqcp.onrender.com/docs
<img src="https://githubstats-gqcp.onrender.com/card/stats?username=YOUR_GITHUB_USERNAME" />Example:
<img src="https://githubstats-gqcp.onrender.com/card/stats?username=itsdevansh5" />Returns API status.
Example:
{"message": "GitHub Stats API is running!"}Fetches latest GitHub language statistics.
- Fetches repositories
- Aggregates all language data
- Computes percentages
- Saves snapshot
- Uses 24-hour caching
/stats/itsdevansh5
Response:
{
"username": "itsdevansh5",
"cached": false,
"total_bytes": {
"Python": 63697231,
"C++": 224954,
"HTML": 246905
},
"percentages": {
"Python": 93.13,
"C++": 0.33,
"HTML": 0.36
}
}If cached:
{
"cached": true,
...
}Returns all historical snapshots of the user.
Example:
{
"username": "itsdevansh5",
"history": [
{
"fetched_at": "2025-12-10T12:34:11",
"total_bytes": { ... },
"percentages": { ... }
},
{
"fetched_at": "2025-12-11T12:34:11",
"total_bytes": { ... },
"percentages": { ... }
}
]
}Generates a dynamic SVG GitHub stats card for a user.
Query Params:
usernameโ GitHub username (required)
Example:
<img src="https://githubstats-gqcp.onrender.com/card?username=itsdevansh5" />
GitHub returns byte counts:
Python โ 63697231
C++ โ 224954
HTML โ 246905
Percentage formula:
percent = (bytes_of_lang / sum(all_bytes)) ร 100
Rounded to 2 decimals.
Your .env should contain:
MONGO_URL="mongodb+srv://<user>:<password>@cluster.mongodb.net/?retryWrites=true&w=majority"
GITHUB_TOKEN="ghp_your_github_token_here"
.env to GitHub.
Add this to .gitignore:
.env
Build Command
pip install -r requirements.txt
Start Command
uvicorn app.main:app --host=0.0.0.0 --port=$PORT
MONGO_URL=your_url_here
GITHUB_TOKEN=your_token_here
PYTHON_VERSION=3.11
- Add user authentication
- Add rate-limiting per IP
- Add frontend dashboard
- Add export to CSV / JSON
- Add charts (Pie, Bar, Trends)
- Add caching with Redis
- Make it a full SaaS product
Made with โค๏ธ by Devansh
A backend + cloud enthusiast building real-world projects.