# heqingpan/rnacos architecture

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

- Interactive diagram: https://gitdiagram.com/heqingpan/rnacos
- Repository: https://github.com/heqingpan/rnacos

## Overview

##### Main Components
- API Gateways:
– HTTP server: Exposes the RESTful APIs including configuration and naming APIs.
– GRPC server: Serves gRPC requests (for 2.x protocol support including instance notifications, heartbeats, etc.).
- Management Console:
– A dedicated service (runs on its own port, as seen from the README and the src/console modules) and is implemented as a separate front‑end/back‑end (with static resources integrated via Cargo).
- Core Modules:
– Config Center: Handles configuration management (create, update, history, import/export) and its persistence.
– Naming/Service Registry: Manages service instances, registration, discovery, and heartbeat mechanisms.
– Raft & Distributed Storage: Provides clustering and high availability via the raft protocol recoded in modules under src/raft (and related file storage, snapshotting, and network components).
– OpenAPI Layer: Exposes endpoints for third‑party clients and integrations.
– Metrics & Health: Modules under src/metrics, src/health that collect, expose, and log performance and system health data.
- Utility and Supporting Modules:
– Common utilities (logging, error handling, cryptography, web utilities in src/common).
– Namespace management, user/permission management (important for the console and security).
– Transfer modules (data migration/backup, e.g., from SQLite/MySQL).

##### Relationships and Interactions
- Clients (SDKs in various languages, HTTP REST clients, gRPC clients) interact with the API Gateway.
- The API Gateway (HTTP and GRPC endpoints) routes requests to the respective core business logic (config center, naming center).
- The Management Console interacts with the API layer to allow administrators to manage users, services, configurations, and view metrics.
- The underlying cluster nodes communicate using Raft. They exchange state information and maintain consensus on configuration/naming updates.
- Persistence is maintained locally (using file storage) in each node, and the raft module ensures these are consistent across nodes.
- Health and metrics modules continuously monitor the runtime performance and provide aggregator endpoints.

##### Architectural Patterns and Important Technologies
- Microkernel/Modular Design: The project is segregated into modules (config, naming, raft, console, openapi, etc.) that interact through clearly defined APIs.
- Distributed Consensus: Raft protocol is employed to handle cluster coordination without an external database.
- API Gateway Pattern: Separate HTTP and gRPC endpoints facilitate protocol-specific client communications.
- Containerization/Deployment: Supporting Docker, docker-compose, and Helm K8s deployment indicates cloud-native and containerized design approaches.
- Use of Rust’s module system to enforce clean separation of concerns.
- Support for plugins or SDK integration points, as exemplified by the sdk‑examples directory.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External Clients
    subgraph "External Clients"
        Clients("SDKs/HTTP/gRPC Clients"):::external
        LoadTesting("LoadTestingTools"):::external
    end

    %% API Gateway Layer
    subgraph "API Gateway Layer"
        HTTP("HTTP API Server"):::service
        GRPC("gRPC Server"):::service
    end

    %% Management Console
    subgraph "Management Console"
        Console("Management Console"):::console
    end

    %% Core Business Modules
    subgraph "Core Business Modules"
        Config("Config Center"):::core
        Naming("Naming/Service Registry"):::core
        Raft("Raft & Distributed Storage"):::core
        Metrics("Metrics Module"):::core
        Health("Health Module"):::core
        Namespace("Namespace Management"):::core
        Transfer("Data Transfer/Backup Modules"):::core
        Utilities("Common Utilities"):::core
    end

    %% Deployment Infrastructure
    subgraph "Deployment Infrastructure"
        Docker("Docker/K8s Container Deployment"):::deployment
    end

    %% Connections from External Clients to API Gateway
    Clients -->|"HTTP/gRPCRequest"| HTTP
    Clients -->|"HTTP/gRPCRequest"| GRPC
    LoadTesting -->|"LoadTestRequests"| HTTP

    %% API Gateway routing to Core Business Modules
    HTTP -->|"handle config"| Config
    HTTP -->|"handle naming"| Naming
    HTTP -->|"cluster update"| Raft
    HTTP -->|"report metrics"| Metrics
    HTTP -->|"healthcheck"| Health
    HTTP -->|"namespace ops"| Namespace
    HTTP -->|"data backup"| Transfer
    HTTP -->|"common utilities"| Utilities

    GRPC -->|"naming/heartbeat"| Naming
    GRPC -->|"health ping"| Health

    %% Management Console interactions
    Console -->|"admin API calls"| HTTP
    Console -->|"view metrics"| Metrics
    Console -->|"manage config/naming"| Config
    Console -->|"manage config/naming"| Naming

    %% Internal Raft Cluster Communication
    Raft <-->|"consensus"| Raft

    %% Deployment - Containerization of components
    Docker -->|"deploys"| HTTP
    Docker -->|"deploys"| GRPC
    Docker -->|"deploys"| Console
    Docker -->|"deploys"| Config
    Docker -->|"deploys"| Naming
    Docker -->|"deploys"| Raft
    Docker -->|"deploys"| Metrics
    Docker -->|"deploys"| Health
    Docker -->|"deploys"| Namespace
    Docker -->|"deploys"| Transfer
    Docker -->|"deploys"| Utilities

    %% Styles
    classDef external fill:#FFEEAD,stroke:#BB8F00,stroke-width:2px;
    classDef service fill:#AED6F1,stroke:#1B4F72,stroke-width:2px;
    classDef console fill:#F5B7B1,stroke:#943126,stroke-width:2px;
    classDef core fill:#C3E6CB,stroke:#155724,stroke-width:2px;
    classDef deployment fill:#FADBD8,stroke:#C0392B,stroke-width:2px;

    %% Click Events for Component Mapping
    click HTTP "https://github.com/heqingpan/rnacos/tree/master/src/openapi"
    click GRPC "https://github.com/heqingpan/rnacos/blob/master/src/grpc/server.rs"
    click Console "https://github.com/heqingpan/rnacos/tree/master/src/console"
    click Config "https://github.com/heqingpan/rnacos/tree/master/src/config"
    click Naming "https://github.com/heqingpan/rnacos/tree/master/src/naming"
    click Raft "https://github.com/heqingpan/rnacos/tree/master/src/raft"
    click Metrics "https://github.com/heqingpan/rnacos/tree/master/src/metrics"
    click Health "https://github.com/heqingpan/rnacos/tree/master/src/health"
    click Utilities "https://github.com/heqingpan/rnacos/tree/master/src/common"
    click Namespace "https://github.com/heqingpan/rnacos/tree/master/src/namespace"
    click Transfer "https://github.com/heqingpan/rnacos/tree/master/src/transfer"
```
