A backend service that analyzes GitHub user profiles using the GitHub public API and stores useful insights in a MySQL database.
- Fetch public GitHub profile data by username
- Calculate extra insights (total stars, forks, top language)
- Store analysis results in MySQL
- Retrieve all analyzed profiles
- Retrieve single profile data
- Duplicate analysis prevention
- Rate limit aware error handling
- Node.js - Runtime environment
- Express.js - Web framework
- MySQL - Database
- GitHub API - Third-party data source
- Axios - HTTP client
- Node.js (v14 or higher)
- MySQL (v5.7 or higher)
- npm or yarn
-
Clone the repository
git clone <your-repo-url> cd github-profile-analyzer
-
Install dependencies
npm install
-
Configure environment variables
Create a
.envfile in the root directory:PORT=3000 DB_HOST=localhost DB_USER=root DB_PASSWORD=your_password DB_NAME=github_analyzer GITHUB_API_URL=https://api.github.com
-
Set up the database
Run the following SQL in your MySQL client:
CREATE DATABASE IF NOT EXISTS github_analyzer; USE github_analyzer; CREATE TABLE IF NOT EXISTS profiles ( id INT AUTO_INCREMENT PRIMARY KEY, username VARCHAR(100) NOT NULL UNIQUE, name VARCHAR(255), bio TEXT, avatar_url VARCHAR(500), public_repos INT DEFAULT 0, followers INT DEFAULT 0, following INT DEFAULT 0, total_stars INT DEFAULT 0, total_forks INT DEFAULT 0, top_language VARCHAR(100), created_at_github DATETIME, analyzed_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, INDEX idx_username (username) );
-
Start the server
# Development npm run dev # Production npm start
Server runs on
http://localhost:3000
http://localhost:3000/api
POST /api/profiles/:username
Analyzes a GitHub profile and stores the insights.
Response (201):
{
"success": true,
"message": "Profile analyzed successfully",
"data": {
"id": 1,
"username": "torvalds",
"name": "Linus Torvalds",
"bio": "Creator of Linux and Git",
"avatar_url": "https://avatars.githubusercontent.com/u/1024025",
"public_repos": 7,
"followers": 204000,
"following": 0,
"total_stars": 15000,
"total_forks": 12000,
"top_language": "C",
"created_at_github": "2011-09-03T15:37:22.000Z"
}
}GET /api/profiles
Returns all previously analyzed profiles.
Response (200):
{
"success": true,
"count": 5,
"data": [...]
}GET /api/profiles/:username
Returns a specific analyzed profile.
Response (200):
{
"success": true,
"data": {...}
}// 404 - User not found on GitHub
{ "success": false, "message": "GitHub user not found" }
// 409 - Profile already analyzed
{ "success": false, "message": "Profile already analyzed" }
// 429 - Rate limit exceeded
{ "success": false, "message": "GitHub API rate limit exceeded. Try again later." }| Column | Type | Description |
|---|---|---|
| id | INT (PK) | Auto-increment ID |
| username | VARCHAR(100) | GitHub username (unique) |
| name | VARCHAR(255) | Display name |
| bio | TEXT | Profile bio |
| avatar_url | VARCHAR(500) | Profile picture URL |
| public_repos | INT | Public repository count |
| followers | INT | Follower count |
| following | INT | Following count |
| total_stars | INT | Stars across all repos |
| total_forks | INT | Forks across all repos |
| top_language | VARCHAR(100) | Most used language |
| created_at_github | DATETIME | GitHub join date |
| analyzed_at | TIMESTAMP | When profile was analyzed |
github-profile-analyzer/
├── src/
│ ├── config/
│ │ └── db.js # Database connection
│ ├── controllers/
│ │ └── profileController.js # Request handlers
│ ├── routes/
│ │ └── profileRoutes.js # API routes
│ ├── services/
│ │ └── githubService.js # GitHub API calls
│ └── index.js # Server entry point
├── .env # Environment variables
├── .gitignore
├── package.json
└── README.md
Test the API using curl or Postman:
# Analyze a profile
curl -X POST http://localhost:3000/api/profiles/torvalds
# Get all profiles
curl http://localhost:3000/api/profiles
# Get single profile
curl http://localhost:3000/api/profiles/torvalds