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.
- ✅ 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
- 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
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
- Clone the repository
cd leetcode_clone- Create and activate virtual environment
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate- Install dependencies
pip install -r requirements.txt- Run migrations
python manage.py migrate- Create superuser for admin
python manage.py createsuperuser- Add sample problems (via admin or manually)
python manage.py shell- Run development server
python manage.py runserverVisit http://localhost:8000 in your browser.
- 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- 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- Sign Up: Create a new account
- Browse Problems: View all available problems with difficulty filters
- Solve Problems: Click on a problem to open the editor
- Write Code: Write Python code in the provided editor
- Submit: Click "Submit Solution" to run against test cases
- Check Results: See if your solution passed all tests
- Track Progress: View your dashboard and submission history
- Access Django admin at
/admin/ - Add new problems with:
- Title and description
- Difficulty level
- Input/output format specifications
- Sample test cases
- Hidden test cases for validation
- 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
- Accepted: Output matches expected output
- Wrong Answer: Output doesn't match expected
- Runtime Error: Code raises an exception
- Time Limit Exceeded: Execution exceeds 5 seconds
- Push to GitHub
git init
git add .
git commit -m "Initial commit"
git push origin main-
Connect to Render
- Go to render.com
- New → Web Service
- Connect your GitHub repository
- Use
render.yamlfor configuration - Set environment variables
-
Environment Variables
DEBUG: FalseSECRET_KEY: Generate strong keyDATABASE_URL: Render PostgreSQL URL (auto-set)ALLOWED_HOSTS: Your Render domain
-
Build & Deploy
- Build command:
pip install -r requirements.txt && python manage.py collectstatic --noinput && python manage.py migrate - Start command:
gunicorn config.wsgi:application
- Build command:
-
Access Application
- Your app will be available at
https://leetcode-clone.onrender.com
- Your app will be available at
- ✅ 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
- User registration with email validation
- Login/logout with session management
- Dashboard with user-specific data
- Admin interface for problem management
- Create, read problems via admin
- Display problems with difficulty badges
- Filter problems by difficulty
- Show solved/unsolved status
- Large textarea with syntax-like styling
- Default Python template code
- Real-time code submission
- Result display below editor
- Safe Python subprocess execution
- Input/output comparison
- Timeout protection
- Error message capture
- Two-level testing (sample + hidden)
- Store every submission
- Track submission results
- Display submission history
- Show code, result, and timestamp
- Total problems count
- Solved problems count
- Success rate percentage
- Recent submission history
- Progress visualization
- 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
# Reset database
python manage.py flush
python manage.py migrate# Collect static files
python manage.py collectstatic --clear --noinputpython manage.py createsuperuserAccess Django admin at: /admin/
Default admin credentials set during superuser creation.
- Go to
/admin/ - Click "Problems"
- Click "Add Problem"
- Fill in all fields with problem details
- Save and the problem appears on the site
This is a student project. Contributions welcome!
- Create a feature branch
- Make changes
- Test thoroughly
- Submit pull request
MIT License - Feel free to use for educational purposes
For issues or questions, create an issue in the GitHub repository.
Built for learning and interview preparation! 🚀