Skip to content

nguyennguyen-computing/leetcode-clone

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

4 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸš€ LeetCode Clone

A comprehensive, full-stack LeetCode clone featuring a modern Angular frontend and robust Go backend with real-time code execution, user authentication, and problem management.

Go Version Angular Version PostgreSQL Docker

✨ Features

πŸ” Authentication & User Management

  • JWT-based authentication system
  • User registration and login
  • Password reset functionality
  • Admin role management
  • Rate limiting for security

πŸ“š Problem Management

  • Complete CRUD operations for coding problems
  • Advanced filtering by difficulty, tags, and search queries
  • Rich problem descriptions with examples and constraints
  • Multi-language support (JavaScript, Python, Java)
  • Template code generation for each language
  • Public and hidden test cases

πŸ’» Code Execution Engine

  • Sandboxed code execution using Docker containers
  • Multi-language support with secure runtime environments
  • Performance monitoring (runtime and memory usage)
  • Timeout and memory limit enforcement
  • Comprehensive error handling and feedback

πŸ“Š Submission System

  • Real-time code submission and evaluation
  • Detailed execution results with test case feedback
  • Submission history with pagination and filtering
  • Performance metrics and statistics tracking
  • User progress tracking and problem completion status
  • Acceptance rate calculations

🎨 Modern Frontend

  • Angular 17 with standalone components (zoneless)
  • NgRx for state management
  • NG-ZORRO UI component library
  • Monaco Editor for code editing with syntax highlighting
  • Tailwind CSS for responsive design
  • Real-time updates and optimistic UI

πŸ›  Tech Stack

Frontend

  • Angular 17 - Modern web framework with standalone components
  • NgRx - Reactive state management
  • NG-ZORRO - Enterprise-class UI components
  • Tailwind CSS - Utility-first CSS framework
  • Monaco Editor - VS Code editor for the web
  • TypeScript - Type-safe JavaScript

Backend

  • Go 1.21 - High-performance backend language
  • Gin - Fast HTTP web framework
  • PostgreSQL 15 - Robust relational database
  • JWT - Secure authentication tokens
  • Docker - Containerized code execution
  • GORM - Go ORM for database operations

Infrastructure

  • Docker & Docker Compose - Containerization and orchestration
  • Colima - Docker container management for macOS
  • PostgreSQL - Primary database
  • Nginx - Production web server

πŸš€ Quick Start

Prerequisites

  • Node.js 20+
  • Go 1.21+
  • Docker & Docker Compose
  • Colima (for macOS users)

1. Clone and Setup

git clone <repository-url>
cd leetcode-clone

# Setup Colima (macOS only)
./setup-colima.sh

2. Development Environment

# Quick setup with sample data
make setup-dev

# Or manual setup
docker-compose -f docker-compose.dev.yml up -d
make seed-db

3. Access the Application

πŸ“– API Documentation

πŸ” Authentication Endpoints

POST   /api/v1/auth/register              - User registration
POST   /api/v1/auth/login                 - User login
POST   /api/v1/auth/password-reset        - Request password reset
POST   /api/v1/auth/password-reset/confirm - Confirm password reset

πŸ“š Problem Management

# Public Endpoints
GET    /api/v1/problems                   - List problems with filtering
GET    /api/v1/problems/search            - Search problems
GET    /api/v1/problems/:id               - Get problem by ID
GET    /api/v1/problems/slug/:slug        - Get problem by slug
GET    /api/v1/problems/:id/testcases     - Get test cases

# Admin Endpoints (Authentication Required)
POST   /api/v1/admin/problems             - Create problem
PUT    /api/v1/admin/problems/:id         - Update problem
DELETE /api/v1/admin/problems/:id         - Delete problem
POST   /api/v1/admin/problems/:id/testcases - Create test case
PUT    /api/v1/admin/testcases/:id        - Update test case
DELETE /api/v1/admin/testcases/:id        - Delete test case

πŸ’» Code Execution

POST   /api/v1/execute/run                - Run code against public test cases
POST   /api/v1/execute/submit             - Submit code for evaluation
POST   /api/v1/execute/validate           - Validate code syntax
GET    /api/v1/execute/languages          - Get supported languages

πŸ“Š Submission Management

POST   /api/v1/submissions                - Create submission
GET    /api/v1/submissions/:id            - Get submission by ID
GET    /api/v1/submissions/me             - Get current user submissions
GET    /api/v1/submissions/stats/me       - Get user statistics
GET    /api/v1/problems/:id/submissions   - Get problem submissions

Query Parameters

  • Pagination: page, page_size (max 100)
  • Filtering: difficulty, tags, problem_id
  • Sorting: sort_by, sort_order
  • Search: q (query string)

πŸ— Project Structure

leetcode-clone/
β”œβ”€β”€ πŸ“ frontend/                    # Angular Application
β”‚   β”œβ”€β”€ πŸ“ src/app/
β”‚   β”‚   β”œβ”€β”€ πŸ“ auth/               # Authentication module
β”‚   β”‚   β”‚   β”œβ”€β”€ πŸ“ components/     # Login, register components
β”‚   β”‚   β”‚   β”œβ”€β”€ πŸ“ guards/         # Route guards
β”‚   β”‚   β”‚   β”œβ”€β”€ πŸ“ services/       # Auth services
β”‚   β”‚   β”‚   └── πŸ“ store/          # NgRx auth state
β”‚   β”‚   β”œβ”€β”€ πŸ“ problems/           # Problem management
β”‚   β”‚   β”‚   β”œβ”€β”€ πŸ“ components/     # Problem list, solve, editor
β”‚   β”‚   β”‚   β”œβ”€β”€ πŸ“ services/       # Problem services
β”‚   β”‚   β”‚   └── πŸ“ store/          # NgRx problem state
β”‚   β”‚   β”œβ”€β”€ πŸ“„ app.config.ts       # App configuration
β”‚   β”‚   └── πŸ“„ app.routes.ts       # Routing configuration
β”‚   β”œβ”€β”€ πŸ“„ package.json
β”‚   β”œβ”€β”€ πŸ“„ angular.json
β”‚   β”œβ”€β”€ πŸ“„ tailwind.config.js
β”‚   └── πŸ“„ Dockerfile
β”œβ”€β”€ πŸ“ backend/                     # Go API Server
β”‚   β”œβ”€β”€ πŸ“ pkg/
β”‚   β”‚   β”œβ”€β”€ πŸ“ auth/               # JWT authentication
β”‚   β”‚   β”œβ”€β”€ πŸ“ database/           # Database connection
β”‚   β”‚   β”œβ”€β”€ πŸ“ execution/          # Code execution engine
β”‚   β”‚   β”œβ”€β”€ πŸ“ handlers/           # HTTP handlers
β”‚   β”‚   β”œβ”€β”€ πŸ“ middleware/         # HTTP middleware
β”‚   β”‚   β”œβ”€β”€ πŸ“ models/             # Data models
β”‚   β”‚   β”œβ”€β”€ πŸ“ repository/         # Data access layer
β”‚   β”‚   └── πŸ“ services/           # Business logic
β”‚   β”œβ”€β”€ πŸ“ migrations/             # Database migrations
β”‚   β”œβ”€β”€ πŸ“ scripts/                # Utility scripts
β”‚   β”œβ”€β”€ πŸ“„ main.go                 # Application entry point
β”‚   β”œβ”€β”€ πŸ“„ go.mod                  # Go dependencies
β”‚   └── πŸ“„ Dockerfile
β”œβ”€β”€ πŸ“„ docker-compose.yml          # Production compose
β”œβ”€β”€ πŸ“„ docker-compose.dev.yml      # Development compose
β”œβ”€β”€ πŸ“„ Makefile                    # Development commands
└── πŸ“„ setup-colima.sh            # macOS Docker setup

πŸ”§ Development

Available Make Commands

make help          # Show all available commands
make setup-dev     # Complete development environment setup
make seed-db       # Seed database with sample problems
make clean-db      # Clear all database data (WARNING!)

Frontend Development

cd frontend
npm install
npm start          # Development server on :4200
npm run build      # Production build
npm test           # Run unit tests
npm run lint       # Code linting

Backend Development

cd backend
go mod download
go run main.go     # Development server on :8080
go test ./...      # Run all tests
go build           # Build binary

Database Operations

# View database schema
cd backend && go run scripts/validate_schema.go

# Seed with sample data
make seed-db

# Connect to database
docker exec -it leetcode-postgres psql -U leetcode -d leetcode

πŸ§ͺ Testing

Backend Testing

# Run all tests
go test ./...

# Run tests with coverage
go test -cover ./...

# Run specific package tests
go test ./pkg/services -v
go test ./pkg/handlers -v

Frontend Testing

# Unit tests
npm test

# E2E tests
npm run e2e

# Test coverage
npm run test:coverage

πŸš€ Deployment

Production Build

# Build and start all services
docker-compose up --build -d

# View logs
docker-compose logs -f

Environment Variables

# Backend (.env)
DB_HOST=postgres
DB_PORT=5432
DB_USER=leetcode
DB_PASSWORD=password
DB_NAME=leetcode
JWT_SECRET=your-secret-key
PORT=8080

# Frontend (environment.prod.ts)
API_URL=http://localhost:8080/api/v1

πŸ“Š Database Schema

Core Tables

  • users - User accounts and authentication
  • problems - Coding problems and metadata
  • test_cases - Problem validation test cases
  • submissions - User code submissions
  • user_progress - Problem completion tracking

Key Features

  • Automatic migrations on startup
  • Foreign key constraints for data integrity
  • Indexes for query performance
  • JSON fields for flexible data storage

πŸ”’ Security Features

Authentication & Authorization

  • JWT tokens with expiration
  • Password hashing with bcrypt
  • Rate limiting on auth endpoints
  • Role-based access control (admin/user)

Code Execution Security

  • Docker sandboxing for code execution
  • Resource limits (CPU, memory, time)
  • Network isolation (no internet access)
  • Input validation and sanitization
  • Dangerous pattern detection

🎯 Current Implementation Status

βœ… Completed Features

  • Authentication System - JWT-based auth with registration/login
  • Problem Management - Full CRUD with advanced filtering
  • Code Execution Engine - Sandboxed multi-language execution
  • Submission System - Complete submission workflow
  • Database Schema - Comprehensive data model
  • API Documentation - Detailed endpoint documentation
  • Testing Suite - Unit and integration tests
  • Docker Setup - Development and production containers

🚧 In Progress

  • Frontend Components - Angular UI implementation
  • Real-time Features - WebSocket integration
  • Advanced Analytics - User performance insights

πŸ“‹ Planned Features

  • Discussion Forum - Problem discussions and solutions
  • Contest System - Timed coding competitions
  • Social Features - User profiles and following
  • Mobile App - React Native mobile client

🀝 Contributing

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

Development Guidelines

  • Follow Go and Angular best practices
  • Write comprehensive tests for new features
  • Update documentation for API changes
  • Use conventional commits for commit messages

πŸ“ License

This project is licensed under the MIT License - see the LICENSE file for details.

πŸ™ Acknowledgments

  • LeetCode for inspiration
  • Angular Team for the amazing framework
  • Go Community for excellent libraries
  • Docker for containerization technology

Built with ❀️ by the development team

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published