How vijaykumarjoshi123/python-leetcode works
1. Overall shape
- This is a classic two-tier web app: a React frontend and a Node.js/Express backend.
- Persistence is in MongoDB through Mongoose models.
- The backend also includes a separate code-execution subsystem for running user-submitted Python safely, which is an important architectural boundary.
2. Frontend subsystem
- frontend/src is organized by page-level screens (Problems, Problem, ProblemSolver, Leaderboard, Profile, Login, Register, Home) and shared UI (Navbar).
- frontend/src/services/api.js is the main client boundary to the backend; it centralizes HTTP calls.
- The UI is a single-page app with React Router-style navigation, so the frontend owns page transitions while the backend only serves data and actions.
3. Backend API layer
- backend/server.js is the Express entry point.
- Routes are split by domain: auth, problems, submissions, forum, leaderboard, and tutor.
- backend/middleware/auth.js and validate.js sit between routes and business logic, enforcing JWT auth and request validation.
4. Domain data model
- MongoDB collections are explicitly modeled in backend/models/.
- User stores credentials and progress stats.
- Problem stores the problem catalog, test cases, solution metadata, categories, and difficulty.
- Submission records code runs, verdicts, runtime, and testcase results.
- Discussion stores forum threads and nested comments tied to a problem.
5. Primary user flow: solving problems
- The frontend loads problems from GET /api/problems, then a user opens a specific problem and writes code in the solver page.
- When submitted, the request flows to the submissions API, which creates a Submission record and triggers execution/testing.
- The result feeds back into user progress, problem acceptance metrics, and leaderboard stats.
6. Code execution boundary
- backend/services/pythonExecutor.js and backend/Dockerfile.executor indicate a dedicated execution path for running Python code separately from the main API process.
- backend/services/submissionQueue.js suggests submissions are queued before execution, which helps isolate and serialize potentially expensive or unsafe work.
- Architecturally, this is the most important trust boundary: untrusted user code should not run in the main Express process.
7. Community and collaboration features
- The forum subsystem (backend/routes/forum.js + Discussion model) supports problem-specific discussions and comments.
- This creates a second read/write path alongside submissions: users can ask questions and share solutions without affecting execution or scoring logic.
- Forum data is scoped by problemId, which keeps discussion tied to the learning object rather than a global feed.
8. Leaderboard and progress tracking
- The leaderboard route reads aggregated user/submission data to rank users globally and by difficulty.
- User statistics such as solved counts, attempts, and per-difficulty counts are part of the persisted user state, not computed only in the UI.
- This means ranking is derived from backend data, not client-side calculations.
9. AI tutor subsystem
- backend/services/aiTutor.js and backend/routes/tutor.js provide an assistance layer beyond static problems.
- This likely consumes problem context and user input to generate hints or explanations, acting as a separate service boundary from core grading.
- In a diagram, it should be shown as an auxiliary backend capability, not part of the submission pipeline.
10. Operational and deployment structure
- The repo is designed for containerized local/dev deployment: docker-compose.yml, backend/Dockerfile, and backend/Dockerfile.executor.
- Frontend deployment is prepared for static hosting via frontend/vercel.json.
- Backend config is environment-driven (backend/.env.example), with MongoDB URI, JWT secret, and port as key runtime dependencies.
11. Bootstrapping and content seeding
- backend/seed.js and backend/seed_gpu_problems.js populate the problem database, which implies the platform is content-heavy and expects preloaded datasets.
- This matters because the app’s core value is the problem corpus, not just user-generated content.
12. What to draw as the main boundaries
- One boundary between browser UI and API backend.
- One boundary inside the backend between core CRUD/auth logic and code execution.
- One boundary between application data in MongoDB and derived views like leaderboard, profile stats, and forum threads.
Main entry points: App.js Browser App · server.js Server · api.js API Client · docker-compose.yml Compose
Components 27
Frontend
React SPA, page views, and shared client-side navigation.
- Browser App · User-facing React application that handles navigation and renders all screens.
frontend/src/App.js - Navbar · Common top-level navigation used across pages.
frontend/src/components/Navbar.js - Problems · Lists the available problem set for browsing and selection.
frontend/src/pages/Problems.js - Problem · Shows a single problem statement and metadata.
frontend/src/pages/Problem.js - Solver · Lets users write, run, and submit code for a problem.
frontend/src/pages/ProblemSolver.js - Auth · Sign-in and account creation screens.
frontend/src/pages/Login.js - Profile · Displays solved counts, attempts, and user progress.
frontend/src/pages/Profile.js - Leaderboard · Shows ranked user progress and difficulty-based standings.
frontend/src/pages/Leaderboard.js - API Client · Centralized browser-to-backend request layer.
frontend/src/services/api.js
Backend API
Express routes, middleware, and application services.
- Server · Bootstraps the backend API process and registers routes.
backend/server.js - Auth Route · Handles authentication and account lifecycle requests.
backend/routes/auth.js - Problems API · Serves the problem catalog and individual problem data.
backend/routes/problems.js - Submissions API · Accepts code submissions and returns grading results.
backend/routes/submissions.js - Forum API · Manages discussions and nested comments tied to problems.
backend/routes/forum.js - Leaderboard API · Computes ranking views from user and submission data.
backend/routes/leaderboard.js - Tutor API · Provides AI-assisted hints and explanations.
backend/routes/tutor.js - Middleware · JWT authentication and request validation layer.
backend/middleware/auth.js
Data Model
MongoDB-backed domain collections and persisted state.
- User · Stores credentials, progress stats, and ranking data.
backend/models/User.js - Problem · Stores problem statements, tests, difficulty, and metadata.
backend/models/Problem.js - Submission · Stores code runs, verdicts, runtime, and testcase results.
backend/models/Submission.js - Discussion · Stores forum threads and comments scoped to a problem.
backend/models/Discussion.js
Execution
Isolated code execution and submission processing.
- Submission Queue · Serializes and buffers submissions before execution.
backend/services/submissionQueue.js - Python Executor · Runs untrusted Python code in an isolated execution path.
backend/services/pythonExecutor.js - AI Tutor · Generates guidance using problem and user context.
backend/services/aiTutor.js
Ops & Deploy
Containerization, environment config, and seeding.
- Seed Data · Populates the problem corpus, including GPU/problem variants.
backend/seed.js - Dockerfiles · Defines backend and executor runtime images.
backend/Dockerfile - Compose · Wires frontend, backend, and database for local deployment.
docker-compose.yml
Connections 33
- Browser App → Navbar: renders · Shared navigation appears across the SPA.
- Browser App → Problems: routes to · Client-side navigation switches between pages.
- Browser App → Problem: routes to · Problem detail is a dedicated page in the SPA.
- Browser App → Solver: routes to · The solver page handles code authoring and submission.
- Browser App → Auth: routes to · Login and registration are client-side views.
- Browser App → Profile: routes to · User profile is rendered in the frontend.
- Browser App → Leaderboard: routes to · Leaderboard is a front-end view backed by server data.
- Problems → API Client: fetches data · Problem list is populated through the shared API client.
- Problem → API Client: fetches data · Problem details are requested from the backend.
- Solver → API Client: submits code · Code runs and submissions go through the client API boundary.
- Auth → API Client: authenticates · Login and registration call backend auth endpoints.
- Profile → API Client: loads stats · Profile reads persisted user progress from the server.
- Leaderboard → API Client: loads rankings · Leaderboard queries derived ranking data from the backend.
- Server → Middleware: guards routes · Authentication and validation sit in front of API handlers.
- Server → Auth Route: mounts · Express exposes authentication endpoints.
- Server → Problems API: mounts · Express exposes problem catalog endpoints.
- Server → Submissions API: mounts · Express exposes submission handling endpoints.
- Server → Forum API: mounts · Express exposes discussion endpoints.
- Server → Leaderboard API: mounts · Express exposes ranking endpoints.
- Server → Tutor API: mounts · Express exposes AI tutor endpoints.
- Submissions API → Submission Queue: enqueues · Submissions are buffered before execution.
- Submission Queue → Python Executor: runs · Queued jobs invoke the isolated Python runner.
- Submissions API → Submission: persists · Submission attempts and verdicts are stored in MongoDB.
- Problems API → Problem: reads/writes · Problem catalog data comes from the Problem collection.
- Auth Route → User: reads/writes · Authentication operates on user records.
- Forum API → Discussion: reads/writes · Forum threads and comments are persisted as discussions.
- Leaderboard API → User: aggregates · Ranking is derived from stored user progress data.
- Leaderboard API → Submission: aggregates · Leaderboard can also use submission outcomes for ranking metrics.
- Tutor API → AI Tutor: invokes · Tutor endpoints delegate to the AI assistance service.
- Seed Data → Problem: populates · Seed scripts load the problem corpus into the database.
- Compose → Browser App: orchestrates · Compose coordinates the frontend runtime.
- Compose → Server: orchestrates · Compose coordinates the backend runtime.
- Compose → Dockerfiles: builds · Container files define the runtime images.