# elyseemb/controllerobs architecture

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

- Interactive diagram: https://gitdiagram.com/elyseemb/controllerobs
- Repository: https://github.com/elyseemb/controllerobs

## Overview

##### Project type and purpose
- ControllerOBS is a full-stack Node.js/TypeScript application.
- Purpose: provide a modern React-based UI to drive OBS Studio via the obs-websocket API. It bundles a backend server that:
- Serves the React SPA (Vite build)
- Manages WebSocket/HTTP endpoints (Socket.IO, finalhandler, serve-static)
- Connects to OBS Studio (OBS-Websocket-JS)
- Manages profiles and configuration (JSON files via utils/db.ts)

##### File structure
- Top-level:
- src/main → server code (app.ts, modules, clients, ObsServer, utils)
- src/render → client code (React/Vite, Layout, components, views, assets)
- src/resources/json/config.json → persisted settings/profiles
- build → compiled output (server and client)
- Patterns & modules:
- MVC-style breakdown inside server: Controller.ts ▲ business logic, Server.ts ▲ HTTP/WebSocket setup, Clients → OBS client wrapper, modules/Profiles & Setup → domain modules
- Reactive flows (RxJS) inside modules/Controller.ts
- Serve static client and open WebSocket channel via Socket.IO
- Configuration/build: package.json scripts, nodemon.json, tsconfig.json, Vite config

##### README
- Confirms: full-stack Node+TS, React/Vite front end + Node server back end
- Key tech: OBS-Websocket-JS, Socket.IO, finalhandler, serve-static, RxJS, pnpm

##### Main components and interactions
a. Components
- Frontend (Browser/React SPA)
- Backend HTTP/WebSocket Server (Express-style + Socket.IO)
- OBS WebSocket API (external service running in OBS Studio)
- Configuration store (local JSON DB)
- Logger (utils/logger.ts)
b. Relationships & data flows
1. User interacts with React UI → emits Socket.IO events or HTTP fetch to Server
2. Server’s ObsServer/Controller modules process the request → use OBSClient to call the OBS WebSocket API
3. OBS Studio responds → OBSClient publishes events via RxJS streams → Controller pushes responses back to UI over Socket.IO
4. For profile/setup, Controller/Profiles modules read/write config.json via db.ts → notify UI of changes
c. Architectural patterns
- Layered: Presentation (React) → API (Socket.IO/HTTP) → Domain logic (Controller, Profiles, Setup modules) → External integration (OBSClient) → Data store (JSON)
- Reactive streams (RxJS) inside the domain layer
- Modular: each feature (Profiles, Setup, Controller) is its own module
d. Key frameworks/technologies
- Frontend: React, Vite, TypeScript, CSS modules
- Server: Node.js, TypeScript, RxJS, Socket.IO, finalhandler, serve-static
- External: obs-websocket-js

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client Tier
    subgraph "Client Tier"
        direction TB
        ReactApp["React SPA (Vite, TSX)"]:::frontend
    end

    %% Server Tier
    subgraph "Server Tier"
        direction TB
        App["Application Entrypoint\n(app.ts)"]:::api
        Server["HTTP/WebSocket Server\n(Server.ts)"]:::api
        ObsServer["OBS-WebSocket Setup\n(ObsServer.ts)"]:::api

        subgraph "Domain Modules"
            direction TB
            Controller["Controller Module\n(Controller.ts)"]:::domain
            Profiles["Profiles Module\n(Profiles.ts)"]:::domain
            SetupMod["Setup Module\n(Setup.ts)"]:::domain
        end

        subgraph "Clients"
            direction TB
            OBSClient["OBSClient Wrapper\n(OBSClient.ts)"]:::client
            ClientBase["Client Base\n(Client.ts)"]:::client
        end

        subgraph "Utilities"
            direction TB
            DB["JSON DB Utils\n(db.ts)"]:::util
            Logger["Logger\n(logger.ts)"]:::util
            Utils["Misc Utilities\n(utils.ts)"]:::util
        end
    end

    %% External and Data Store
    OBSStudio["OBS Studio\n(OBS WebSocket)"]:::external
    ConfigFile["Config File\n(config.json)"]:::datastore
    BuildOutput["Build Output\n(build/main)"]:::datastore

    %% Connections
    User[/"User"/]:::external -->|interacts| ReactApp
    ReactApp -->|"HTTP Fetch / WebSocket"| Server
    ReactApp <-->|"Socket.IO Events"| ObsServer

    App -->|initializes| Server
    App -->|initializes| ObsServer
    Server -->|routes to| Controller
    Server -->|routes to| Profiles
    Server -->|routes to| SetupMod

    ObsServer -->|"Socket.IO to Controller"| Controller

    Controller -->|"calls"| OBSClient
    Profiles -->|"uses"| DB
    SetupMod -->|"uses"| DB

    OBSClient -->|"OBS WebSocket"| OBSStudio
    OBSStudio -->|"events"| OBSClient

    Controller -->|"reads/writes"| DB
    Controller -->|"logs via"| Logger
    Profiles -->|"logs via"| Logger
    SetupMod -->|"logs via"| Logger
    Server -->|"serves static via"| Utils

    DB -->|persists| ConfigFile

    %% Build Output
    BuildOutput -->|contains| ReactApp
    BuildOutput -->|contains| Server

    %% Click Events
    click ReactApp "https://github.com/elyseemb/controllerobs/tree/master/src/render"
    click App "https://github.com/elyseemb/controllerobs/blob/master/src/main/app.ts"
    click Server "https://github.com/elyseemb/controllerobs/blob/master/src/main/server/Server.ts"
    click ObsServer "https://github.com/elyseemb/controllerobs/blob/master/src/main/server/ObsServer.ts"
    click Controller "https://github.com/elyseemb/controllerobs/blob/master/src/main/modules/Controller.ts"
    click Profiles "https://github.com/elyseemb/controllerobs/blob/master/src/main/modules/Profiles.ts"
    click SetupMod "https://github.com/elyseemb/controllerobs/blob/master/src/main/modules/Setup.ts"
    click OBSClient "https://github.com/elyseemb/controllerobs/blob/master/src/main/clients/OBSClient.ts"
    click ClientBase "https://github.com/elyseemb/controllerobs/blob/master/src/main/clients/Client.ts"
    click DB "https://github.com/elyseemb/controllerobs/blob/master/src/main/utils/db.ts"
    click Logger "https://github.com/elyseemb/controllerobs/blob/master/src/main/utils/logger.ts"
    click Utils "https://github.com/elyseemb/controllerobs/blob/master/src/main/utils/utils.ts"
    click ConfigFile "https://github.com/elyseemb/controllerobs/blob/master/src/resources/json/config.json"
    click BuildOutput "https://github.com/elyseemb/controllerobs/tree/master/build/main"

    %% Styles
    classDef frontend fill:#f9f,stroke:#333,stroke-width:1px
    classDef api fill:#bbf,stroke:#333,stroke-width:1px
    classDef domain fill:#bfb,stroke:#333,stroke-width:1px
    classDef client fill:#ffd,stroke:#333,stroke-width:1px
    classDef util fill:#fcf,stroke:#333,stroke-width:1px
    classDef external fill:#fea,stroke:#333,stroke-width:1px
    classDef datastore fill:#aff,stroke:#333,stroke-width:1px
```
