GitHunt
PR

Pratham-Prog861/code-compete

A competitive coding platform built with Next.js, featuring real-time code execution, problem tracking, and leaderboard rankings.

Code Compete ๐Ÿ†

A competitive coding platform built with Next.js, featuring real-time code execution, problem tracking, and leaderboard rankings.

Features โœจ

  • Problem Solving: Solve coding problems with multiple difficulty levels (Easy, Medium, Hard)
  • Multi-Language Support: Write solutions in JavaScript, Python, C++, and Go
  • Real-Time Code Execution: Execute code using Piston API with instant feedback
  • Test Case Validation: Detailed test results showing input, expected output, and actual output
  • Progress Tracking: Track solved problems and earn points for each solution
  • Leaderboard: Compete with other users and climb the rankings
  • Authentication: Secure user authentication with Clerk
  • Modern UI: Beautiful, responsive interface built with Tailwind CSS and shadcn/ui

Tech Stack ๐Ÿ› ๏ธ

  • Framework: Next.js 16 (App Router)
  • Database: PostgreSQL with Neon
  • ORM: Drizzle ORM
  • Authentication: Clerk
  • Code Editor: Monaco Editor (VS Code editor)
  • Code Execution: Piston API
  • Styling: Tailwind CSS
  • UI Components: shadcn/ui, Radix UI
  • Markdown Rendering: react-markdown with syntax highlighting

Getting Started ๐Ÿš€

Prerequisites

  • Node.js 18+ installed
  • PostgreSQL database (Neon recommended)
  • Clerk account for authentication

Installation

1.Clone the repository:

git clone https://github.com/Pratham-Prog861/code-compete.git
cd code-compete

2.Install dependencies:

npm install

3.Set up environment variables:
Create a .env.local file in the root directory:

# Database
DATABASE_URL=your_neon_database_url

# Clerk Authentication
NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY=your_clerk_publishable_key
CLERK_SECRET_KEY=your_clerk_secret_key
NEXT_PUBLIC_CLERK_SIGN_IN_URL=/sign-in
NEXT_PUBLIC_CLERK_SIGN_UP_URL=/sign-up

4.Push the database schema:

npx drizzle-kit push

5.Seed the database with sample problems:

npx tsx src/db/seed.ts

6.Run the development server:

npm run dev

Open http://localhost:3000 to view the application.

Project Structure ๐Ÿ“

code-compete/
โ”œโ”€โ”€ src/
โ”‚   โ”œโ”€โ”€ app/                    # Next.js app router pages
โ”‚   โ”‚   โ”œโ”€โ”€ api/               # API routes
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ submit/        # Code submission endpoint
โ”‚   โ”‚   โ”œโ”€โ”€ leaderboard/       # Leaderboard page
โ”‚   โ”‚   โ”œโ”€โ”€ problems/          # Problems listing and detail pages
โ”‚   โ”‚   โ””โ”€โ”€ profile/           # User profile page
โ”‚   โ”œโ”€โ”€ components/            # React components
โ”‚   โ”‚   โ”œโ”€โ”€ code-editor.tsx    # Monaco code editor component
โ”‚   โ”‚   โ”œโ”€โ”€ navbar.tsx         # Navigation bar
โ”‚   โ”‚   โ””โ”€โ”€ ui/                # shadcn/ui components
โ”‚   โ”œโ”€โ”€ db/                    # Database configuration
โ”‚   โ”‚   โ”œโ”€โ”€ schema.ts          # Drizzle schema definitions
โ”‚   โ”‚   โ”œโ”€โ”€ index.ts           # Database connection
โ”‚   โ”‚   โ””โ”€โ”€ seed.ts            # Database seeding script
โ”‚   โ””โ”€โ”€ lib/                   # Utility functions
โ”‚       โ”œโ”€โ”€ piston.ts          # Piston API integration
โ”‚       โ””โ”€โ”€ utils.ts           # Helper functions
โ”œโ”€โ”€ public/                    # Static assets
โ””โ”€โ”€ drizzle.config.ts          # Drizzle ORM configuration

Database Schema ๐Ÿ“Š

  • problems: Coding problems with descriptions, test cases, and starter code
  • testCases: Input/output test cases for each problem
  • submissions: User code submissions with status and timestamps
  • solvedProblems: Tracks which problems each user has solved
  • userStats: User statistics including points and problems solved

Features in Detail ๐Ÿ”

Problem Solving

  • View problem descriptions with markdown formatting
  • Write code in an integrated Monaco editor
  • Select from multiple programming languages
  • Run code and see detailed test results

Points System

  • Earn points by solving problems (10 points for Easy problems)
  • Points are awarded only on first successful solve
  • Track your total points and rank on the leaderboard

Leaderboard

  • Real-time rankings based on total points
  • Displays user names, profile pictures, and email
  • Special badges for top 3 users
  • Shows problems solved count and total points

Scripts ๐Ÿ“

  • npm run dev - Start development server
  • npm run build - Build for production
  • npm run start - Start production server
  • npm run lint - Run ESLint
  • npx drizzle-kit push - Push database schema changes
  • npx tsx src/db/seed.ts - Seed database with problems

Contributing ๐Ÿค

Contributions are welcome! Please feel free to submit a Pull Request.

License ๐Ÿ“„

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

Acknowledgments ๐Ÿ™