# roshan-anand/code-join architecture

> Architecture diagram of the GitHub repository roshan-anand/code-join, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-07-30). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/roshan-anand/code-join
- Repository: https://github.com/roshan-anand/code-join

## Overview

##### Project Type and Purpose
- This is a full-stack, collaborative, real-time code-editing web application (“CODE JOIN”).
- The front end is a React + TypeScript single-page application served via Vite (and Nginx in Docker).
- The back end is a Node.js + TypeScript service using WebSockets for live collaboration, Passport for authentication, and Docker to spin up isolated containers for code execution and terminals.

##### File Structure Analysis
- Top-level:
- `frontend/` – React SPA, Vite build, UI components, hooks, Redux slices, environment, Dockerfile.
- `backend/` – Express (or similar) server, Socket configurations, route definitions, listeners for Chat, Editor, Room, Container, Terminal, Docker configs, Passport setup.
- `compose.dev.yaml` & `compose.prod.yaml` – multi-container orchestration definitions.
- `traefik.yaml` – edge router configuration (Traefik) for SSL, domain routing.
- `Makefile` – convenience tasks.
- Patterns:
- Separation of concerns: UI vs business logic vs real-time event handlers.
- Publish/subscribe via Socket listeners.
- Micro-service style container spawning for code sandboxing.

##### README Insights
- Title: “CODE JOIN an interactive code editor.”
- Confirms focus on interactive, collaborative editing.

a. Main Components
1. Ingress Layer: Traefik proxy (handles HTTPS, routing to front or back).
2. Frontend Service: React SPA running in a container with Nginx.
3. Backend API Service: Node.js/TypeScript app exposing REST endpoints (auth, file operations) and WebSocket endpoints (chat, editor, terminal, room lifecycle).
4. Docker Daemon (host or sidecar): Backend invokes Docker SDK to create per-room sandboxes.
5. Authentication Store: e.g., MongoDB/Redis or JWT (implied by Passport).
6. (Optional) Persistent Storage: for user session data, logs.
7. Client Browsers: connect over HTTPS/WebSocket.
b. Relationships & Data Flows
- Clients → Traefik → Frontend (HTTP 200 + static assets).
- Frontend → Traefik → Backend (REST calls for login, file listing, room management).
- Frontend ↔ Backend via WebSocket (event streams for code changes, chat messages, terminal I/O).
- Backend → Docker Daemon (gRPC or local socket) to spin up / tear down sandbox containers.
- Backend → Auth Store / DB (validate tokens, session info).
c. Architectural Patterns & Principles
- Single Page Application (SPA) with clear separation from the API.
- Event-driven architecture: each listener handles its domain (Chat, Editor, Terminal, Container, Room).
- Containerized sandbox per user or room for security and isolation.
- API gateway / ingress controller (Traefik) for unified SSL termination and routing.
d. Technologies & Frameworks
- Frontend: React, TypeScript, Vite, Redux, WebSocket client.
- Backend: Node.js, TypeScript, Express (or similar), Passport (auth), Socket.io or ws, Docker SDK.
- Orchestration: Docker Compose (dev and prod), Traefik.

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph "Client Layer"
        Browser["Client Browser"]:::client
    end

    subgraph "Edge Layer"
        Traefik["Traefik Proxy"]:::edge
    end

    subgraph "Application Layer"
        subgraph "Frontend Service"
            ReactSPA["React SPA + Nginx"]:::frontend
        end
        subgraph "Backend Service"
            NodeAPI["Node.js API + WebSocket"]:::backend
            subgraph "SocketListeners"
                Chat["ChatService"]:::backend
                Editor["EditorService"]:::backend
                Room["RoomService"]:::backend
                Container["ContainerService"]:::backend
                TerminalL["TerminalService"]:::backend
            end
        end
    end

    subgraph "Infrastructure Layer"
        DockerDaemon["Docker Daemon"]:::infra
        AuthStore["Auth Store (DB/Redis)"]:::infra
    end

    Browser -->|"HTTPS/HTTP"| Traefik
    Traefik -->|"serves static assets"| ReactSPA
    ReactSPA -->|"RESTAPI"| Traefik
    Traefik -->|"forwards REST"| NodeAPI
    ReactSPA ---|"WebSocket"| NodeAPI
    NodeAPI -->|uses| Chat
    NodeAPI -->|uses| Editor
    NodeAPI -->|uses| Room
    NodeAPI -->|uses| Container
    NodeAPI -->|uses| TerminalL
    NodeAPI -.->|"DockerSDKcalls"| DockerDaemon
    NodeAPI -->|"auth validation"| AuthStore

    click Traefik "https://github.com/roshan-anand/code-join/blob/main/traefik.yaml"
    click ReactSPA "https://github.com/roshan-anand/code-join/tree/main/frontend/"
    click NodeAPI "https://github.com/roshan-anand/code-join/tree/main/backend/"
    click Chat "https://github.com/roshan-anand/code-join/blob/main/backend/src/listeners/Chat.service.ts"
    click Editor "https://github.com/roshan-anand/code-join/blob/main/backend/src/listeners/Editor.service.ts"
    click Room "https://github.com/roshan-anand/code-join/blob/main/backend/src/listeners/Room.service.ts"
    click Container "https://github.com/roshan-anand/code-join/blob/main/backend/src/listeners/Container.service.ts"
    click TerminalL "https://github.com/roshan-anand/code-join/blob/main/backend/src/listeners/Terminal.service.ts"

    classDef client fill:#ADD8E6,stroke:#333,stroke-width:1px;
    classDef edge fill:#90EE90,stroke:#333,stroke-width:1px;
    classDef frontend fill:#FFA500,stroke:#333,stroke-width:1px;
    classDef backend fill:#FF8C00,stroke:#333,stroke-width:1px;
    classDef infra fill:#D3D3D3,stroke:#333,stroke-width:1px;
```
