# base/chains architecture

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

- Interactive diagram: https://gitdiagram.com/base/chains
- Repository: https://github.com/base/chains

## Overview

##### Project Type and Purpose
- It is organized as a collection of Gradle sub-projects:
- model: defines domain objects (Chain, Explorer, NativeCurrency)
- processor: validates JSON files against the domain model and constraints, then composes aggregate outputs
- tools: Node.js scripts for ancillary tasks (schema checking, cleanup)
- website (static site not shown but implied by directory)

##### File Structure Analysis
- Top-level directories:
- httpsloader, model, processor: three Kotlin/Gradle modules following a pipeline
- tools: Node.js utility scripts and JSON schemas
- ci/.github: CI/CD configuration (GitHub Actions)
- gradle/…: build system
- The processor module contains:
- src/main: core validation and aggregation logic
- src/test: unit tests covering invalid and valid scenarios
- README specifies constraints, example JSON, aggregation outputs, and usage contexts
- CI pipelines run ‘./gradlew run’, schema checks, formatting, and on success deploy outputs

##### Main Components and Their Interactions
a. Data Sources (raw):
- _data/chains/*.json – individual chain definitions
b. HTTPS/IPFS Loader (httpsloader):
- Ensures that assets are reachable and cached if necessary
c. Domain Model (model):
- Kotlin data classes: Chain, Explorer, NativeCurrency
- Shared by loader and processor for serialization/deserialization
d. Processor (processor):
- Reads raw JSON via model
- Emits aggregate JSON outputs: chains.json, chains_mini.json
- Runs unit tests to guard invalid cases
e. Tools (Node scripts + schemas):
- schema/chainSchema.json – formal JSON Schema definitions
- schemaCheck.js – validates files against schema before Gradle tasks
- rmNetwork.js, package.json – other maintenance tasks
f. CI/CD (GitHub Actions):
- build.yml – compiles modules, runs validation
- deploy.yml – publishes aggregated outputs to chainid.network or npm
- pr_checks.yml, prettier.yml, validate_json.yml – maintain quality

##### Architectural Patterns and Principles
- Modular architecture: clear separation into “loader”, “domain model”, “processor”, and “tools”
- Pipeline pattern: raw data → loader → model → processor → published outputs
- Test-driven validation: exhaustive unit tests for invalid/legal cases in processor
- CI-oriented: automated checks and deployment on each PR
- Data-centric: focus on JSON schemas and domain integrity

##### Essential Elements
- Data ingestion (raw JSON → modules)
- Validation loops (processor ↔ tests; tools ↔ schema)
- Deployment (processor → published outputs → consumers)

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Data Sources"
        DC["_data/chains"]:::data
        DI["_data/icons"]:::data
    end

    subgraph "External Dependencies"
        IPFS["IPFS Gateway"]:::external
        HTTP["HTTPS Endpoints"]:::external
    end

    subgraph "Internal Modules"
        subgraph "HTTPS/IPFS Loader"
            Loader["httpsloader"]:::internal
        end
        subgraph "Domain Model"
            Model["model"]:::internal
        end
        subgraph "Processor"
            Processor["processor"]:::internal
        end
        subgraph "Tools"
            Tools["tools"]:::internal
            ToolsSchema["tools/schema"]:::data
        end
    end

    subgraph "CI/CD"
        CI["CI/CD (GitHub Actions)"]:::ci
    end

    subgraph "Outputs & Consumers"
        Outputs["Published JSON\n(chains.json, chains_mini.json)"]:::data
        Consumers["Consumers\n(wallets, explorers)"]:::external
    end

    DC --> Loader
    DI --> Loader
    IPFS --> Loader
    HTTP --> Loader
    Loader --> Model
    Model --> Processor
    ToolsSchema --> Tools
    Tools --> Processor
    Processor --> Outputs
    Outputs --> Consumers
    CI --> Loader
    CI --> Processor
    CI --> Tools

    click DC "https://github.com/base/chains/tree/master/_data/chains/"
    click DI "https://github.com/base/chains/tree/master/_data/icons/"
    click Loader "https://github.com/base/chains/tree/master/httpsloader/"
    click Model "https://github.com/base/chains/tree/master/model/"
    click Processor "https://github.com/base/chains/tree/master/processor/"
    click Tools "https://github.com/base/chains/tree/master/tools/"
    click ToolsSchema "https://github.com/base/chains/tree/master/tools/schema/"

    classDef internal fill:#cce5ff,stroke:#004085,color:#004085
    classDef data fill:#d4edda,stroke:#155724,color:#155724
    classDef external fill:#fff3cd,stroke:#856404,color:#856404
    classDef ci fill:#e2e3e5,stroke:#6c757d,color:#6c757d
```
