# jameschensh/frost architecture

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

- Interactive diagram: https://gitdiagram.com/jameschensh/frost
- Repository: https://github.com/jameschensh/frost

## Overview

##### Project type and purpose
- FRoST (“FoundationDB, RocksDB Simulation Tester”) is an open‑source, command‑line deterministic simulation framework written in Zig.
- It exercises “actors” (clients and replicas) against pluggable key‑value backends (FoundationDB, RocksDB, etc.) under a deterministic scheduler and PRNG to compare correctness and performance.

##### File structure
- Top‑level:
- build.zig       – Zig’s build script
- config/         – TOML files for atomic ops and simulator parameters
- scripts/        – helper scripts (e.g., run_fdb_sim.sh)
- src/            – all Zig source code
- src/ substructure:
- main.zig        – CLI entry point (“frost”)
- config.zig      – loads and parses TOML settings
- prng.zig        – deterministic random number generator
- scheduler.zig   – event/time‐tick scheduler
- network.zig     – message queueing and delivery simulation
- simulator.zig   – top‐level orchestrator tying actors, network, scheduler
- actors/         – client.zig & replica.zig, driving read/write ops
- messages.zig    – typed message definitions between actors
- db/             – adapter.zig plus backend folders (fdb/, rocksdb/) each with a C binding, build.zig

##### README’s architectural hints
- It mentions a high‐level SVG in docs/assets showing how clients, replicas, network, scheduler, and storage backends interact.
- Emphasizes deterministic replay via seed, pluggable backends, and “tick” loop.

a. Main components
- CLI / “frost” process
- Configuration Loader (TOML parser)
- Simulator Core
- Scheduler (time/tick manager)
- PRNG (deterministic seed)
- Actor Layer
- Client Actor
- Replica Actor
- Network Layer (virtual message queue)
- Storage Layer (DB Adapters)
- FoundationDB adapter (C binding)
- RocksDB adapter (C binding)
- Output / Logging module

b. Relationships & interactions
1. CLI → Configuration Loader → Simulator Core
2. Simulator Core uses Scheduler & PRNG to drive a loop:
- On each tick, Scheduler awakens Actors
- Actors generate Messages (requests, acks)
- Messages pass to Network Layer
- Network delivers messages back to actors according to schedule
- Replica Actors invoke DB Adapter calls (FDB / RocksDB)
3. Results & logs flow back to Core for reporting

c. Architectural patterns & principles
- Event‐driven, tick‐based deterministic simulation
- Modular plugin pattern for backend adapters
- Clear separation: orchestration (simulator), behavior (actors), communication (network), storage (db)

d. Key technologies & libraries
- Zig 0.14.0 (ZVM) for all implementation
- TOML for config (AtomicOps.toml)
- FoundationDB C API (fdb.c / fdb.zig)
- RocksDB C++ API via C shim (rocks.zig)

##### Detail
- PRNG and config loader as first‑class components because seed and params drive determinism

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Config/CLI Layer
    subgraph "Config & CLI Layer"
        CLI["CLI / frost process"]:::cli
        Config["Configuration Loader"]:::cli
    end

    %% Orchestration Core
    subgraph "Orchestration Layer"
        Simulator["Simulator Core"]:::orchestration
        Scheduler["Scheduler"]:::orchestration
        PRNG["PRNG"]:::orchestration
    end

    %% Actors Layer
    subgraph "Actor Layer"
        Client["Client Actor"]:::actors
        Replica["Replica Actor"]:::actors
    end

    %% Network & Messaging
    subgraph "Network & Messaging"
        Messages["Message Definitions"]:::messages
        Network["Network Layer"]:::network
    end

    %% Storage Layer
    subgraph "Storage Layer"
        Adapter["Adapter Interface"]:::storage
        subgraph "FoundationDB Adapter"
            FDBAdapter["FDB Adapter"]:::storage
            FDBC["fdb.c"]:::storage
            FDBBuild["build.zig"]:::storage
        end
        subgraph "RocksDB Adapter"
            RocksAdapter["RocksDB Adapter"]:::storage
            RocksBuild["build.zig"]:::storage
        end
    end

    %% Logging
    Logging["Output / Logging Module"]:::logging

    %% Connections
    CLI -->|invokes| Config
    Config -->|loads settings| Simulator
    Simulator -->|uses| Scheduler
    Simulator -->|uses| PRNG
    Simulator -->|reports to| Logging

    Scheduler -->|tick| Client
    Scheduler -->|tick| Replica

    Client -->|sends| Messages
    Replica -->|sends| Messages

    Messages -->|queued in| Network
    Network -->|delivers to| Client
    Network -->|delivers to| Replica

    Replica -->|calls| Adapter

    Adapter -->|implements| FDBAdapter
    Adapter -->|implements| RocksAdapter

    FDBAdapter -->|binds via| FDBC
    FDBAdapter -->|build script| FDBBuild

    RocksAdapter -->|build script| RocksBuild

    %% Click Events
    click CLI "https://github.com/jameschensh/frost/blob/main/src/main.zig"
    click Config "https://github.com/jameschensh/frost/blob/main/src/config.zig"
    click Simulator "https://github.com/jameschensh/frost/blob/main/src/simulator.zig"
    click Scheduler "https://github.com/jameschensh/frost/blob/main/src/scheduler.zig"
    click PRNG "https://github.com/jameschensh/frost/blob/main/src/prng.zig"
    click Client "https://github.com/jameschensh/frost/blob/main/src/actors/client.zig"
    click Replica "https://github.com/jameschensh/frost/blob/main/src/actors/replica.zig"
    click Network "https://github.com/jameschensh/frost/blob/main/src/network.zig"
    click Messages "https://github.com/jameschensh/frost/blob/main/src/messages.zig"
    click Adapter "https://github.com/jameschensh/frost/blob/main/src/db/adapter.zig"
    click FDBAdapter "https://github.com/jameschensh/frost/blob/main/src/db/fdb/fdb.zig"
    click FDBC "https://github.com/jameschensh/frost/blob/main/src/db/fdb/fdb.c"
    click FDBBuild "https://github.com/jameschensh/frost/blob/main/src/db/fdb/build.zig"
    click RocksAdapter "https://github.com/jameschensh/frost/blob/main/src/db/rocksdb/rocks.zig"
    click RocksBuild "https://github.com/jameschensh/frost/blob/main/src/db/rocksdb/build.zig"
    click Logging "https://github.com/jameschensh/frost/blob/main/build.zig"
    click Config "https://github.com/jameschensh/frost/blob/main/config/AtomicOps.toml"

    %% Styles
    classDef orchestration fill:#cfe2f3,stroke:#333,stroke-width:1px;
    classDef actors fill:#d9ead3,stroke:#333,stroke-width:1px;
    classDef network fill:#fce5cd,stroke:#333,stroke-width:1px;
    classDef storage fill:#ead1dc,stroke:#333,stroke-width:1px;
    classDef cli fill:#e7e6e6,stroke:#333,stroke-width:1px;
    classDef messages fill:#fff2cc,stroke:#333,stroke-width:1px;
    classDef logging fill:#e7e6e6,stroke:#333,stroke-width:1px;
```
