Skip to content

About

This is the backend for the platform AlgoForge - A coding platform like leetcode , constitutes of 4 different microservices - (Problem Service , Evaluator Service , Submission Service and Socket Service) , providing an end to end flow for code execution.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

2 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 

Repository files navigation

AlgoForge

A distributed microservices platform for online coding challenges and automated code evaluation

License: ISC Microservices Node.js MongoDB Docker


Table of Contents


Overview

AlgoForge is a scalable microservices-based platform for competitive programming and code evaluation. It provides a complete solution for creating coding challenges, submitting solutions, executing code in isolated environments, and delivering real-time results to users.

Key Features:

  • 🏗️ Microservices Architecture - Independent, scalable services
  • 🔒 Secure Code Execution - Isolated Docker containers with resource limits
  • ⚡ Real-time Notifications - WebSocket-based instant feedback
  • 📊 Queue-based Processing - Reliable async job handling with BullMQ
  • 🌐 Multi-language Support - Python, Java, C++, JavaScript
  • 🗃️ Distributed Data - MongoDB for persistence, Redis for caching/queuing

System Architecture

The platform consists of four core microservices communicating via REST APIs and message queues:

AlgoForge-HLD

Architecture Flow

  1. Client submits code to Submission Service
  2. Submission Service fetches problem details from Problem Service
  3. Code with test cases is queued to Submission Queue
  4. Evaluator Service consumes job, executes code in Docker container
  5. Results are published to Evaluation Queue
  6. Submission Service updates database and notifies Socket Service
  7. Socket Service sends real-time update to connected client

Microservices

1. Problem Service

Repository: Algoforge-problem-service

Manages coding challenges, test cases, and code stubs.

  • Tech: Node.js + Express.js + MongoDB
  • Port: 3000
  • Responsibilities:
    • CRUD operations for coding problems
    • Test case storage and retrieval
    • Language-specific code template management
    • Markdown sanitization for XSS prevention

Quick Start:

cd Problem-Service
npm install
cp .env.example .env
npm run dev

2. Submission Service

Repository: Algoforge-submission-service

Orchestrates the entire code evaluation workflow.

  • Tech: Node.js + Fastify + MongoDB + BullMQ
  • Port: 3003
  • Responsibilities:
    • Accept user code submissions
    • Fetch problem metadata and inject code stubs
    • Queue jobs for evaluation
    • Process results and update submission status
    • Trigger real-time notifications

Quick Start:

cd Submission-Service
npm install
cp .env.example .env
npm run dev

3. Evaluator Service

Repository: Algoforge-evaluator-service

Executes user code in isolated Docker containers.

  • Tech: Node.js + TypeScript + Docker + BullMQ
  • Port: 3001
  • Responsibilities:
    • Consume jobs from submission queue
    • Execute code in isolated Docker containers (256MB, 2s timeout)
    • Validate output against expected results
    • Publish results to evaluation queue

Quick Start:

cd Evaluator-Service
npm install
cp .env.example .env
npm run dev

4. Socket Service

Repository: Algoforge-socket-service

Provides real-time bidirectional communication.

  • Tech: Node.js + Socket.IO + Redis
  • Port: 3002
  • Responsibilities:
    • Maintain WebSocket connections
    • Store userId to socketId mappings in Redis
    • Deliver instant submission results to connected clients

Quick Start:

cd Socket-Service
npm install
cp .env.example .env
npm run dev

Tech Stack

Backend Services

  • Node.js 18+ - Runtime environment
  • Express.js / Fastify - HTTP frameworks
  • TypeScript - Type-safe development (Evaluator)

Databases & Caching

  • MongoDB 6.0+ - Primary data store
  • Redis 6.0+ - Caching and message queuing

Queue & Messaging

  • BullMQ - Job queue management
  • Socket.IO - Real-time communication

Containerization

  • Docker - Code execution isolation
  • Dockerode - Docker API client

Monitoring & Logging

  • Winston - Structured logging
  • Bull Board - Queue monitoring UI

Prerequisites

Before running AlgoForge, ensure you have:

  • Node.js >= 18.0.0
  • Docker Desktop - Running and accessible
  • MongoDB >= 6.0 (local or Atlas)
  • Redis Server >= 6.0

Quick Verification:

node --version
docker --version
mongosh --eval "db.adminCommand('ping')"
redis-cli ping

Quick Start

1. Clone All Repositories

# Create project directory
mkdir algoforge && cd algoforge

# Clone all services
git clone https://github.com/yourusername/algoforge-problem-service Problem-Service
git clone https://github.com/yourusername/algoforge-submission-service Submission-Service
git clone https://github.com/yourusername/algoforge-evaluator-service Evaluator-Service
git clone https://github.com/yourusername/algoforge-socket-service Socket-Service

2. Start Infrastructure

# Start MongoDB
mongod --dbpath /path/to/data

# Start Redis
redis-server

3. Configure Services

Create .env files in each service directory based on the examples provided in individual READMEs.

4. Install Dependencies

# Install dependencies for all services
cd Problem-Service && npm install && cd ..
cd Submission-Service && npm install && cd ..
cd Evaluator-Service && npm install && cd ..
cd Socket-Service && npm install && cd ..

5. Start Services (Order Matters!)

# Terminal 1 - Problem Service
cd Problem-Service
npm run dev

# Terminal 2 - Socket Service
cd Socket-Service
npm run dev

# Terminal 3 - Evaluator Service
cd Evaluator-Service
npm run dev

# Terminal 4 - Submission Service
cd Submission-Service
npm run dev

6. Verify Services

curl http://localhost:3000/ping  # Problem Service
curl http://localhost:3002/ping  # Socket Service
curl http://localhost:3001/ui    # Evaluator Bull Board
curl http://localhost:3003/api/v1/ping  # Submission Service

Data Flow

Submission Creation Flow

1. Client sends POST /api/v1/submissions to Submission Service
2. Submission Service requests problem details from Problem Service
3. Code stubs are injected into user code
4. Submission saved to MongoDB with status "Pending"
5. Job added to SubmissionQueue (Redis)
6. Client receives submission ID

Code Execution Flow

7. Evaluator Service consumes job from SubmissionQueue
8. Docker container created with user code and test cases
9. Code executed with 2s timeout and 256MB memory limit
10. Output compared against expected results
11. Result published to EvaluationQueue
12. Container removed

Result Notification Flow

13. Submission Service consumes result from EvaluationQueue
14. Database updated with final status (Accepted/Wrong Answer/Error)
15. Notification sent to Socket Service
16. Socket Service emits result to connected client via WebSocket
17. Client displays result in real-time

API Gateway

Currently, services are accessed directly. For production deployment, consider adding an API Gateway (e.g., Kong, Nginx, AWS API Gateway) for:

  • Unified entry point
  • Authentication and authorization
  • Rate limiting
  • Request routing
  • Load balancing

Recommended Structure:

Client → API Gateway → [Problem Service | Submission Service]
                    → WebSocket Gateway → Socket Service

Deployment

Docker Compose (Recommended for Development)

Create docker-compose.yml at root:

version: "3.8"

services:
  mongodb:
    image: mongo:6.0
    ports:
      - "27017:27017"
    volumes:
      - mongo-data:/data/db

  redis:
    image: redis:7-alpine
    ports:
      - "6379:6379"

  problem-service:
    build: ./Problem-Service
    ports:
      - "3000:3000"
    depends_on:
      - mongodb

  socket-service:
    build: ./Socket-Service
    ports:
      - "3002:3002"
    depends_on:
      - redis

  evaluator-service:
    build: ./Evaluator-Service
    ports:
      - "3001:3001"
    depends_on:
      - redis
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock

  submission-service:
    build: ./Submission-Service
    ports:
      - "3003:3003"
    depends_on:
      - mongodb
      - redis

volumes:
  mongo-data:

Start all services:

docker-compose up -d

Production Deployment

For production, consider:

  • Kubernetes - Container orchestration
  • AWS ECS/EKS - Managed container services
  • Horizontal Scaling - Multiple instances per service
  • Load Balancers - Distribute traffic
  • Monitoring - Prometheus + Grafana
  • Logging - ELK Stack (Elasticsearch, Logstash, Kibana)

Monitoring

Queue Monitoring

Access Bull Board UIs:

Health Checks

# Check service health
curl http://localhost:3000/ping
curl http://localhost:3002/ping
curl http://localhost:3003/api/v1/ping

Logs

Each service uses Winston for structured logging. Check logs in:

  • Problem-Service/logs/
  • Submission-Service/logs/
  • Evaluator-Service/logs/
  • Socket-Service/logs/

Contributing

We welcome contributions to any of the AlgoForge microservices!

General Guidelines

  1. Fork the repository you want to contribute to
  2. Create a feature branch (git checkout -b feature/AmazingFeature)
  3. Follow the coding standards of each service
  4. Write tests for new features
  5. Commit your changes (git commit -m 'Add AmazingFeature')
  6. Push to the branch (git push origin feature/AmazingFeature)
  7. Open a Pull Request

Code Standards

  • Use ESLint configurations provided in each service
  • Follow RESTful API design principles
  • Write clear commit messages
  • Document new endpoints in README
  • Add JSDoc comments for complex functions

License

This project is licensed under the ISC License.


Acknowledgments

  • Built with modern microservices architecture principlesAlgoForge-HLD

  • Inspired by platforms like LeetCode, HackerRank, and Codeforces

  • Special thanks to the open-source community


Made with ❤️ by Krrish Kumar
Main Repository • Report Bug • Discussions

⭐ Star this project if you find it helpful!

About

This is the backend for the platform AlgoForge - A coding platform like leetcode , constitutes of 4 different microservices - (Problem Service , Evaluator Service , Submission Service and Socket Service) , providing an end to end flow for code execution.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors