# cipher-rc5/echo-client architecture

> Architecture diagram of the GitHub repository cipher-rc5/echo-client, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-02-23). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/cipher-rc5/echo-client
- Repository: https://github.com/cipher-rc5/echo-client

## Overview

##### Main Components
- Entry Point: The src/index.ts file acts as the main application entry point, handling command-line inputs.
- Config Module: Located in src/config, which includes both environment configuration (environment.config.ts) and chain-specific configuration (chains.config.ts).
- Schemas & Types: The src/schemas and src/types directories define application-level contracts. These validate input commands and API responses.
- Service Layer: The src/services directory (specifically dune.service.ts) is critical as it manages communication with the external Dune Analytics API.
- Utility Functions: Found in src/utils, these include logging (logger.ts) and any data filtering (filters.ts), supporting cross-cutting concerns.
- Test Infrastructure: Although not part of production design, the tests/ directory provides context for verifying the behavior of key components.
- External Interface: The Dune Analytics API. This external service is accessed by the dune.service and represents a crucial dependency.

##### Relationships and Data Flow
- That the entry point then routes the process to utilize the Dune service. This service not only interacts with the external Dune Analytics API but may also use schemas to validate the responses.
- That schemas and types act as the contract between incoming command line arguments and the processed API responses.
- From index.ts → config modules (environment and chains).
- From index.ts → schemas transition (validate commands) → types (data structure definitions).
- From index.ts → dune.service.ts (which sends requests to the external API and processes responses via validation).
- From dune.service.ts → external Dune Analytics API.

##### Architectural Patterns and Design Principles
- Modular Design: The separation of configuration, service, schemas, and utilities not only aids in maintainability but also promotes easy extensibility.
- Minimal Dependencies: The modular building blocks work together while relying on a minimal set of external libraries (e.g., Zod for schema validation and Pino for logging).

##### Technology and Framework Details
- Zod: Indicate its use in validating schemas.
- Pino: Highlight its role in logging, which is handled by logger.ts.
- TypeScript: Emphasize that type safety and schema definitions are core to the design.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Configuration"
        EnvironmentConfig["Environment Config (src/config/environment.config.ts)"]
        ChainConfig["Chain Config (src/config/chains.config.ts)"]
    end

    subgraph "Schemas & Types"
        ChainSchema["Chain Validation Schema (src/schemas/chain.schema.ts)"]
        CommandSchema["Command Validation Schema (src/schemas/command.schema.ts)"]
        Types["API/Command Contracts (src/types/api.types.ts & src/types/command.types.ts)"]
    end

    subgraph "Utilities"
        Logger["Logging (src/utils/logger.ts)"]
        Filters["Data Filtering (src/utils/filters.ts)"]
    end

    MainEntry["Main Entry (src/index.ts)"]
    DuneService["Dune Analytics Service (src/services/dune.service.ts)"]
    ExternalAPI["Dune Analytics API"]
    BunRuntime["Bun Runtime/Package Manager"]

    MainEntry -->|"loads"| EnvironmentConfig
    MainEntry -->|"loads"| ChainConfig
    MainEntry -->|"validates"| CommandSchema
    MainEntry -->|"calls"| DuneService
    DuneService -->|"calls"| ExternalAPI
    DuneService -->|"validates"| ChainSchema
    DuneService -->|"uses"| Types
    MainEntry -.->|"runsOn"| BunRuntime
    Logger -.-> MainEntry
    Logger -.-> DuneService
    Filters -.-> DuneService

    click MainEntry "https://github.com/cipher-rc5/echo-client/blob/main/src/index.ts"
    click EnvironmentConfig "https://github.com/cipher-rc5/echo-client/blob/main/src/config/environment.config.ts"
    click ChainConfig "https://github.com/cipher-rc5/echo-client/blob/main/src/config/chains.config.ts"
    click ChainSchema "https://github.com/cipher-rc5/echo-client/blob/main/src/schemas/chain.schema.ts"
    click CommandSchema "https://github.com/cipher-rc5/echo-client/blob/main/src/schemas/command.schema.ts"
    click Types "https://github.com/cipher-rc5/echo-client/blob/main/src/types/api.types.ts & src/types/command.types.ts"
    click DuneService "https://github.com/cipher-rc5/echo-client/blob/main/src/services/dune.service.ts"
    click Logger "https://github.com/cipher-rc5/echo-client/blob/main/src/utils/logger.ts"
    click Filters "https://github.com/cipher-rc5/echo-client/blob/main/src/utils/filters.ts"

    classDef entry fill:#aqua,stroke:#000,stroke-width:2px;
    classDef config fill:#cceecc,stroke:#000,stroke-width:2px;
    classDef schemas fill:#f9e79f,stroke:#000,stroke-width:2px;
    classDef service fill:#f5b7b1,stroke:#000,stroke-width:2px;
    classDef utility fill:#d6eaf8,stroke:#000,stroke-width:2px;
    classDef external fill:#fadbd8,stroke:#000,stroke-width:2px;
    classDef runtime fill:#d7bde2,stroke:#000,stroke-width:2px;

    class MainEntry entry;
    class EnvironmentConfig,ChainConfig config;
    class ChainSchema,CommandSchema,Types schemas;
    class DuneService service;
    class Logger,Filters utility;
    class ExternalAPI external;
    class BunRuntime runtime;
```
