Skip to content

About

GitHub Profile Analyzer API – A production-ready Node.js backend service that fetches GitHub user data, generates developer insights, and stores analytics in MySQL.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

GitHub Profile Analyzer API

A production-ready Node.js backend service that analyzes GitHub user profiles using the GitHub REST API, generates developer insights, and persists the results in a MySQL database for fast querying and analytics.


Overview

GitHub Profile Analyzer is a RESTful API built with Node.js, Express.js, MySQL, and the GitHub Public API.

The service allows users to:

  • Synchronize GitHub profiles into a local database
  • Generate repository-based developer insights
  • Store profile analytics for future access
  • Search developers by primary programming language
  • Retrieve top influencers based on GitHub stars
  • Generate ecosystem-level analytics
  • Avoid unnecessary GitHub API calls using change detection

The application follows a layered architecture with clear separation between:

  • Controllers
  • Services
  • Repositories
  • Middleware
  • Utilities
  • Database Layer

Features

Core Features

GitHub Profile Synchronization

Fetches public GitHub profile information and repository metadata.

Example:

POST /api/users/sync/octocat

Collected profile data includes:

  • GitHub ID
  • Username
  • Name
  • Company
  • Blog
  • Location
  • Public Repository Count
  • Followers
  • Following

Insight Generation

The system analyzes repositories and generates:

Insight Description
Total Stars Sum of stars across all repositories
Total Forks Sum of forks across all repositories
Top Language Most frequently used language
Repository Count Public repository count
Followers Social influence metric

Example:

{
  "totalStars": 1540,
  "totalForks": 231,
  "topLanguage": "TypeScript"
}

Smart Sync Optimization

Before processing repositories, the application compares:

stored.updated_at === github.updated_at;

If no changes are detected:

{
  "status": "UNCHANGED",
  "message": "GitHub profile unchanged"
}

This reduces:

  • GitHub API consumption
  • Response time
  • Rate-limit exposure

Local Database Access

Fetch previously synchronized profiles without contacting GitHub.

GET /api/users/local/:username

Analytics Dashboard Endpoint

Provides system-wide analytics.

GET /api/users/analytics

Returns:

  • Total synced users
  • Average repositories
  • Ecosystem impact score
  • Top influencer

Top Influencers Ranking

GET /api/users/top?limit=10

Ranks users by:

total_stars DESC

Language Based Search

GET /api/users/search?language=TypeScript

Find developers whose primary language matches the requested ecosystem.


Health Monitoring

GET /health

Returns:

  • Uptime
  • Memory usage
  • Node version
  • Database status
  • Timestamp

Architecture

Client
  |
  v
Routes
  |
  v
Controllers
  |
  v
Services
  |
  v
Repositories
  |
  v
MySQL Database

Layer Responsibilities

Routes

Responsible for:

  • URL mapping
  • Validation middleware
  • Controller delegation

Files:

src/routes/
├── userRoutes.js
└── healthRoutes.js

Controllers

Handle HTTP requests and responses.

Files:

src/controllers/
├── userController.js
└── healthController.js

Services

Contain business logic.

Files:

src/services/
├── githubService.js
├── insightService.js
├── syncService.js
└── userService.js

Responsibilities:

  • GitHub communication
  • Insight generation
  • Synchronization workflow
  • Analytics processing

Repository Layer

Handles database operations.

src/repositories/
└── userRepository.js

Middleware

src/middleware/
├── errorMiddleware.js
└── validateRequest.js

Provides:

  • Global error handling
  • Request validation

Utilities

src/utils/
├── AppError.js
├── asyncHandler.js
├── githubErrorHandler.js
└── validateUser.js

Project Structure

github-profile-analyzer/
│
├── src/
│   ├── config/
│   │   ├── env.js
│   │   └── githubClient.js
│   │
│   ├── controllers/
│   │   ├── healthController.js
│   │   └── userController.js
│   │
│   ├── db/
│   │   ├── connection.js
│   │   └── connectWithRetry.js
│   │
│   ├── middleware/
│   │   ├── errorMiddleware.js
│   │   └── validateRequest.js
│   │
│   ├── repositories/
│   │   └── userRepository.js
│   │
│   ├── routes/
│   │   ├── healthRoutes.js
│   │   └── userRoutes.js
│   │
│   ├── services/
│   │   ├── githubService.js
│   │   ├── insightService.js
│   │   ├── syncService.js
│   │   └── userService.js
│   │
│   ├── tests/
│   │   └── user.test.js
│   │
│   ├── utils/
│   │   ├── AppError.js
│   │   ├── asyncHandler.js
│   │   ├── githubErrorHandler.js
│   │   └── validateUser.js
│   │
│   └── app.js
│
├── docker-compose.yml
├── dockerfile
├── init.sql
├── package.json
└── README.md

Technology Stack

Backend

  • Node.js
  • Express.js

Database

  • MySQL 8

Validation

  • Zod

HTTP Client

  • Axios
  • Axios Retry

Security

  • Helmet
  • Express Rate Limit

Logging

  • Morgan

Testing

  • Jest
  • Supertest

Containerization

  • Docker
  • Docker Compose

Security Features

Helmet

Adds security headers:

app.use(helmet());

Rate Limiting

max: 100 requests
window: 15 minutes

Protects API from abuse.


Input Validation

Implemented using Zod.

Example:

usernameSchema;

Validates:

  • Length
  • Format
  • Consecutive hyphens
  • Illegal characters

Request Size Limits

10kb

Protection against payload abuse.


Environment Validation

All environment variables are validated at startup.

Application fails fast if required variables are missing.


Database Schema

Table: github_users

CREATE TABLE github_users (
    github_id BIGINT PRIMARY KEY,
    login VARCHAR(255) UNIQUE,
    name VARCHAR(255),
    company VARCHAR(255),
    blog VARCHAR(500),
    location VARCHAR(255),

    public_repos INT,
    followers INT,
    following INT,

    total_stars INT,
    total_forks INT,
    top_language VARCHAR(100),

    created_at DATETIME,
    updated_at DATETIME,
    synced_at TIMESTAMP
);

Indexes

idx_login
idx_language
idx_stars
idx_synced_at

Optimized for:

  • User lookups
  • Language search
  • Rankings
  • Recent synchronization queries

API Documentation

Postman Collection

The project includes a comprehensive Postman collection covering:

  • Health checks
  • Profile synchronization
  • Validation testing
  • Analytics endpoints
  • Search functionality
  • Error handling scenarios

Import Collection

  1. Open Postman
  2. Click Import
  3. Select:
postman/GitHub-Profile-Analyzer.postman_collection.json

Environment Variables

{
  "base_url": "http://localhost:5000"
}

For deployed environments:

{
    "base_url": "https://github-profile-analyzer-production.up.railway.app"
}

Health Check

Request

GET /health

Response

{
  "success": true,
  "database": "connected"
}

Sync GitHub Profile

Request

POST /api/users/sync/octocat

Response

{
  "success": true,
  "status": "UPDATED"
}

Fetch All Profiles

Request

GET /api/users

Fetch Single Stored Profile

Request

GET /api/users/local/octocat

Analytics Summary

Request

GET /api/users/analytics

Top Influencers

Request

GET /api/users/top?limit=5

Search By Language

Request

GET /api/users/search?language=TypeScript

Environment Variables

Create a .env file:

PORT=5000

DB_HOST=localhost
DB_USER=root
DB_PASSWORD=root
DB_NAME=githubdb

GITHUB_TOKEN=your_github_token

Local Development Setup

Clone Repository

git clone <repository-url>
cd github-profile-analyzer

Install Dependencies

npm install

Configure Environment

cp .env.example .env

Update values.

Start MySQL

mysql -u root -p

Create database:

CREATE DATABASE githubdb;

Run schema:

mysql -u root -p githubdb < init.sql

Start Application

Development:

npm run dev

Production:

npm start

Docker Deployment

Run Entire Stack

docker compose up --build

Services:

Service Port
API 5000
MySQL 3306

Stop Containers

docker compose down

Testing

Frameworks:

  • Jest
  • Supertest

Run:

npm test

Validation Test Coverage

The project has been successfully tested against:

Profile Synchronization

✓ Standard user synchronization

✓ High-volume organization accounts

✓ Enterprise repositories

✓ Repeat sync cache detection


Input Validation

✓ Invalid username

✓ Consecutive hyphens

✓ Length violations

✓ Illegal characters

✓ Empty language query

✓ Invalid limits


Database Access

✓ Fetch all users

✓ Fetch local user

✓ Missing user handling


Analytics

✓ Analytics summary

✓ Top influencers

✓ Custom limit values

✓ Language ecosystem filtering


Health Monitoring

✓ Health endpoint

✓ Database connectivity

✓ Runtime metadata


Error Handling

Centralized error architecture.

Examples:

GitHub User Not Found

{
  "success": false,
  "message": "GitHub user not found"
}

Validation Error

{
  "success": false,
  "message": "Invalid GitHub username format"
}

GitHub Rate Limit

{
  "success": false,
  "message": "GitHub API rate limit exceeded"
}

Performance Optimizations

Database Indexing

Optimized search and ranking queries.

Connection Pooling

connectionLimit: 10;

Retry Strategy

GitHub API requests automatically retry transient failures.

Change Detection

Avoids unnecessary synchronization operations.


Future Improvements

Potential enhancements:

  • Redis caching layer
  • GitHub GraphQL API integration
  • Historical profile tracking
  • Scheduled background synchronization
  • Pagination support
  • OpenAPI / Swagger documentation
  • Authentication & RBAC
  • Prometheus metrics
  • CI/CD pipeline
  • GitHub Actions deployment

Assignment Requirements Mapping

Requirement Status
Node.js Completed
Express.js Completed
MySQL Completed
GitHub API Integration Completed
Store Insights Completed
Persist Data Completed
Fetch All Profiles API Completed
Fetch Single Profile API Completed
Docker Support Completed
Validation Layer Completed
Error Handling Completed
Automated Testing Completed
Production Hardening Completed

Author

Yash Chincholi

Backend Developer

Node.js • Express.js • MySQL • REST APIs


Built as part of the GitHub Profile Analyzer Backend Engineering Assignment.

About

GitHub Profile Analyzer API – A production-ready Node.js backend service that fetches GitHub user data, generates developer insights, and stores analytics in MySQL.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages