leetcodegenerator Svelte Themes

Leetcodegenerator

Leetcode generator using Flask + Unsloth and Astro + Svelte

AI LeetCode Generator

A modern, AI-powered coding problem generator built with Astro, Svelte, and Python Flask. Generate custom LeetCode-style problems with intelligent difficulty scaling, topic selection, and an integrated code editor.

๐Ÿš€ Features

Frontend (Astro + Svelte)

  • ๐ŸŽฏ Interactive Problem Generator: Select difficulty, topics, and custom requirements
  • ๐Ÿ’ป Integrated Code Editor: Monaco Editor with syntax highlighting for multiple languages
  • ๐Ÿงช Test Runner: Execute and validate solutions with detailed feedback
  • ๐ŸŒ™ Dark/Light Theme: Responsive design with theme toggle
  • ๐Ÿ“ฑ Mobile Responsive: Works seamlessly across all devices
  • โšก Fast Performance: Astro's static site generation with Svelte islands

Backend (Python Flask)

  • ๐Ÿค– AI-Powered Generation: Advanced algorithms for problem creation using multiple AI models
  • ๐Ÿ“Š Difficulty Scaling: Intelligent problem complexity adjustment
  • ๐Ÿ’พ Caching System: Redis-based caching for improved performance
  • ๐Ÿ”’ Rate Limiting: Protection against abuse with Redis-backed rate limiting
  • ๐Ÿ“ˆ Analytics: Problem generation tracking and metrics
  • โšก Code Execution: Integrated Judge0 API for code testing and validation
  • ๐Ÿ—๏ธ Unified Architecture: Centralized service management with database abstraction

๐Ÿ› ๏ธ Tech Stack

Frontend

  • Astro 4.0 - Static site generator with islands architecture
  • Svelte - Reactive UI components
  • Tailwind CSS - Utility-first CSS framework
  • Monaco Editor - VS Code-powered code editor
  • TypeScript - Type-safe development

Backend

  • Python Flask - Lightweight web framework
  • MongoDB - Document database for problem storage
  • Redis - Caching and session management
  • AI Models - Multiple AI providers (OpenAI, Unsloth) for problem generation
  • Judge0 API - Code execution and testing service
  • Flask-CORS - Cross-origin resource sharing
  • Flask-Limiter - Rate limiting with Redis backend

๐Ÿ“ฆ Installation

Prerequisites

  • Node.js 18+ and npm
  • Python 3.8+
  • MongoDB
  • Redis
  • AI API keys (OpenAI recommended)
  • Judge0 API key (for code execution)

Frontend Setup

cd frontend
npm install
npm run dev

The frontend will be available at http://localhost:4321

Backend Setup

cd backend
python -m venv venv
source venv/bin/activate  # On Windows: venv\Scripts\activate
pip install -r requirements.txt

# Copy environment variables
cp .env.example .env
# Edit .env with your configuration

python app.py

The backend API will be available at http://localhost:5000

โš™๏ธ Configuration

Frontend Environment Variables

Create a .env file in the frontend directory:

BACKEND_URL=http://localhost:5000
PUBLIC_APP_NAME="AI LeetCode Generator"

Backend Environment Variables

Create a .env file in the backend directory:

# MongoDB Configuration
MONGO_URI=mongodb://localhost:27017/leetcode_generator

# Redis Configuration
REDIS_URI=redis://localhost:6379

# Judge0 API Configuration
JUDGE0_API_KEY=your_judge0_api_key_here
JUDGE0_API_URL=https://judge0-ce.p.rapidapi.com

# Unsloth AI Model Configuration
UNSLOTH_MODEL_PATH=unsloth/llama-2-7b-chat-bnb-4bit
UNSLOTH_MAX_SEQ_LENGTH=2048
UNSLOTH_DTYPE=float16
UNSLOTH_LOAD_IN_4BIT=true

# Flask Configuration
FLASK_ENV=development
FLASK_DEBUG=true
SECRET_KEY=your_secret_key_here_change_in_production

# Rate Limiting
RATE_LIMIT_STORAGE_URL=redis://localhost:6379
RATE_LIMIT_DEFAULT=100 per hour

# CORS Configuration
CORS_ORIGINS=http://localhost:3000,http://localhost:4321

# Logging
LOG_LEVEL=INFO
LOG_FILE=app.log

๐ŸŽฎ Usage

Generating Problems

  1. Select Difficulty: Choose from Easy, Medium, or Hard
  2. Pick a Topic: Select from 20+ programming topics or leave blank
  3. Custom Requirements: Add specific requirements or constraints
  4. Generate: Click "Generate Problem" to create a new challenge

Coding Interface

  1. Language Selection: Choose from JavaScript, Python, Java, C++, C#, Go, or Rust
  2. Code Editor: Write your solution in the Monaco editor
  3. Run Tests: Execute your code against test cases
  4. View Results: See detailed feedback and performance metrics
  5. Solution: Access reference solutions when needed

API Endpoints

Generate Problem

POST /api/problems/generate-problem
Content-Type: application/json

{
  "topic": "Array",
  "difficulty": "medium",
  "additional_requirements": "Focus on two-pointer technique"
}

Submit Solution

POST /api/submissions/submit
Content-Type: application/json

{
  "problem_id": "problem-id",
  "code": "function solution() { ... }",
  "language": "javascript"
}

๐Ÿ—๏ธ Architecture

Frontend Architecture

frontend/
โ”œโ”€โ”€ src/
โ”‚   โ”œโ”€โ”€ components/          # Svelte components
โ”‚   โ”‚   โ”œโ”€โ”€ LeetCodeGenerator.svelte
โ”‚   โ”‚   โ””โ”€โ”€ CodeEditor.svelte
โ”‚   โ”œโ”€โ”€ layouts/             # Astro layouts
โ”‚   โ”œโ”€โ”€ pages/               # Astro pages and API routes
โ”‚   โ”‚   โ”œโ”€โ”€ index.astro
โ”‚   โ”‚   โ””โ”€โ”€ api/generate.js
โ”‚   โ””โ”€โ”€ styles/              # Global styles
โ”œโ”€โ”€ astro.config.mjs         # Astro configuration
โ”œโ”€โ”€ tailwind.config.mjs      # Tailwind configuration
โ””โ”€โ”€ package.json

Backend Architecture

backend/
โ”œโ”€โ”€ app/
โ”‚   โ”œโ”€โ”€ models/              # Database models
โ”‚   โ”‚   โ”œโ”€โ”€ problem.py
โ”‚   โ”‚   โ””โ”€โ”€ submission.py
โ”‚   โ”œโ”€โ”€ routes/              # API routes
โ”‚   โ”‚   โ”œโ”€โ”€ problems.py
โ”‚   โ”‚   โ”œโ”€โ”€ submissions.py
โ”‚   โ”‚   โ”œโ”€โ”€ ai.py
โ”‚   โ”‚   โ”œโ”€โ”€ code_exec.py
โ”‚   โ”‚   โ””โ”€โ”€ health.py
โ”‚   โ”œโ”€โ”€ services/            # Business logic services
โ”‚   โ””โ”€โ”€ database.py          # Database configuration
โ”œโ”€โ”€ db/                      # Database management
โ”‚   โ””โ”€โ”€ __init__.py          # Unified database manager
โ”œโ”€โ”€ services/                # Core services
โ”‚   โ”œโ”€โ”€ ai_service.py        # AI service integration
โ”‚   โ”œโ”€โ”€ code_exec.py         # Code execution service
โ”‚   โ””โ”€โ”€ problem_gen.py       # Problem generation service
โ”œโ”€โ”€ models/                  # AI models
โ”‚   โ”œโ”€โ”€ llama_model.py
โ”‚   โ””โ”€โ”€ mistral_model.py
โ”œโ”€โ”€ utils/                   # Utility functions
โ”‚   โ”œโ”€โ”€ formatters.py        # Response formatting
โ”‚   โ”œโ”€โ”€ validators.py        # Input validation
โ”‚   โ””โ”€โ”€ prompt_templates.py  # AI prompt templates
โ”œโ”€โ”€ app.py                   # Flask application
โ””โ”€โ”€ requirements.txt

๐Ÿงช Testing

Frontend Testing

cd frontend
npm run test
npm run test:e2e

Backend Testing

cd backend
python -m pytest tests/

๐Ÿš€ Deployment

Frontend (Vercel/Netlify)

npm run build
# Deploy dist/ folder

Backend (Docker)

docker build -t leetcode-generator-backend .
docker run -p 5000:5000 leetcode-generator-backend

๐Ÿค Contributing

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

๐Ÿ“ License

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

๐Ÿ™ Acknowledgments

  • Astro Team - For the amazing static site generator
  • Svelte Team - For the reactive UI framework
  • Monaco Editor - For the powerful code editor
  • OpenAI - For AI-powered problem generation
  • LeetCode - For inspiration and problem format

๐Ÿ“ž Support

If you have any questions or need help:


Happy Coding! ๐ŸŽ‰

Top categories

Loading Svelte Themes