# misterneo/monkey-app-clone architecture

> Architecture diagram of the GitHub repository misterneo/monkey-app-clone, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-11-10). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/misterneo/monkey-app-clone
- Repository: https://github.com/misterneo/monkey-app-clone

## Overview

##### Project type and purpose
- This is a full-stack, real-time video-chat “Monkey App Clone” comprising:
- A ReactJS SPA frontend (Vite) that handles user interface, state (Redux), WebRTC peer connections (PeerJS), and WebSocket signaling (react-use-websocket).
- A BunJS backend that exposes an HTTP server (serving WebSocket upgrades) for pairing users and relaying WebRTC signaling messages.
- Docker Compose to orchestrate two containers: one for client (port 5173) and one for server (port 3000).

##### File structure
- Top level:
- client/ → React application (src/, public/, Vite & Tailwind config, Dockerfile, .env.example).
- server/ → BunJS app (index.ts - HTTP + WebSocket server, utils/, pm2 config, Dockerfile, tsconfig).
- docker-compose.yml orchestrates both.
- Patterns:
- client/src/features/main & /messaging subdivide UI into the video-chat flow and DataChannel chat flow (Redux slices, components).
- client/src/utils/usePeer.js & constants/helpers manage PeerJS initialization and config.
- server/utils/websocketHandler.ts implements pairing logic and routes signaling messages.

##### README
- Confirms use of React, Redux Toolkit, PeerJS (WebRTC), react-use-websocket, BunJS, Docker Compose.
- No persistent database—peer-to-peer media and data is ephemeral; server only handles signaling.
- Running modes: BunJS locally or containerized with Docker Compose.

##### Detail
- Every distinct module as its own node: WebSocket Handler, PeerJS Init, Redux Store, video components, data components.
- Don’t oversimplify—show the two-phase connection (signaling vs direct P2P).
- Ports (5173, 3000) and mention environment variables (.env.local → VITE_SERVER_PORT).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Container
    subgraph "Frontend Container (Client)" 
        direction TB
        FE_HTTP["HTTP Server\n(Vite Dev/Static)"]:::frontend
        FE_WS["WebSocket Client\n(react-use-websocket)"]:::frontend
        FE_Peer["PeerJS Init Hook\n(usePeer)"]:::frontend
        FE_Redux["Redux Store\n(store.js)"]:::frontend
        FE_Video["Video Chat Feature\n(mainSlice, LocalSide, RemoteSide)"]:::frontend
        FE_Msg["DataChannel Chat Feature\n(messagingSlice, index.jsx)"]:::frontend
        FE_Constants["Constants & Helpers"]:::frontend
        FE_Layouts["App Layouts\n(AppLayout, Side)"]:::frontend
        FE_ConfigVite["Vite Config"]:::frontend
        FE_ConfigTailwind["Tailwind Config"]:::frontend
        FE_DockerfileClient["Dockerfile"]:::frontend
        FE_ENTRY["React Entry Point\n(main.jsx)"]:::frontend
    end

    %% Backend Container
    subgraph "Backend Container (Signaling Server)" 
        direction TB
        BE_HTTP["HTTP & WebSocket Server\n(index.ts)"]:::backend
        BE_WSHandler["WebSocket Handler\n(websocketHandler.ts)"]:::backend
        BE_Helpers["Server Helpers & Types"]:::backend
        BE_Dockerfile["Dockerfile"]:::backend
        BE_PM2["PM2 Config"]:::backend
    end

    %% Docker Compose Network
    subgraph "Docker Compose Network" 
        direction TB
        FrontendContainer((Frontend))
        BackendContainer((Backend))
    end

    %% External Services
    STUN["STUN/TURN Server\n(PeerJS Cloud)"]:::external

    %% Connections
    FE_HTTP -->|"loads SPA"| FE_ENTRY
    FE_ENTRY --> FE_Layouts
    FE_Layouts --> FE_Redux
    FE_Redux --> FE_Video
    FE_Redux --> FE_Msg
    FE_Video --> FE_Peer
    FE_Msg --> FE_Peer
    FE_Peer --> FE_WS
    FE_WS -->|"WebSocket: SDP & ICE"| BE_WSHandler
    BE_WSHandler --> BE_HTTP
    BE_HTTP -->|"upgrade WS"| BE_WSHandler
    FE_Peer -->|"WebRTC Media Stream & DataChannel"| FE_Peer
    FE_Peer -->|"peer-to-peer"| STUN

    %% Container to Network
    FrontendContainer --- FE_HTTP
    BackendContainer --- BE_HTTP

    %% Network to Network
    FrontendContainer --- BackendContainer

    %% Click Events
    click FE_HTTP "https://github.com/misterneo/monkey-app-clone/tree/main/client/"
    click FE_WS "https://github.com/misterneo/monkey-app-clone/blob/main/client/src/utils/usePeer.js"
    click FE_Peer "https://github.com/misterneo/monkey-app-clone/blob/main/client/src/utils/usePeer.js"
    click FE_Redux "https://github.com/misterneo/monkey-app-clone/blob/main/client/src/app/store.js"
    click FE_Video "https://github.com/misterneo/monkey-app-clone/tree/main/client/src/features/main/"
    click FE_Msg "https://github.com/misterneo/monkey-app-clone/tree/main/client/src/features/messaging/"
    click FE_Constants "https://github.com/misterneo/monkey-app-clone/blob/main/client/src/utils/constants.js"
    click FE_Constants "https://github.com/misterneo/monkey-app-clone/blob/main/client/src/utils/helpers.js"
    click FE_Layouts "https://github.com/misterneo/monkey-app-clone/blob/main/client/src/layouts/AppLayout.jsx"
    click FE_Layouts "https://github.com/misterneo/monkey-app-clone/blob/main/client/src/layouts/Side.jsx"
    click FE_ConfigVite "https://github.com/misterneo/monkey-app-clone/blob/main/client/vite.config.js"
    click FE_ConfigTailwind "https://github.com/misterneo/monkey-app-clone/blob/main/client/tailwind.config.js"
    click FE_DockerfileClient "https://github.com/misterneo/monkey-app-clone/tree/main/client/Dockerfile"
    click FE_ENTRY "https://github.com/misterneo/monkey-app-clone/blob/main/client/src/main.jsx"

    click BE_HTTP "https://github.com/misterneo/monkey-app-clone/blob/main/server/index.ts"
    click BE_WSHandler "https://github.com/misterneo/monkey-app-clone/blob/main/server/utils/websocketHandler.ts"
    click BE_Helpers "https://github.com/misterneo/monkey-app-clone/blob/main/server/utils/helpers.ts"
    click BE_Helpers "https://github.com/misterneo/monkey-app-clone/blob/main/server/utils/types.ts"
    click BE_Dockerfile "https://github.com/misterneo/monkey-app-clone/tree/main/server/Dockerfile"
    click BE_PM2 "https://github.com/misterneo/monkey-app-clone/blob/main/server/pm2.config.cjs"

    click FrontendContainer "https://github.com/misterneo/monkey-app-clone/blob/main/docker-compose.yml"
    click BackendContainer "https://github.com/misterneo/monkey-app-clone/blob/main/docker-compose.yml"

    %% Styles
    classDef frontend fill:#bbe1fa,stroke:#1f618d,color:#1b2631;
    classDef backend fill:#8ef598,stroke:#1b5e20,color:#1b2631;
    classDef external fill:#ffd6a5,stroke:#e67e22,color:#1b2631;
    classDef network fill:#f1c0e8,stroke:#8e44ad,color:#1b2631;
```
