Skip to content

TILAKMK/LeetCode-Clone

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

LeetCode Clone Platform

A complete LeetCode-like coding platform built with Django. This project provides a student-friendly interface for practicing coding problems with real-time code execution and submission tracking.

Features

  • User Authentication: Sign up, login, logout using Django's built-in authentication
  • Problem Library: Browse problems filtered by difficulty (Easy, Medium, Hard)
  • Code Editor: Write Python code directly in the browser with a code editor
  • Code Execution: Safe Python code execution with timeout protection
  • Result Feedback: Instant feedback on code submissions (Accepted, Wrong Answer, Runtime Error)
  • Submission History: Track all submissions with detailed information
  • User Dashboard: View statistics, progress, and recent submissions
  • Professional UI: Dark-themed UI similar to LeetCode using Bootstrap 5

Tech Stack

  • Backend: Django 4.2 (Python)
  • Frontend: HTML5, CSS3, Bootstrap 5, Vanilla JavaScript
  • Database: SQLite (development), PostgreSQL (production)
  • Deployment: Render with Gunicorn
  • Code Execution: Python subprocess with safety measures

Project Structure

leetcode_clone/
├── accounts/                 # Authentication & user management
│   ├── models.py
│   ├── views.py
│   ├── forms.py
│   ├── urls.py
│   └── admin.py
├── problems/                 # Problem management
│   ├── models.py
│   ├── views.py
│   ├── urls.py
│   └── admin.py
├── submissions/              # Code submissions & execution
│   ├── models.py
│   ├── views.py
│   ├── utils.py            # Code execution logic
│   ├── urls.py
│   └── admin.py
├── config/                   # Django settings
│   ├── settings.py
│   ├── urls.py
│   └── wsgi.py
├── templates/                # HTML templates
│   ├── base.html            # Base template with navbar
│   ├── auth/
│   │   ├── home.html
│   │   ├── signup.html
│   │   ├── login.html
│   │   └── dashboard.html
│   ├── problems/
│   │   ├── problem_list.html
│   │   └── problem_detail.html
│   └── submissions/
│       ├── user_submissions.html
│       └── detail.html
├── static/
│   ├── css/
│   │   └── style.css
│   └── js/
│       └── main.js
├── manage.py
├── requirements.txt
├── render.yaml              # Render deployment config
└── .gitignore

Installation & Setup

Local Development

  1. Clone the repository
cd leetcode_clone
  1. Create and activate virtual environment
python -m venv venv
source venv/bin/activate  # On Windows: venv\Scripts\activate
  1. Install dependencies
pip install -r requirements.txt
  1. Run migrations
python manage.py migrate
  1. Create superuser for admin
python manage.py createsuperuser
  1. Add sample problems (via admin or manually)
python manage.py shell
  1. Run development server
python manage.py runserver

Visit http://localhost:8000 in your browser.

Database Models

Problem Model

- title: CharField (unique problem title)
- description: TextField
- difficulty: Choice (Easy, Medium, Hard)
- input_description: TextField
- output_description: TextField
- sample_input: TextField
- sample_output: TextField
- test_input: TextField (hidden test cases)
- test_output: TextField
- created_at: DateTime
- updated_at: DateTime

Submission Model

- user: ForeignKey to User
- problem: ForeignKey to Problem
- code: TextField (user's submitted code)
- result: Choice (Accepted, Wrong Answer, Runtime Error, Time Limit Exceeded)
- error_message: TextField (optional)
- created_at: DateTime

Usage

For Users

  1. Sign Up: Create a new account
  2. Browse Problems: View all available problems with difficulty filters
  3. Solve Problems: Click on a problem to open the editor
  4. Write Code: Write Python code in the provided editor
  5. Submit: Click "Submit Solution" to run against test cases
  6. Check Results: See if your solution passed all tests
  7. Track Progress: View your dashboard and submission history

For Administrators

  1. Access Django admin at /admin/
  2. Add new problems with:
    • Title and description
    • Difficulty level
    • Input/output format specifications
    • Sample test cases
    • Hidden test cases for validation

Code Execution Details

  • Language: Python only
  • Timeout: 5 seconds per submission
  • Isolation: Uses subprocess for safe execution
  • Input/Output: Compared against expected output
  • Error Handling: Captures runtime errors and timeouts

Execution Results

  1. Accepted: Output matches expected output
  2. Wrong Answer: Output doesn't match expected
  3. Runtime Error: Code raises an exception
  4. Time Limit Exceeded: Execution exceeds 5 seconds

Deployment on Render

Setup Instructions

  1. Push to GitHub
git init
git add .
git commit -m "Initial commit"
git push origin main
  1. Connect to Render

    • Go to render.com
    • New → Web Service
    • Connect your GitHub repository
    • Use render.yaml for configuration
    • Set environment variables
  2. Environment Variables

    • DEBUG: False
    • SECRET_KEY: Generate strong key
    • DATABASE_URL: Render PostgreSQL URL (auto-set)
    • ALLOWED_HOSTS: Your Render domain
  3. Build & Deploy

    • Build command: pip install -r requirements.txt && python manage.py collectstatic --noinput && python manage.py migrate
    • Start command: gunicorn config.wsgi:application
  4. Access Application

    • Your app will be available at https://leetcode-clone.onrender.com

Security Considerations

  • ✅ CSRF protection enabled
  • ✅ Secure code execution with subprocess
  • ✅ Timeout protection (5 seconds)
  • ✅ No shell execution
  • ✅ User authentication required
  • ✅ SQL injection prevention (Django ORM)
  • ✅ WhiteNoise for secure static file serving

Features Implemented

Authentication

  • User registration with email validation
  • Login/logout with session management
  • Dashboard with user-specific data
  • Admin interface for problem management

Problem Management

  • Create, read problems via admin
  • Display problems with difficulty badges
  • Filter problems by difficulty
  • Show solved/unsolved status

Code Editor

  • Large textarea with syntax-like styling
  • Default Python template code
  • Real-time code submission
  • Result display below editor

Code Execution

  • Safe Python subprocess execution
  • Input/output comparison
  • Timeout protection
  • Error message capture
  • Two-level testing (sample + hidden)

Submissions

  • Store every submission
  • Track submission results
  • Display submission history
  • Show code, result, and timestamp

Dashboard

  • Total problems count
  • Solved problems count
  • Success rate percentage
  • Recent submission history
  • Progress visualization

Future Enhancements

  • Multiple programming languages (Java, C++, JavaScript)
  • Syntax highlighting in editor (Ace Editor)
  • Difficulty-wise statistics
  • Leaderboard
  • Problem categories/tags
  • Discussion/comments on problems
  • IDE themes (Light/Dark)
  • Code templates for different languages
  • Time/memory usage tracking
  • Problem editorials/solutions

Troubleshooting

Database Issues

# Reset database
python manage.py flush
python manage.py migrate

Static Files Not Loading

# Collect static files
python manage.py collectstatic --clear --noinput

Create Superuser

python manage.py createsuperuser

Admin Panel

Access Django admin at: /admin/

Default admin credentials set during superuser creation.

Managing Problems

  1. Go to /admin/
  2. Click "Problems"
  3. Click "Add Problem"
  4. Fill in all fields with problem details
  5. Save and the problem appears on the site

Contributing

This is a student project. Contributions welcome!

  1. Create a feature branch
  2. Make changes
  3. Test thoroughly
  4. Submit pull request

License

MIT License - Feel free to use for educational purposes

Support

For issues or questions, create an issue in the GitHub repository.


Built for learning and interview preparation! 🚀

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages