# codemaster17/pathfiller-online-codeeditor-and-compiler architecture

> Architecture diagram of the GitHub repository codemaster17/pathfiller-online-codeeditor-and-compiler, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-17). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/codemaster17/pathfiller-online-codeeditor-and-compiler
- Repository: https://github.com/codemaster17/pathfiller-online-codeeditor-and-compiler

## Overview

##### Project type and purpose
- Pathfiller is a full‑stack, interactive coding platform comprising two main experiences:
- Coding Playground – free‑form code editing and execution with custom inputs
- Coding Arena – timed/problem‑driven code challenges with test‑case validation
- Frontend: React + TypeScript + Tailwind + CodeMirror, deployed on Vercel
- Backend: Node/Express (TypeScript) exposing REST endpoints
- Data stores: MongoDB (problems, users, submissions, profiles, tags, test cases), Redis for Bull job queues
- Code execution: child_process invoked by worker processes

##### File structure
- Top‑level “frontend” folder: Vite/React app, includes schema (Zod), API clients, components, pages, Redux store, routing, assets
- Top‑level “express_backend” folder: src/ & dist/ code, controllers, routers, services, models, utils, middleware, queue logic under src/code
- Config files: tsconfig, nodemon.json, ecosystem.config (PM2), vercel.json
- Infrastructure indicators: Mongoose (models), Bull (job_queue.ts), Redis client, child_process scripts (executePy.ts, execute_cpp.ts)

##### README for additional insights
- Tech stack enumerated (MongoDB, Bull, child_process, Mongoose)
- Emphasis on scalability, security, message‑queue patterns

a. Main components to include
- User’s Browser (React SPA)
- Frontend App (API layer)
- Backend API Server (Express.js)
- Job Queue (Bull on Redis)
- Worker Service(s) (Node.js processes executing code)
- Data Store (MongoDB cluster)
- Child_Process Executor (OS sandbox invoked by worker)
- (Optional) CDN / Vercel Layer

b. Relationships & interactions
1. Browser → Frontend App (HTTP/Fetch)
2. Frontend → Backend API (REST endpoints: /api/problems, /api/code, /api/playground, /api/user)
3. Backend → MongoDB (via Mongoose ORM) for reads/writes
4. Backend → Redis/Bull Enqueue (job submissions)
5. Worker ← Bull Queue (job intake)
6. Worker → Child_Process sandbox (compile & run code)
7. Child_Process → Worker (stdout, stderr, metrics)
8. Worker → MongoDB (store result, execution logs)
9. Frontend polls or retrieves job status via API (Backend → Mongo)

c. Architectural patterns & design principles
- Separation of concerns: UI vs API vs Worker
- Asynchronous processing with message queue (Bull) for heavy CPU‑bound tasks
- MVC‑style controllers & routers in backend; React components/pages in frontend
- Centralized error handling via middleware
- Config driven (environment variables, tsconfig, vercel.json)

d. Key technologies/frameworks
- Frontend: React, TypeScript, Tailwind, Shadcn/Magic UI, CodeMirror, Redux
- Backend: Express.js, TypeScript, Mongoose, Bull, Redis client, child_process
- Data stores: MongoDB Atlas, Redis instance
- Deployment: Vercel (frontend), PM2/ecosystem.config or Vercel Serverless (backend)

##### Detailed capture of essential elements
- Don’t just show “Backend” – break it into Router → Controller → Service → Model
- Code_execution flow: generateFile.ts → job_queue.ts → executePy/execute_cpp → store results
- External dependencies: MongoDB cluster, Redis server, child_process sandbox

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client Tier
    subgraph "Client Tier"
        Browser["User Browser"]:::client
        CDN["CDN / Vercel"]:::client
        ReactApp["React App"]:::client
        PlaygroundUI["Coding Playground UI"]:::client
        ArenaUI["Coding Arena UI"]:::client
        APIClients["API Clients"]:::client
        Redux["Redux Store"]:::client
        Routing["Frontend Routing"]:::client
        Zod["Zod Schemas"]:::client
    end

    %% Server Tier
    subgraph "Server Tier"
        subgraph "API Layer"
            ExpressServer["Express API Server"]:::server
            Routers["REST Routers"]:::server
            Controllers["Controllers"]:::server
            Services["Services"]:::server
            Models["Mongoose Models"]:::db
            Middleware["Global Error Handler"]:::server
        end
        subgraph "Worker Layer"
            JobQueue["Redis & Bull Queue"]:::queue
            Workers["Code Execution Workers"]:::worker
            FileGen["File Generation"]:::server
        end
        subgraph "Data Stores"
            Mongo["MongoDB Cluster"]:::db
            Redis["Redis Server"]:::queue
        end
    end

    %% Client interactions
    Browser -->|HTTP/Fetch| ReactApp
    ReactApp --> PlaygroundUI
    ReactApp --> ArenaUI
    PlaygroundUI -->|calls APIs| APIClients
    ArenaUI -->|calls APIs| APIClients
    APIClients -->|REST calls| ExpressServer

    %% Frontend internal
    ReactApp -->|uses| Redux
    ReactApp -->|uses| Routing
    ReactApp -->|validates| Zod

    %% API Layer flows
    ExpressServer -->|routes| Routers
    Routers -->|invoke| Controllers
    Controllers -->|business logic| Services
    Services -->|ORM access| Models
    Models -->|reads/writes| Mongo
    Controllers -->|enqueue jobs| JobQueue
    ExpressServer -->|handle errors| Middleware
    ExpressServer -->|reads/writes| Mongo

    %% Worker Layer flows
    JobQueue -->|jobs| Workers
    Workers -->|generate files| FileGen
    FileGen -->|prepare code| Workers
    Workers -->|store results| Models
    Workers -->|store results| Mongo

    %% Queue and Datastore
    JobQueue --> Redis
    ExpressServer --> Redis

    %% Click Events - Frontend
    click ReactApp "https://github.com/codemaster17/pathfiller-online-codeeditor-and-compiler/blob/main/frontend/src/App.tsx"
    click ReactApp "https://github.com/codemaster17/pathfiller-online-codeeditor-and-compiler/blob/main/frontend/src/main.tsx"
    click PlaygroundUI "https://github.com/codemaster17/pathfiller-online-codeeditor-and-compiler/blob/main/frontend/src/pages/CodingPlayground.tsx"
    click PlaygroundUI "https://github.com/codemaster17/pathfiller-online-codeeditor-and-compiler/blob/main/frontend/src/components/core/playground/InputArea.tsx"
    click ArenaUI "https://github.com/codemaster17/pathfiller-online-codeeditor-and-compiler/blob/main/frontend/src/pages/CodingArena.tsx"
    click ArenaUI "https://github.com/codemaster17/pathfiller-online-codeeditor-and-compiler/blob/main/frontend/src/components/core/arena/ProblemDescriptionTab.tsx"
    click APIClients "https://github.com/codemaster17/pathfiller-online-codeeditor-and-compiler/blob/main/frontend/src/api/codePlaygroundApi.ts"
    click APIClients "https://github.com/codemaster17/pathfiller-online-codeeditor-and-compiler/blob/main/frontend/src/api/codeArenaApi.ts"
    click APIClients "https://github.com/codemaster17/pathfiller-online-codeeditor-and-compiler/blob/main/frontend/src/api/problemApi.ts"
    click Redux "https://github.com/codemaster17/pathfiller-online-codeeditor-and-compiler/blob/main/frontend/src/redux/store.ts"
    click Routing "https://github.com/codemaster17/pathfiller-online-codeeditor-and-compiler/blob/main/frontend/src/routes/index.ts"
    click Zod "https://github.com/codemaster17/pathfiller-online-codeeditor-and-compiler/blob/main/frontend/schema/authSchema/index.ts"
    click Zod "https://github.com/codemaster17/pathfiller-online-codeeditor-and-compiler/blob/main/frontend/schema/dataSchema/index.ts"

    %% Click Events - Backend
    click ExpressServer "https://github.com/codemaster17/pathfiller-online-codeeditor-and-compiler/blob/main/express_backend/src/server.ts"
    click ExpressServer "https://github.com/codemaster17/pathfiller-online-codeeditor-and-compiler/blob/main/express_backend/src/app.ts"
    click Routers "https://github.com/codemaster17/pathfiller-online-codeeditor-and-compiler/blob/main/express_backend/src/router/apiRouter.ts"
    click Routers "https://github.com/codemaster17/pathfiller-online-codeeditor-and-compiler/blob/main/express_backend/src/router/codeRouter.ts"
    click Routers "https://github.com/codemaster17/pathfiller-online-codeeditor-and-compiler/blob/main/express_backend/src/router/playgroundRouter.ts"
    click Routers "https://github.com/codemaster17/pathfiller-online-codeeditor-and-compiler/blob/main/express_backend/src/router/problemRouter.ts"
    click Routers "https://github.com/codemaster17/pathfiller-online-codeeditor-and-compiler/blob/main/express_backend/src/router/userRouter.ts"
    click Controllers "https://github.com/codemaster17/pathfiller-online-codeeditor-and-compiler/blob/main/express_backend/src/controllers/apiController.ts"
    click Controllers "https://github.com/codemaster17/pathfiller-online-codeeditor-and-compiler/blob/main/express_backend/src/controllers/code_controller.ts"
    click Controllers "https://github.com/codemaster17/pathfiller-online-codeeditor-and-compiler/blob/main/express_backend/src/controllers/code_playground_controller.ts"
    click Controllers "https://github.com/codemaster17/pathfiller-online-codeeditor-and-compiler/blob/main/express_backend/src/controllers/problem_controller.ts"
    click Services "https://github.com/codemaster17/pathfiller-online-codeeditor-and-compiler/blob/main/express_backend/src/service/databaseService.ts"
    click Models "https://github.com/codemaster17/pathfiller-online-codeeditor-and-compiler/blob/main/express_backend/src/models/problem_model.ts"
    click Models "https://github.com/codemaster17/pathfiller-online-codeeditor-and-compiler/blob/main/express_backend/src/models/user.ts"
    click Models "https://github.com/codemaster17/pathfiller-online-codeeditor-and-compiler/blob/main/express_backend/src/models/test_case_model.ts"
    click Models "https://github.com/codemaster17/pathfiller-online-codeeditor-and-compiler/blob/main/express_backend/src/models/tag_model.ts"
    click Models "https://github.com/codemaster17/pathfiller-online-codeeditor-and-compiler/blob/main/express_backend/src/models/profile_model.ts"
    click Models "https://github.com/codemaster17/pathfiller-online-codeeditor-and-compiler/blob/main/express_backend/src/models/jobs_model.ts"
    click Middleware "https://github.com/codemaster17/pathfiller-online-codeeditor-and-compiler/blob/main/express_backend/src/middleware/globalErrorHandler.ts"
    click JobQueue "https://github.com/codemaster17/pathfiller-online-codeeditor-and-compiler/blob/main/express_backend/src/code/job_queue.ts"
    click JobQueue "https://github.com/codemaster17/pathfiller-online-codeeditor-and-compiler/blob/main/express_backend/src/code/job_queue_playground.ts"
    click Workers "https://github.com/codemaster17/pathfiller-online-codeeditor-and-compiler/blob/main/express_backend/src/code/code_execution/executePy.ts"
    click Workers "https://github.com/codemaster17/pathfiller-online-codeeditor-and-compiler/blob/main/express_backend/src/code/code_execution/execute_cpp.ts"
    click FileGen "https://github.com/codemaster17/pathfiller-online-codeeditor-and-compiler/blob/main/express_backend/src/code/generateFile.ts"
    click ExpressServer "https://github.com/codemaster17/pathfiller-online-codeeditor-and-compiler/blob/main/express_backend/src/config/config.ts"
    click ExpressServer "https://github.com/codemaster17/pathfiller-online-codeeditor-and-compiler/blob/main/express_backend/src/config/database.ts"
    click ExpressServer "https://github.com/codemaster17/pathfiller-online-codeeditor-and-compiler/blob/main/express_backend/src/config/get_redis_client.ts"
    click ExpressServer "https://github.com/codemaster17/pathfiller-online-codeeditor-and-compiler/blob/main/express_backend/src/utils/httpError.ts"
    click ExpressServer "https://github.com/codemaster17/pathfiller-online-codeeditor-and-compiler/blob/main/express_backend/src/utils/httpResponse.ts"
    click ExpressServer "https://github.com/codemaster17/pathfiller-online-codeeditor-and-compiler/blob/main/express_backend/src/utils/logger.ts"
    click ExpressServer "https://github.com/codemaster17/pathfiller-online-codeeditor-and-compiler/blob/main/express_backend/src/utils/errorObject.ts"
    click ExpressServer "https://github.com/codemaster17/pathfiller-online-codeeditor-and-compiler/blob/main/express_backend/src/utils/quicker.ts"
    click ExpressServer "https://github.com/codemaster17/pathfiller-online-codeeditor-and-compiler/blob/main/express_backend/src/types/types.ts"
    click ExpressServer "https://github.com/codemaster17/pathfiller-online-codeeditor-and-compiler/blob/main/express_backend/src/ecosystem.config.ts"
    click ExpressServer "https://github.com/codemaster17/pathfiller-online-codeeditor-and-compiler/blob/main/express_backend/vercel.json"
    click CDN "https://github.com/codemaster17/pathfiller-online-codeeditor-and-compiler/blob/main/frontend/vercel.json"

    %% Styles
    classDef client fill:#cfe2f3,stroke:#000,stroke-width:1px
    classDef server fill:#d9ead3,stroke:#000,stroke-width:1px
    classDef db fill:#f9cb9c,stroke:#000,stroke-width:1px
    classDef queue fill:#fff2cc,stroke:#000,stroke-width:1px
    classDef worker fill:#ffe6cc,stroke:#000,stroke-width:1px
```
