Skip to content

naman22a/leetcode-microservices

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Leetcode Microservices

A fully-featured, scalable LeetCode-style online judge built using a modern microservices architecture. Includes real-time code execution, WebSockets, problem solving interface with Monaco Editor, authenticated user system, distributed queues, and Docker-based isolated execution.

πŸ—οΈ Architecture

This project uses a microservices architecture with 7 independent services communicating through an API Gateway.

Architecture

Service Name Port Description
API Gateway 5000 Entry point, routing, WebSocket support
Users Service 5001 User profiles and account management
Auth Service 5002 Authentication, JWT tokens, sessions
Problems Service 5003 Problem CRUD, metadata, difficulty
Tags Service 5004 Problem categorization and filtering
Companies Service 5005 Company tags and frequency tracking
Submissions Service 5006 Code submission tracking and history
Execution Service 5007 Async code execution via BullMQ workers

🎯 Key Features

  • Real-time code execution with live feedback
  • Monaco Editor with syntax highlighting
  • Docker-based sandboxed execution environment
  • Distributed job processing with BullMQ
  • Full monitoring stack (Prometheus + Grafana + Loki)
  • CI/CD pipeline with GitHub Actions
  • JWT authentication with refresh tokens
  • Email verification and password reset

βš™οΈ Tech Stack

Frontend

  • Beautiful UI with shadcn/ui
  • Problem-solving interface with Monaco Editor
  • Live submission updates using Socket.IO
  • Global state management with Zustand
  • Fully typed with TypeScript
  • Form handling with React Hook Form
  • API interactions using Axios
  • Tailwind CSS styling
  • Day.js for handling timestamps and dates

Backend

  • NestJS for all microservices
  • Redis + BullMQ for distributed queues
  • PostgreSQL (shared DB, Prisma ORM)
  • Socket.IO (real-time communication)
  • Docker containers for isolated code execution
  • JWT authentication
  • Event-driven architecture

DevOps & Infrastructure

  • Docker & Docker Compose - Containerized microservices orchestration
  • GitHub Actions - Automated CI/CD pipeline
  • Prometheus - Metrics collection and monitoring
  • Grafana - Visualization dashboards for system metrics
  • Loki - Centralized log aggregation
  • BullMQ + Redis - Distributed job queues for async processing
  • Nginx - Reverse proxy and load balancing

βš™οΈ Execution Pipeline

  • User clicks "Submit" β†’ Frontend sends code via WebSocket to API Gateway
  • API Gateway β†’ TCP request to Submission Service
  • Submission Service β†’ Publishes job to execution-queue (BullMQ)
  • Execution Service β†’ Consumes job from queue
  • Execution Service β†’ Runs code in sandboxed Docker container
  • Workers β†’ Return execution result
  • Execution Service β†’ Publishes result to results-queue
  • Submission Service β†’ Consumes result from queue
  • Submission Service β†’ Updates database with status/results
  • Submission Service β†’ Publishes notification to notifications-queue
  • API Gateway β†’ Consumes notification event
  • API Gateway β†’ Pushes real-time update through WebSocket to user's browser

✨ Why Microservices?

  • Each service deploys independently
  • Execution workload isolated from main API
  • Faster horizontal scaling
  • Services communicate through queues β†’ highly resilient
  • Matches real LeetCode-scale architecture

πŸ“· Screenshots

Application

Two sum List of Problems

Grafana

Grafana Metrics

πŸšΆπŸ»β€β™‚οΈ Getting started and πŸƒπŸ»β€β™‚οΈ Running the app

Clone the repo

$ git clone https://github.com/naman22a/leetcode-microservices
$ cd leetcode-microservices

copy env files

$ cp .env.example .env
$ cp ./apps/client/.env.example ./apps/client/.env

run the backend (microservices)

$ docker compose up

run the frontend

$ cd ./apps/client
$ pnpm install
$ pnpm dev

πŸ“Š Monitoring Dashboards

After running docker compose up, access:

πŸ§ͺ Running Tests

$ pnpm test

πŸ“‘ API Features (OpenAPI 3.0)

This project includes a complete OAS 3.0 compliant REST API.

πŸ‘€ Users API

Method Endpoint Description
GET /api/users Get all users
PATCH /api/users Update own user details
GET /api/users/me Get authenticated user
GET /api/users/{id} Get user by ID

πŸ” Auth API

Method Endpoint Description
POST /api/auth/register User registration
POST /api/auth/confirm-email/{token} Email verification
POST /api/auth/login Login using credentials
POST /api/auth/logout Logout and invalidate session
POST /api/auth/refresh_token Refresh JWT access token
POST /api/auth/forgot-password Generate password reset link
POST /api/auth/reset-password/{token} Reset password

🧠 Problems API

Method Endpoint
GET /api/problems
POST /api/problems
GET /api/problems/{slug}
DELETE /api/problems/{id}
PATCH /api/problems/{id}

🏷️ Tags API

Method Endpoint
GET /api/tags
GET /api/tags/{id}
POST /api/tags/bulk

🏒 Companies API

Method Endpoint
GET /api/companies
GET /api/companies/{id}
POST /api/companies/bulk

πŸ“ Submissions API

Method Endpoint
GET /api/submissions/{id}

πŸ“ Folder Structure

.
β”œβ”€β”€ apps
β”‚   β”œβ”€β”€ api-gateway
β”‚   β”œβ”€β”€ auth-service
β”‚   β”œβ”€β”€ client
β”‚   β”œβ”€β”€ companies-service
β”‚   β”œβ”€β”€ execution-service
β”‚   β”œβ”€β”€ problems-service
β”‚   β”œβ”€β”€ submissions-service
β”‚   β”œβ”€β”€ tags-service
β”‚   └── users-service
β”œβ”€β”€ assets
β”‚   β”œβ”€β”€ architecture.png
β”‚   β”œβ”€β”€ problems.png
β”‚   └── two-sum.png
β”œβ”€β”€ docker-compose.dev.yml
β”œβ”€β”€ docker-compose.yml
β”œβ”€β”€ Dockerfile.base
β”œβ”€β”€ Dockerfile.web
β”œβ”€β”€ .dockerignore
β”œβ”€β”€ .env
β”œβ”€β”€ .env.example
β”œβ”€β”€ .env.test
β”œβ”€β”€ .gitignore
β”œβ”€β”€ LICENSE
β”œβ”€β”€ nginx.conf
β”œβ”€β”€ .npmrc
β”œβ”€β”€ package.json
β”œβ”€β”€ packages
β”‚   β”œβ”€β”€ config
β”‚   β”œβ”€β”€ constants
β”‚   β”œβ”€β”€ database
β”‚   β”œβ”€β”€ eslint-config
β”‚   β”œβ”€β”€ types
β”‚   └── typescript-config
β”œβ”€β”€ pnpm-lock.yaml
β”œβ”€β”€ pnpm-workspace.yaml
β”œβ”€β”€ .prettierignore
β”œβ”€β”€ .prettierrc
β”œβ”€β”€ README.md
β”œβ”€β”€ tsconfig.json
└── turbo.json

🀝 Contributions

Contributions, issues, and suggestions are welcome! Feel free to fork the repository and submit pull requests.

πŸ“« Stay in touch

πŸ—’οΈ License

Leetcode is GPL V3

About

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published