# rocicorp/mono architecture

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

- Interactive diagram: https://gitdiagram.com/rocicorp/mono
- Repository: https://github.com/rocicorp/mono

## Overview

##### Main Components and Their Purposes
- Zero Product:
- Client Library: Located in packages/zero-client. This is the main client library that uses Replicache under the hood.
- Server Side: Found in packages/zero-cache, which handles server responsibilities.
- Incremental View Maintenance Engine & Query Language/API: In packages/zql; this module builds the “IVM” and query functionality.
- Bug Tracker App: In apps/zbugs, an example full-stack application built on top of the Zero libraries.
- Other supportive packages like zero-pg, zero-protocol, zero-react, zero-schema, and zero-solid provide additional features, integrations, and frontend components.

- Replicache Product:
- Client Library: Located in packages/replicache (and its associated docs within the same package structure).
- Documentation pages and related tooling (e.g., the replicache-doc content).

- Ancillary Tools and Libraries:
- Additional packages like shared, otel, datadog, ast-to-zql, and others that support logging, telemetry, and code reuse across both product lines.
- Tools directory (e.g., client-simulator, load-generator, process-tracker) and prod/sts for deployments.

##### Recognize Architectural Patterns from the File Structure
- Layered Architecture for Zero: For Zero, you want to show the frontend layers (e.g., bug tracker UI in apps/zbugs, zero-react, or solid-view integrations) and back-end layers (e.g., zero-cache, zero-server packages). Also, note that the client libraries interact with the server implementations using the IVM/query engine (zql).
- Common Utilities and Shared Code: The packages/shared module and similar packages are used by multiple products, so show them as supporting libraries that provide cross-cutting capabilities (e.g., configuration, logging, validation).

##### Relationships and Data Flow
- How the Zero client (zero-client) sends or receives data from the Zero server (zero-cache), potentially via the IVM engine provided by zql.
- How replicache and other auxiliary modules come into play: for example, the Zero client library uses Replicache functionality.
- Integration paths to external systems, such as Docker configurations (in apps/zbugs/docker) for setting up databases, as well as CI/CD pipelines defined in the .github/workflows folder which orchestrate testing, deployments, and build processes.

##### Technologies, Frameworks, and Design Principles
- The repo predominantly uses TypeScript (note tsconfig.json files distributed across the monorepo) and relies on modern web development practices.
- The use of packages such as Playwright for testing (see apps/zbugs/playwright) indicates an automated end-to-end testing strategy.
- The inclusion of Docker files and various deployment configurations (prod/sst, docker-compose files) suggests containerization and serverless deployment practices.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Zero Product Subgraph
    subgraph "Zero Product"
        ZClient("Zero Client Library"):::zero
        Zql("IVM & Query Engine (ZQL)"):::zero
        ZCache("Zero Server Side (Cache)"):::zero
        BugApp("Bug Tracker App"):::zero
        ZeroPg("zero-pg"):::zero
        ZeroProtocol("zero-protocol"):::zero
        ZeroReact("zero-react"):::zero
        ZeroSchema("zero-schema"):::zero
        ZeroSolid("zero-solid"):::zero
    end

    %% Replicache Product Subgraph
    subgraph "Replicache Product"
        RepClient("Replicache Client Library"):::replicache
        RepDoc("Replicache Documentation and Tooling"):::replicache
    end

    %% Ancillary Tools & Libraries Subgraph
    subgraph "Ancillary Tools & Libraries"
        Shared("Shared Utilities"):::ancillary
        Otel("Telemetry (otel)"):::ancillary
        Datadog("Telemetry (datadog)"):::ancillary
        AstToZQL("AST to ZQL"):::ancillary
    end

    %% Additional Tools Subgraph
    subgraph "Additional Tools"
        ClientSim("Client Simulator"):::tools
        LoadGen("Load Generator"):::tools
        ProcTrack("Process Tracker"):::tools
    end

    %% Deployment & Production Subgraph
    subgraph "Deployment & Production"
        SST("SST Deployments"):::deployment
        Functions("Serverless Functions"):::deployment
    end

    %% Connections within Zero Product
    ZClient -->|"uses"| Zql
    Zql -->|"queries"| ZCache
    ZClient -->|"communicates"| ZCache
    BugApp -->|"built_on"| ZClient

    %% Supportive Zero Packages connections
    ZeroProtocol -->|"manages"| ZClient
    ZeroSchema -->|"validates"| ZClient
    ZeroReact -->|"enhances_UI"| BugApp
    ZeroSolid -->|"enhances_UI"| BugApp
    ZeroPg -->|"integrates_DB"| ZCache

    %% Integration between Zero and Replicache
    ZClient -->|"integrates_Replicache"| RepClient

    %% Ancillary Tools & Libraries supporting products
    Shared --- ZClient
    Otel --- ZClient
    Datadog --- ZCache
    AstToZQL --- Zql
    Shared --- RepClient
    Otel --- RepClient

    %% Additional Tools supporting Zero Product
    ClientSim --- ZClient
    LoadGen --- ZClient
    ProcTrack --- ZCache

    %% Deployment & Production integrating with products
    SST --- ZCache
    SST --- RepClient
    Functions --- ZCache

    %% Click Events
    click ZClient "https://github.com/rocicorp/mono/tree/main/packages/zero-client"
    click ZCache "https://github.com/rocicorp/mono/tree/main/packages/zero-cache"
    click Zql "https://github.com/rocicorp/mono/tree/main/packages/zql"
    click BugApp "https://github.com/rocicorp/mono/tree/main/apps/zbugs"
    click ZeroPg "https://github.com/rocicorp/mono/tree/main/packages/zero-pg"
    click ZeroProtocol "https://github.com/rocicorp/mono/tree/main/packages/zero-protocol"
    click ZeroReact "https://github.com/rocicorp/mono/tree/main/packages/zero-react"
    click ZeroSchema "https://github.com/rocicorp/mono/tree/main/packages/zero-schema"
    click ZeroSolid "https://github.com/rocicorp/mono/tree/main/packages/zero-solid"
    click RepClient "https://github.com/rocicorp/mono/tree/main/packages/replicache"
    click RepDoc "https://github.com/rocicorp/mono/tree/main/packages/replicache-doc"
    click Shared "https://github.com/rocicorp/mono/tree/main/packages/shared"
    click Otel "https://github.com/rocicorp/mono/tree/main/packages/otel"
    click Datadog "https://github.com/rocicorp/mono/tree/main/packages/datadog"
    click AstToZQL "https://github.com/rocicorp/mono/tree/main/packages/ast-to-zql"
    click ClientSim "https://github.com/rocicorp/mono/tree/main/tools/client-simulator"
    click LoadGen "https://github.com/rocicorp/mono/tree/main/tools/load-generator"
    click ProcTrack "https://github.com/rocicorp/mono/tree/main/tools/process-tracker"
    click SST "https://github.com/rocicorp/mono/tree/main/prod/sst"
    click Functions "https://github.com/rocicorp/mono/tree/main/prod/functions"

    %% Styles
    classDef zero fill:#ffcccc,stroke:#cc0000,stroke-width:2px;
    classDef replicache fill:#ccffcc,stroke:#006600,stroke-width:2px;
    classDef ancillary fill:#ccccff,stroke:#0000cc,stroke-width:2px;
    classDef tools fill:#ffffcc,stroke:#cccc00,stroke-width:2px;
    classDef deployment fill:#ffccff,stroke:#cc00cc,stroke-width:2px;
```
