# placenl/chief architecture

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

- Interactive diagram: https://gitdiagram.com/placenl/chief
- Repository: https://github.com/placenl/chief

## Overview

##### Main System Components

a) WebSocket Server Layer
- Central communication hub for real-time updates
- Handles various types of messages (orders, capabilities, subscriptions)
- Located in /src/ws directory

b) REST API Layer
- HTTP endpoints for non-real-time operations
- Documented in /docs/rest/ROUTES.md
- Located in /src/api directory

c) Core Services
- Artist Service (/src/artist)
- Service (/src/place)
- Template Service (/src/template)
- Metrics Service (/src/metrics)

d) Web Interface
- Artist interface (/web/artist)
- Order creation interface (/web/artist/createorder)
- Main dashboard (/web/index.html)

##### Component Relationships

a) Client Communication Flow:
**Clients <---> WebSocket Server <---> Core Services**
**Clients <---> REST API <---> Core Services**

b) Internal Service Communication:
**Template Service <---> Place Service**
**Artist Service <---> Template Service**
**Metrics Service <--- (monitors all services)**

##### Specific Elements

a) WebSocket Handlers (from /src/ws/handler):
- Brand handler
- Capabilities handler
- Orders handler
- Handler
- Stats handler
- Subscriptions handler

b) Client Types (from docs/client):
- Overlay clients
- Automatic placers
- Different subscription types

##### Notes for Implementation Details

Annotations for:
- Docker container boundary (due to presence of Dockerfile)
- GitHub Actions workflow integration
- Metrics collection points
- Client capability negotiation

Remember to indicate the scalability points and potential bottlenecks in the system, as this is crucial for a r/Place coordination server that might need to handle numerous concurrent connections and template updates.

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Clients
        OC[Overlay Clients]:::client
        AP[Automatic Placers]:::client
    end

    subgraph "WebSocket Server"
        WS["WebSocket Server"]:::ws
        click WS "https://github.com/PlaceNL/Chief/blob/master/src/ws/index.js"
        
        subgraph "WS Handlers"
            BH["Brand Handler"]:::handler
            click BH "https://github.com/PlaceNL/Chief/blob/master/src/ws/handler/brand.js"
            CH["Capabilities Handler"]:::handler
            click CH "https://github.com/PlaceNL/Chief/blob/master/src/ws/handler/capabilities.js"
            OH["Orders Handler"]:::handler
            click OH "https://github.com/PlaceNL/Chief/blob/master/src/ws/handler/orders.js"
            PH["Place Handler"]:::handler
            click PH "https://github.com/PlaceNL/Chief/blob/master/src/ws/handler/place.js"
            SH["Stats Handler"]:::handler
            click SH "https://github.com/PlaceNL/Chief/blob/master/src/ws/handler/stats.js"
            SubH["Subscriptions Handler"]:::handler
            click SubH "https://github.com/PlaceNL/Chief/blob/master/src/ws/handler/subscriptions.js"
        end
    end

    subgraph "REST API"
        API["REST API Server"]:::api
        click API "https://github.com/PlaceNL/Chief/blob/master/src/api/index.js"
    end

    subgraph "Core Services"
        AS["Artist Service"]:::service
        click AS "https://github.com/PlaceNL/Chief/blob/master/src/artist/index.js"
        PS["Place Service"]:::service
        click PS "https://github.com/PlaceNL/Chief/blob/master/src/place/PlaceClient.js"
        TS["Template Service"]:::service
        click TS "https://github.com/PlaceNL/Chief/blob/master/src/template/index.js"
        MS["Metrics Service"]:::service
        click MS "https://github.com/PlaceNL/Chief/blob/master/src/metrics/index.js"
    end

    subgraph "Web Interface"
        MD["Main Dashboard"]:::web
        click MD "https://github.com/PlaceNL/Chief/blob/master/web/index.html"
        AI["Artist Interface"]:::web
        click AI "https://github.com/PlaceNL/Chief/blob/master/web/artist/index.html"
        OCI["Order Creation Interface"]:::web
        click OCI "https://github.com/PlaceNL/Chief/blob/master/web/artist/createorder/index.html"
    end

    %% Connections
    OC & AP <--> WS
    OC & AP <--> API
    
    WS --> BH & CH & OH & PH & SH & SubH
    BH & CH & OH & PH & SH & SubH --> AS & PS & TS
    
    API --> AS & PS & TS
    
    AS <--> TS
    TS <--> PS
    MS --> AS & PS & TS & WS & API
    
    AI & OCI --> API
    MD --> API
    
    %% Styles
    classDef client fill:#gray,stroke:#333,stroke-width:2px
    classDef ws fill:#blue,stroke:#333,stroke-width:2px
    classDef handler fill:#lightblue,stroke:#333,stroke-width:2px
    classDef api fill:#green,stroke:#333,stroke-width:2px
    classDef service fill:#orange,stroke:#333,stroke-width:2px
    classDef web fill:#purple,stroke:#333,stroke-width:2px

    %% Legend
    subgraph Legend
        C1[Client]:::client
        W1[WebSocket]:::ws
        H1[Handler]:::handler
        A1["REST API"]:::api
        S1[Service]:::service
        WI1["Web Interface"]:::web
    end
```
