# cbnsndwch/zero-sources architecture

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

- Interactive diagram: https://gitdiagram.com/cbnsndwch/zero-sources
- Repository: https://github.com/cbnsndwch/zero-sources

## Overview

##### Project Type & Purpose
- This is a monorepo that provides custom change source implementations for @rocicorp/zero together with utility libraries. Its main services (in the apps folder, such as “source-mongodb”) are built using NestJS and are designed to be containerized (Docker support is present).
- The repository manages multiple packages via Yarn Workspaces and Turborepo, and it includes helper libraries (like “zero-nest-mongoose” for schema utilities and integrations) along with configuration utilities (eslint-config, tsconfig).

##### Main Components

a. Custom Change Source Apps (e.g., apps/source-mongodb)
- Health Check Module (“healthz”): responsible for system health endpoints.
- Watermark Handling Modules: shows two paths (one via a “nats” submodule and another via “zqlite”) that manage watermark-related interactions.
- Zero Module: encapsulates logic for handling custom change source behaviors (e.g., “zero” feature with contracts, gateways, services, and entities).
- Intra-module relationships such as controllers, services, providers, and utilities (like cors, serialization, etc.).

b. Shared Libraries
- “libs” folder as another major block with several sub-components:
- ESLint Config and TSConfig: shared configurations that affect coding standards and project settings.
- Zero-Nest-Mongoose Library: highlight that this library provides additional functionality (e.g., schema generation, contracts, and modules for managing entities such as “bugs” and “pokemon”).

c. External Systems & Infrastructure
- Docker: Represent the Docker configuration (e.g., under the “.docker/nats” folder) as an external deployment/infrastructure environment component. This illustrates that parts of the system (like NATS for messaging) are containerized.
- NATS (and associated configurations): Show a separate component for the NATS messaging system that the applications interact with via their watermark components.
- If applicable, you may include the “kv.sqlite” file as an indicator of lightweight, embedded persistence used by the change source.

##### Relationships and Interactions
- From external client calls (or even @rocicorp/zero itself) to the NestJS-based custom change sources.

##### Architectural Patterns & Design Principles
- It leverages a microservice/component-like approach even within a monorepo. Emphasize the separation between custom change sources (apps) and shared libraries (libs).
- Emphasis on configuration and extensibility, which might be illustrated by showing how common configuration files (YAML, tsconfig, etc.) support multiple modules.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External Client
    C1("Client (@rocicorp)"):::client

    %% Custom Change Sources (NestJS Applications)
    subgraph "Custom Change Sources (NestJS Applications)"
        A1("Health Check Module"):::app
        A2("Watermark Module (NATS)"):::app
        A3("Watermark Module (Zqlite)"):::app
        A4("Zero Module"):::app
    end

    %% Shared Libraries
    subgraph "Shared Libraries"
        L1("ESLint Config"):::lib
        L2("TSConfig"):::lib
        L3("Zero-Nest-Mongoose Library"):::lib
    end

    %% External Systems & Infrastructure
    subgraph "External Systems"
        E1("Docker (NATS Config)"):::external
        E2("NATS Messaging Service"):::external
        E3("KV.sqlite Persistence"):::external
    end

    %% Connections from External Client to App
    C1 -->|"API_Call"| A1

    %% Intra-App relationships
    A1 -->|"Service_Call"| A4

    %% Interaction with external systems
    A2 -->|"MessagingEvent"| E2
    A3 -->|"PersistenceQuery"| E3

    %% Integration with Shared Libraries
    A1 -->|"TSConfigImport"| L2
    A2 -->|"LintConfigImport"| L1
    A4 -->|"SchemaIntegration"| L3

    %% External infrastructure deployment connection
    E1 -->|"DeployConfig"| E2

    %% Click Events
    click A1 "https://github.com/cbnsndwch/zero-sources/tree/main/apps/source-mongodb/src/features/healthz"
    click A2 "https://github.com/cbnsndwch/zero-sources/tree/main/apps/source-mongodb/src/features/watermark/nats"
    click A3 "https://github.com/cbnsndwch/zero-sources/tree/main/apps/source-mongodb/src/features/watermark/zqlite"
    click A4 "https://github.com/cbnsndwch/zero-sources/tree/main/apps/source-mongodb/src/features/zero"
    click L1 "https://github.com/cbnsndwch/zero-sources/tree/main/libs/eslint-config"
    click L2 "https://github.com/cbnsndwch/zero-sources/tree/main/libs/tsconfig"
    click L3 "https://github.com/cbnsndwch/zero-sources/tree/main/libs/zero-nest-mongoose"
    click E1 "https://github.com/cbnsndwch/zero-sources/tree/main/.docker/nats"
    click E3 "https://github.com/cbnsndwch/zero-sources/blob/main/apps/source-mongodb/kv.sqlite"
    click C1 "https://github.com/cbnsndwch/zero-sources/tree/main/apps/source-mongodb"

    %% Styles
    classDef app fill:#E3F2FD,stroke:#1E88E5,stroke-width:2px;
    classDef lib fill:#E8F5E9,stroke:#43A047,stroke-width:2px;
    classDef external fill:#FFEBEE,stroke:#E53935,stroke-width:2px;
    classDef client fill:#FFF3E0,stroke:#FB8C00,stroke-width:2px;
```
