diff --git a/Readme.md b/Readme.md index c7511f8..d75f99a 100644 --- a/Readme.md +++ b/Readme.md @@ -1,60 +1,73 @@ -# ๐ LeetLab - Advanced Coding Platform +# ๐ CodeArena - Advanced Competitive Programming Platform -LeetLab is a comprehensive full-stack coding platform designed for developers to practice coding problems, participate in contests, access premium problem sheets, and get real-time code execution feedback. Built with modern technologies and containerized for easy deployment. +CodeArena is a comprehensive full-stack competitive programming platform designed for developers to practice coding problems, participate in contests, access premium DSA sheets, and get real-time code execution feedback. Built with modern technologies and containerized for easy deployment. ## โจ Key Features ### Core Functionality -- ๐งฉ **Problem Solving**: Extensive library of coding problems with multiple difficulty levels -- ๐ป **Real-time Code Execution**: Integrated Judge0 API for instant code compilation and execution -- ๐ **Progress Tracking**: Personal dashboard to track coding progress and statistics -- ๐ **Contests**: Participate in timed coding competitions with leaderboards -- ๐ **Premium Sheets**: Curated DSA practice sheets with Razorpay payment integration +- ๐งฉ **Problem Solving**: Extensive library of coding problems with difficulty levels (Easy, Medium, Hard) +- ๐ป **Real-time Code Execution**: Integrated Judge0 API for instant code compilation and execution across 5 languages +- ๐ **Progress Tracking**: Personal dashboard to track coding progress, submissions, and statistics +- ๐ **Contests**: Full-featured timed coding competitions with live leaderboards and real-time updates +- ๐ **Premium DSA Sheets**: Curated Data Structures & Algorithms practice sheets with Razorpay payment integration +- ๐ **Custom Playlists**: Create and manage personal problem collections ### Advanced Features -- ๐ **Secure Authentication**: JWT-based auth with refresh tokens and role-based access -- ๐ณ **Payment Integration**: Razorpay integration for premium content access -- ๏ฟฝ **Responsive Design**: Modern UI built with React, Tailwind CSS, and Lucide icons -- โก **Real-time Updates**: Live notifications and updates using Socket.IO -- ๏ฟฝ **Containerized**: Full Docker support for development and production environments -- ๐๏ธ **Database Management**: PostgreSQL with Prisma ORM for type-safe database operations -- ๐ **Redis Caching**: Session management and performance optimization +- ๐ **Secure Authentication**: JWT-based auth with refresh tokens and role-based access control (User, Admin, SuperAdmin) +- ๐ณ **Payment Integration**: Razorpay integration for premium DSA sheet purchases +- ๐จ **Responsive Design**: Modern UI built with React 19, Vite, Tailwind CSS 4, and Lucide icons +- โก **Real-time Updates**: Live contest updates and notifications using Socket.IO +- ๐ณ **Containerized**: Full Docker support with Docker Compose for development and production +- ๐๏ธ **Database Management**: PostgreSQL 15 with Prisma ORM 6 for type-safe database operations +- ๐ **Redis Caching**: Session management and performance optimization with Redis 7 +- ๐ **Session Management**: Advanced session handling with token expiry and refresh mechanisms ### User Experience -- ๐จ **Modern Interface**: Clean, intuitive design with dark theme support +- ๐จ **Modern Interface**: Clean, intuitive design with dark theme support and theme toggle - ๐ **Advanced Search**: Filter problems by difficulty, tags, and completion status -- ๐ **Analytics Dashboard**: Detailed progress tracking and performance insights -- ๐ก๏ธ **Admin Panel**: Comprehensive admin interface for content management -- ๐ง **Email Notifications**: SMTP integration for user communications +- ๐ **Analytics Dashboard**: Detailed progress tracking with recent submissions and activity feed +- ๐ก๏ธ **Admin Panel**: Comprehensive admin interface for user, problem, contest, and sheet management +- ๐ **Code Editor**: Monaco Editor (VS Code-based) with syntax highlighting and autocomplete +- โ **Test Cases**: Built-in test case execution with detailed results and error messages +- ๐ฏ **Contest Features**: Live leaderboards, real-time rankings, and submission tracking ## ๐๏ธ Architecture & Tech Stack ### Frontend -- **React 18** - Modern React with hooks and context -- **Vite** - Fast build tool and dev server -- **Tailwind CSS** - Utility-first CSS framework +- **React 19** - Latest React with hooks and context +- **Vite 7.1** - Lightning-fast build tool and dev server +- **Tailwind CSS 4** - Utility-first CSS framework with modern features - **Lucide React** - Beautiful icon library - **Zustand** - Lightweight state management -- **Monaco Editor** - VS Code-based code editor +- **Monaco Editor** - VS Code-based code editor with syntax highlighting +- **React Router 7** - Client-side routing +- **React Hook Form + Zod** - Form validation and management +- **DaisyUI** - Tailwind CSS component library +- **Framer Motion** - Animation library ### Backend -- **Node.js & Express** - Server runtime and web framework -- **Prisma ORM** - Type-safe database client and migrations -- **PostgreSQL** - Primary relational database -- **Redis** - Session storage and caching layer -- **Socket.IO** - Real-time bidirectional communication -- **Judge0 API** - Code execution and compilation service +- **Node.js & Express 4.19** - Server runtime and web framework +- **Prisma ORM 6.12** - Type-safe database client and migrations +- **PostgreSQL 15** - Primary relational database +- **Redis 7** - Session storage and caching layer +- **Socket.IO 4.8** - Real-time bidirectional communication +- **Judge0 API** - Code execution and compilation service (supports 5 languages) +- **Razorpay SDK** - Payment processing integration +- **bcryptjs** - Password hashing +- **jsonwebtoken** - JWT authentication ### DevOps & Infrastructure - **Docker & Docker Compose** - Containerization and orchestration - **Nginx** - Reverse proxy and load balancing -- **SSL/TLS** - HTTPS support with certificate management +- **PostgreSQL 15 Alpine** - Containerized database +- **Redis 7 Alpine** - Containerized cache +- **Health Checks** - Configured for all services ## ๐ Quick Start @@ -71,8 +84,8 @@ LeetLab is a comprehensive full-stack coding platform designed for developers to ```bash # Clone the repository -git clone https://github.com/yourusername/leetlab.git -cd leetlab +git clone https://github.com/Rahul5977/CodeArena.git +cd CodeArena # Copy environment template cp .env.example .env @@ -103,8 +116,8 @@ docker-compose logs -f #### 1. Clone and Install Dependencies ```bash -git clone https://github.com/yourusername/leetlab.git -cd leetlab +git clone https://github.com/Rahul5977/CodeArena.git +cd CodeArena # Install backend dependencies cd backend @@ -121,14 +134,14 @@ Create `.env` file in the `backend` directory: ```env # Database -DATABASE_URL="postgresql://myuser:mypassword@localhost:5432/leetlab" +DATABASE_URL="postgresql://myuser:mypassword@localhost:5432/codearena" REDIS_URL="redis://:redispassword@localhost:6379" # Authentication SECRET="your-super-secret-jwt-key-change-this-in-production" REFRESH_SECRET="your-super-secret-refresh-key-change-this-in-production" -# External Services +# External Services - Judge0 Code Execution JUDGE0_API_URL="https://judge0-ce.p.sulu.sh" SULU_API_KEY="your-judge0-api-key" @@ -136,7 +149,7 @@ SULU_API_KEY="your-judge0-api-key" RAZORPAY_KEY_ID="your-razorpay-key-id" RAZORPAY_KEY_SECRET="your-razorpay-key-secret" -# Email Configuration +# Email Configuration (SMTP configured, not actively used) SMTP_HOST="smtp.gmail.com" SMTP_PORT="587" SMTP_USER="your-email@gmail.com" @@ -186,20 +199,27 @@ redis-server --requirepass redispassword ## ๐ Project Structure ``` -leetlab/ +CodeArena/ โโโ ๐ backend/ # Node.js Express API Server โ โโโ ๐ src/ โ โ โโโ ๐ controllers/ # Route handlers and business logic -โ โ โโโ ๐ routes/ # API route definitions -โ โ โโโ ๐ middleware/ # Custom middleware functions -โ โ โโโ ๐ libs/ # External service integrations +โ โ โ โโโ auth.controller.js +โ โ โ โโโ problem.controller.js +โ โ โ โโโ submission.controller.js +โ โ โ โโโ contest.controller.js +โ โ โ โโโ sheet.controller.js +โ โ โ โโโ playlist.controller.js +โ โ โ โโโ user.controller.js +โ โ โ โโโ admin.controller.js +โ โ โโโ ๐ routes/ # API route definitions (11 route modules) +โ โ โโโ ๐ middleware/ # Auth, validation, error handling +โ โ โโโ ๐ libs/ # External service integrations (Judge0, Razorpay) โ โ โโโ ๐ utils/ # Utility functions and helpers โ โ โโโ ๐ generated/ # Prisma generated client โ โ โโโ ๐ index.js # Main server entry point โ โโโ ๐ prisma/ โ โ โโโ ๐ migrations/ # Database migration files โ โ โโโ ๐ schema.prisma # Database schema definition -โ โโโ ๐ uploads/ # File upload storage โ โโโ ๐ Dockerfile # Production Docker config โ โโโ ๐ Dockerfile.dev # Development Docker config โ โโโ ๐ package.json # Backend dependencies @@ -208,19 +228,20 @@ leetlab/ โ โโโ ๐ src/ โ โ โโโ ๐ components/ # Reusable React components โ โ โ โโโ ๐ ui/ # Base UI components -โ โ โ โโโ ๐ layout/ # Layout components +โ โ โ โโโ ๐ layout/ # Layout components (Navbar, Footer) โ โ โ โโโ ๐ shared/ # Shared components โ โ โโโ ๐ pages/ # Route-based page components -โ โ โ โโโ ๐ auth/ # Authentication pages -โ โ โ โโโ ๐ problems/ # Problem-related pages -โ โ โ โโโ ๐ contests/ # Contest pages -โ โ โ โโโ ๐ sheets/ # Sheet pages -โ โ โ โโโ ๐ admin/ # Admin panel pages -โ โ โโโ ๐ contexts/ # React context providers +โ โ โ โโโ ๐ auth/ # Login, Register, ForgotPassword +โ โ โ โโโ ๐ problems/ # Problem list, Problem solver +โ โ โ โโโ ๐ contests/ # Contest list, Contest detail +โ โ โ โโโ ๐ sheets/ # DSA sheets, Sheet detail +โ โ โ โโโ ๐ playlists/ # Playlist management +โ โ โ โโโ ๐ dashboard/ # User dashboard +โ โ โ โโโ ๐ admin/ # Admin panel +โ โ โโโ ๐ contexts/ # React context providers (Auth, Theme) โ โ โโโ ๐ stores/ # Zustand state management โ โ โโโ ๐ services/ # API service functions โ โ โโโ ๐ utils/ # Utility functions -โ โ โโโ ๐ assets/ # Static assets โ โ โโโ ๐ lib/ # Third-party library configs โ โโโ ๐ public/ # Public static files โ โโโ ๐ Dockerfile # Production Docker config @@ -231,17 +252,23 @@ leetlab/ โ โโโ ๐ nginx/ # Nginx Reverse Proxy โ โโโ ๐ nginx.conf # Nginx configuration -โ โโโ ๐ ssl/ # SSL certificates -โ โโโ ๐ logs/ # Nginx access/error logs +โ โโโ ๐ ssl/ # SSL certificates directory โ โโโ ๐ docs/ # Project Documentation -โ โโโ ๐ API_DOCS.md # API documentation -โ โโโ ๐ DEPLOYMENT.md # Deployment guide -โ โโโ ๐ TESTING_GUIDE.md # Testing instructions +โ โโโ ๐ API_DOCS.md # API endpoint documentation +โ โโโ ๐ SHEETS_TESTING_GUIDE.md # DSA sheets testing guide +โ โโโ ๐ DASHBOARD_TESTING_GUIDE.md # Dashboard testing guide +โ โโโ ๐ CODE_EXECUTION_TESTING.md # Code execution testing +โ โโโ ๐ IMPLEMENTATION_SUMMARY.md # Feature implementation summary +โ โโโ ๐ PROJECT_SUMMARY.md # Comprehensive project summary +โ โโโ (40+ additional documentation files) โ โโโ ๐ docker-compose.yml # Production compose config โโโ ๐ docker-compose.dev.yml # Development compose config โโโ ๐ init-db.sql # Database initialization +โโโ ๐ test-sheets.sql # Test DSA sheets data +โโโ ๐ sample-problem.sql # Sample problem data +โโโ ๐ more-problems.sql # Additional problems โโโ ๐ .env.example # Environment variables template โโโ ๐ README.md # This file ``` @@ -357,58 +384,220 @@ SMTP_PASS="your-app-password" ### Core Entities -- **Users**: Authentication, profiles, roles -- **Problems**: Coding challenges with test cases -- **Sheets**: Curated problem collections -- **Contests**: Timed competitions -- **Submissions**: Code submissions and results -- **Payments**: Transaction records +The application uses a comprehensive Prisma schema with the following main models: + +- **User**: Authentication, profiles, roles (USER, ADMIN, SUPERADMIN) + - Fields: id, name, email, password, role, refreshToken, passwordResetToken, isActive, emailVerified + - Relations: submissions, problems, playlists, contest participation, sheet purchases + +- **Problem**: Coding challenges with test cases + - Fields: id, title, description, difficulty (EASY, MEDIUM, HARD), tags, examples, constraints, hints, editorial + - Relations: submissions, sheet problems, contest problems, playlists + +- **Submission**: Code submissions and results + - Fields: id, userId, problemId, code, language, status, runtime, memory, createdAt + - Relations: user, problem, test case results + +- **TestCaseResult**: Individual test case execution results + - Fields: id, submissionId, input, expectedOutput, actualOutput, status, executionTime + +- **Contest**: Timed competitions + - Fields: id, title, description, startTime, endTime, status (UPCOMING, LIVE, COMPLETED, CANCELLED) + - Relations: participants, submissions, leaderboard, problems + +- **ContestParticipant**: User contest registrations +- **ContestSubmission**: Contest-specific submissions with scores +- **ContestLeaderboard**: Real-time contest rankings + +- **Sheet**: DSA practice sheets + - Fields: id, title, description, type (FREE, PREMIUM), price, difficulty, estimatedHours + - Relations: sheet problems, user purchases, progress tracking + +- **UserSheet**: Sheet purchases via Razorpay + - Fields: id, userId, sheetId, paymentId, amount, status, purchaseDate + +- **SheetProgress**: Problem-by-problem progress in sheets + - Fields: id, userId, sheetId, problemId, isCompleted, completedAt + +- **Playlist**: User-created problem collections + - Fields: id, name, description, userId, createdAt + - Relations: problems + +- **Payment**: Transaction records + - Fields: id, userId, razorpayOrderId, razorpayPaymentId, amount, status + +- **UserSession**: Session management + - Fields: id, userId, sessionToken, expiresAt + +- **RoleChange**: Audit trail for user role modifications + - Fields: id, userId, changedBy, previousRole, newRole, reason, createdAt ### Key Relationships -```sql +``` User 1---* Submission User 1---* Payment +User 1---* Playlist +User 1---* ProblemSolved +User 1---* UserSheet +User 1---* ContestParticipant Problem 1---* Submission +Problem 1---* TestCaseResult Sheet 1---* SheetProblem *---1 Problem Contest 1---* ContestProblem *---1 Problem +Contest 1---* ContestParticipant *---1 User ``` +## โ Implemented Features + +### ๐ Authentication & Authorization System +- **Complete JWT-based authentication** with access and refresh tokens +- **Role-based access control** supporting three roles: USER, ADMIN, SUPERADMIN +- **Session management** with UserSession model and automatic cleanup +- **Password reset** functionality with secure token generation +- **Email verification** system (infrastructure ready) +- **Account status management** (active/inactive users) + +### ๐ป Code Execution Engine +- **Judge0 API integration** for real-time code compilation and execution +- **Multi-language support**: Python, Java, JavaScript, C++, C +- **Batch submission processing** for running multiple test cases +- **Detailed execution results** with runtime, memory usage, and error messages +- **Test case management** with expected vs actual output comparison +- **Submission history** tracking all code submissions per user + +### ๐งฉ Problem Management System +- **CRUD operations** for problems (admin/superadmin only) +- **Rich problem metadata**: title, description, difficulty, tags, examples, constraints +- **Editorial support** with hints and detailed solutions +- **Test cases** stored in JSON format with input/output pairs +- **Code snippets** for different languages as starter templates +- **Problem-solving tracking** per user with ProblemSolved model +- **Search and filter** by difficulty, tags, and completion status + +### ๐ Contest Management +- **Full contest lifecycle**: UPCOMING โ LIVE โ COMPLETED +- **Contest registration** system with ContestParticipant tracking +- **Real-time leaderboards** with Socket.IO integration +- **Contest-specific submissions** with scoring and ranking +- **Time-based duration** management with automatic status updates +- **Penalty system** for wrong submissions +- **Multiple problems per contest** with ContestProblem association + +### ๐ DSA Sheets System +- **Free and Premium sheets** with type-based access control +- **Razorpay payment integration** for premium sheet purchases +- **Sheet progress tracking** per problem for each user +- **Curated problem collections** organized by topics and difficulty +- **Estimated completion time** for each sheet +- **Prerequisites and topics** metadata for better organization +- **Purchase history** tracking with payment records + +### ๐ Playlist Feature +- **User-created custom playlists** for organizing problems +- **Add/remove problems** from playlists dynamically +- **Playlist management** (create, update, delete) +- **Personal problem collections** for focused practice + +### ๐ฅ Admin Features +- **User management**: view all users, search, filter by role +- **Role modification**: promote/demote users with audit trail (RoleChange model) +- **Problem creation and management** through admin interface +- **Contest management**: create, update, cancel contests +- **Sheet management**: create and manage DSA sheets +- **Statistics dashboard** for system overview +- **Permission-based access control** for sensitive operations + +### ๐ค User Dashboard +- **Profile management**: update name, email, profile image +- **Activity feed** showing recent submissions +- **Statistics display**: problems solved, submission count, accuracy +- **Recent submissions** with status and language information +- **Progress visualization** for problem-solving journey +- **Problem recommendations** based on user history + +### ๐จ Frontend Features +- **Dark/Light theme toggle** with persistent storage +- **Monaco Editor integration** with VS Code features +- **Split pane layout** for problem description and code editor +- **Custom test case input/output** for debugging +- **Loading states and error handling** throughout the app +- **Toast notifications** for user feedback +- **Responsive design** with Tailwind CSS +- **Smooth animations** with Framer Motion + +### ๐ง Technical Features +- **Type-safe database operations** with Prisma ORM +- **RESTful API design** with 11 route modules +- **Comprehensive error handling** with custom middleware +- **Input validation** on all API endpoints +- **Password hashing** with bcryptjs +- **Redis session storage** for performance +- **Health check endpoints** for monitoring +- **Docker containerization** for easy deployment + +### ๐ Current Limitations +- **Email notifications**: SMTP configured but not actively used +- **AI code review**: Endpoint stub exists but not fully implemented +- **Advanced analytics**: Basic statistics present, advanced features planned +- **Admin UI**: Some admin components are stubs requiring full implementation + ## ๐งช Testing ### Backend Testing +The backend includes several SQL files for testing and seeding: + ```bash -cd backend -npm test # Run all tests -npm run test:unit # Unit tests only -npm run test:integration # Integration tests only -npm run test:coverage # Generate coverage report -``` +# Initialize database +psql -U myuser -d postgres -f init-db.sql -### Frontend Testing +# Load test DSA sheets +psql -U myuser -d postgres -f test-sheets.sql -```bash -cd frontend -npm test # Run Jest/Vitest tests -npm run test:e2e # Run end-to-end tests -npm run test:component # Component testing +# Load sample problems +psql -U myuser -d postgres -f sample-problem.sql + +# Load additional problems +psql -U myuser -d postgres -f more-problems.sql ``` +### Testing Guides + +The project includes comprehensive testing documentation in the `/docs` directory: + +- **SHEETS_TESTING_GUIDE.md**: Complete guide for testing DSA sheets functionality +- **DASHBOARD_TESTING_GUIDE.md**: Dashboard feature testing guide +- **CODE_EXECUTION_TESTING.md**: Code execution and Judge0 integration testing + ### API Testing -Use the provided Postman collection or test manually: +Use the provided API documentation or test manually: ```bash # Health check curl http://localhost:8080/api/v1/health # Authentication +curl -X POST http://localhost:8080/api/v1/auth/register \ + -H "Content-Type: application/json" \ + -d '{"name":"Test User","email":"test@example.com","password":"password123"}' + +# Login curl -X POST http://localhost:8080/api/v1/auth/login \ -H "Content-Type: application/json" \ - -d '{"email":"user@example.com","password":"password"}' + -d '{"email":"test@example.com","password":"password123"}' ``` +### Judge0 Integration Testing + +Test code execution with supported languages: +- Python (language_id: 71) +- Java (language_id: 62) +- JavaScript (language_id: 63) +- C++ (language_id: 54) +- C (language_id: 50) + ## ๐จ Troubleshooting ### Common Issues @@ -491,8 +680,8 @@ docker-compose logs [service-name] ```bash # Clone repository -git clone https://github.com/yourusername/leetlab.git -cd leetlab +git clone https://github.com/Rahul5977/CodeArena.git +cd CodeArena # Configure production environment cp .env.example .env @@ -545,8 +734,8 @@ curl -fsSL https://get.docker.com -o get-docker.sh sh get-docker.sh # Deploy application -git clone https://github.com/yourusername/leetlab.git -cd leetlab +git clone https://github.com/Rahul5977/CodeArena.git +cd CodeArena ./deploy-prod.sh ``` @@ -649,43 +838,49 @@ This project is licensed under the MIT License. See the [LICENSE](LICENSE) file ### Core Technologies -- **[React](https://react.dev/)** - Frontend framework +- **[React](https://react.dev/)** - Frontend framework (v19) - **[Node.js](https://nodejs.org/)** - Backend runtime -- **[PostgreSQL](https://postgresql.org/)** - Primary database -- **[Prisma](https://prisma.io/)** - Database ORM and migrations +- **[PostgreSQL](https://postgresql.org/)** - Primary database (v15) +- **[Prisma](https://prisma.io/)** - Database ORM and migrations (v6.12) - **[Docker](https://docker.com/)** - Containerization platform ### UI & Design -- **[Tailwind CSS](https://tailwindcss.com/)** - Utility-first CSS framework +- **[Tailwind CSS](https://tailwindcss.com/)** - Utility-first CSS framework (v4) - **[Lucide React](https://lucide.dev/)** - Beautiful icon library - **[Monaco Editor](https://microsoft.github.io/monaco-editor/)** - Code editor +- **[DaisyUI](https://daisyui.com/)** - Tailwind CSS component library +- **[Framer Motion](https://www.framer.com/motion/)** - Animation library ### External Services - **[Judge0](https://judge0.com/)** - Code execution API - **[Razorpay](https://razorpay.com/)** - Payment processing -- **[Redis](https://redis.io/)** - In-memory data structure store +- **[Redis](https://redis.io/)** - In-memory data structure store (v7) + +### State Management & Routing + +- **[Zustand](https://zustand-demo.pmnd.rs/)** - Lightweight state management +- **[React Router](https://reactrouter.com/)** - Client-side routing (v7) ### Community -Special thanks to all contributors, testers, and users who help make LeetLab better! +Special thanks to all contributors, testers, and users who help make CodeArena better! --- ## ๐ Support -- **Documentation**: [Wiki](https://github.com/yourusername/leetlab/wiki) -- **Community**: [Discord Server](https://discord.gg/leetlab) -- **Issues**: [GitHub Issues](https://github.com/yourusername/leetlab/issues) -- **Email**: support@leetlab.com +- **Documentation**: [docs/ directory](docs/) - Comprehensive project documentation +- **Issues**: [GitHub Issues](https://github.com/Rahul5977/CodeArena/issues) +- **Repository**: [https://github.com/Rahul5977/CodeArena](https://github.com/Rahul5977/CodeArena) ---