# olivmath/wess architecture

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

- Interactive diagram: https://gitdiagram.com/olivmath/wess
- Repository: https://github.com/olivmath/wess

## Overview

##### Main Components

a) API Layer:
- HTTP Server (Actix-web based on the Rust ecosystem)
- Three main operation groups: Read, Write, and Run operations
- Middleware components for validation and error handling

b) Worker System:
- Reader Worker (with cache)
- Writer Worker
- Runner Worker (with WebAssembly engine)

c) Storage:
- RocksDB for persistent storage
- In-memory cache for Reader

d) Monitoring & Observability:
- Prometheus metrics endpoint
- Grafana dashboards
- Logging system

##### Component Relationships

a) Write Flow:
**HTTP Request → Write Ops Controller → Writer Channel → Writer Worker → RocksDB**

b) Read Flow:
**HTTP Request → Read Ops Controller → Reader Channel → Reader Worker → Cache/RocksDB → Response**

c) Run Flow:
**HTTP Request → Run Ops Controller → Runner Channel → Runner Worker → WASM Engine → Response**

##### Detailed Component Breakdown

**┌─ API Layer ─────────────────────┐**
- POST / (Create WASM)          │
- PUT /{id} (Update WASM)       │
- GET /{id} (Read WASM)         │
- POST /{id} (Execute WASM)     │
- ┘

- ▼
**┌─ Channel System ───────────────┐**
- WriteJob Channel             │
- ReadJob Channel             │
- RunJob Channel              │
- ┘

- ▼
**┌─ Workers ──────────────────────┐**
- ┌─ Reader ─┐ ┌─ Writer ─┐     │
- Cache  │ │          │     │
- ┘ └──────────┘     │
- ┌─ Runner ────────────────┐    │
- WASM Engine           │    │
- ┘    │
- ┘

- ▼
**┌─ Storage ─────────────────────┐**
- RocksDB                       │
- ┘

##### Additional Elements

Supporting components:
- Metrics collectors
- Logging system
- Configuration management
- Error handling flows

##### Important Notes

- Error handling paths
- Monitoring points
- Configuration injection points
- Cache invalidation flows

##### Testing Components

A separate section showing:
- Behave testing framework integration
- K6 load testing setup
- Test WASM modules

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Styles and classes
    classDef api fill:#2196F3,stroke:#1565C0,color:white
    classDef worker fill:#FF9800,stroke:#F57C00,color:white
    classDef storage fill:#4CAF50,stroke:#388E3B,color:white
    classDef monitoring fill:#9C27B0,stroke:#7B1FA2,color:white
    classDef config fill:#607D8B,stroke:#455A64,color:white
    classDef testing fill:#795548,stroke:#5D4037,color:white
    classDef channel fill:#00BCD4,stroke:#0097A7,color:white

    %% API Layer
    subgraph API
        Server["HTTP Server"]
        ReadOps["Read Operations"]
        WriteOps["Write Operations"]
        RunOps["Run Operations"]
        Middleware["Middleware"]
    end

    %% Channel System
    subgraph Channels
        WriteChannel["Write Channel"]
        ReadChannel["Read Channel"]
        RunChannel["Run Channel"]
    end

    %% Worker System
    subgraph Workers
        ReaderWorker["Reader Worker"]
        ReaderCache["Reader Cache"]
        WriterWorker["Writer Worker"]
        RunnerWorker["Runner Worker"]
        WASMEngine["WASM Engine"]
    end

    %% Storage Layer
    subgraph Storage
        DB["RocksDB"]
        DBModels["Database Models"]
    end

    %% Monitoring
    subgraph Monitoring
        Metrics["Metrics"]
        MetricsRoutes["Metrics Routes"]
        Logger["Logging System"]
        Grafana["Grafana Dashboard"]
        Prometheus["Prometheus"]
    end

    %% Configuration
    subgraph Config
        ConfigHandler["Config Handler"]
        ConfigFiles["Config Files"]
    end

    %% Testing
    subgraph Testing
        BehaveTests["Behave Tests"]
        LoadTests["K6 Load Tests"]
        TestWASM["Test WASM Modules"]
    end

    %% Relationships
    Server --> ReadOps & WriteOps & RunOps
    ReadOps --> ReadChannel
    WriteOps --> WriteChannel
    RunOps --> RunChannel
    
    ReadChannel --> ReaderWorker
    WriteChannel --> WriterWorker
    RunChannel --> RunnerWorker
    
    ReaderWorker --> ReaderCache
    ReaderWorker --> DB
    WriterWorker --> DB
    RunnerWorker --> WASMEngine
    
    Server --> Middleware
    Server --> MetricsRoutes
    MetricsRoutes --> Metrics
    Metrics --> Prometheus
    Prometheus --> Grafana
    
    ConfigHandler --> Server

    %% Click events
    click Server "https://github.com/olivmath/wess/blob/main/src/server/mod.rs"
    click ReadOps "https://github.com/olivmath/wess/blob/main/src/server/routes/read_ops/mod.rs"
    click WriteOps "https://github.com/olivmath/wess/blob/main/src/server/routes/write_ops/mod.rs"
    click RunOps "https://github.com/olivmath/wess/blob/main/src/server/routes/run_ops/mod.rs"
    click Middleware "https://github.com/olivmath/wess/blob/main/src/server/routes/middleware/mod.rs"
    click ReaderWorker "https://github.com/olivmath/wess/blob/main/src/workers/reader/mod.rs"
    click ReaderCache "https://github.com/olivmath/wess/blob/main/src/workers/reader/cache.rs"
    click WriterWorker "https://github.com/olivmath/wess/blob/main/src/workers/writer/mod.rs"
    click RunnerWorker "https://github.com/olivmath/wess/blob/main/src/workers/runner/mod.rs"
    click WASMEngine "https://github.com/olivmath/wess/blob/main/src/workers/runner/engine/mod.rs"
    click DB "https://github.com/olivmath/wess/blob/main/src/database/mod.rs"
    click DBModels "https://github.com/olivmath/wess/blob/main/src/database/models.rs"
    click Metrics "https://github.com/olivmath/wess/blob/main/src/metrics/mod.rs"
    click MetricsRoutes "https://github.com/olivmath/wess/blob/main/src/server/routes/metrics/mod.rs"
    click Logger "https://github.com/olivmath/wess/blob/main/src/logger/mod.rs"
    click Grafana "https://github.com/olivmath/wess/blob/main/grafana-wess.json"
    click Prometheus "https://github.com/olivmath/wess/blob/main/prometheus.yml"
    click ConfigHandler "https://github.com/olivmath/wess/blob/main/src/config/mod.rs"
    click ConfigFiles "https://github.com/olivmath/wess/blob/main/wess.toml"
    click BehaveTests "https://github.com/olivmath/wess/tree/main/tests/behave/features/"
    click LoadTests "https://github.com/olivmath/wess/blob/main/tests/load/k6.js"
    click TestWASM "https://github.com/olivmath/wess/tree/main/wasm/"

    %% Style applications
    class Server,ReadOps,WriteOps,RunOps,Middleware api
    class ReaderWorker,WriterWorker,RunnerWorker,WASMEngine,ReaderCache worker
    class DB,DBModels storage
    class Metrics,MetricsRoutes,Logger,Grafana,Prometheus monitoring
    class ConfigHandler,ConfigFiles config
    class BehaveTests,LoadTests,TestWASM testing
    class WriteChannel,ReadChannel,RunChannel channel
```
