# blessnetwork/b7s architecture

> Architecture diagram of the GitHub repository blessnetwork/b7s, 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/blessnetwork/b7s
- Repository: https://github.com/blessnetwork/b7s

## Overview

Below are step-by-step guidelines tailored for this project:

##### Main Components
- API Layer: Represented by the “api” folder, this layer handles external communications (e.g., exposing the REST API, executing commands, health checks, and install commands). Include components such as API endpoints, client interfaces, and any API testing.
- Core Node & Networking: The “node” directory contains the essential components for node operation including head node responsibilities (handling cluster, execution, health, and roll-call) and worker functionalities that process requests. Also include the “host” module that provides discovery, publishing, and subscription mechanisms.
- Executor/Worker: The “executor” folder deals with function execution and process handling. Its design should be shown as a component that receives tasks from the node component.
- Storage & File Store: Include the “fstore” and “store” directories which manage persistent file storage and state/data storage. This covers aspects like deployment records and key management.
- Cryptography: The “crypto” directory provides the certificate and cryptographic functionality vital for secure peer communications.
- Command-line Interfaces: The “cmd” directory contains multiple binaries (e.g., node, manager, keyforge) that serve as entry points for running different roles and tools. These illustrate how operators interact with the daemon.

##### Relationships and Interactions
- API layer interacting with the core node, which in turn coordinates with the consensus module.
- Core node with the worker/executor module to represent the delegation of work.
- Interactions from the core node or consensus modules to the storage layers (“fstore” and “store”) for persisting data reliably.
- Crypto services as foundational, indicating that various components (especially API, host, and consensus) depend on secure certificate and key management functionality.

##### Architectural Patterns and Design Principles
- Modular design – each major folder (API, consensus, node, executor) is a standalone component that integrates through well-defined interfaces.
- Use of microservice-like patterns for commands in the “cmd” directory, separating various concerns (node operations, key management, etc.).
- How consensus patterns (PBFT and Raft) enable fault tolerance and synchronized state across a distributed network.

##### Relevant Technologies and Frameworks
- The project is implemented in Go, so mention Go as the programming language.
- For networking and peer-to-peer communication, highlight libp2p (as implied by the networking flags) as part of the underlying infrastructure.
- The consensus algorithms (PBFT and Raft) themselves are key design parts.
- The usage of Docker is indicated (via the Dockerfile and Docker-related configs), so mention containerization as an optional deployment strategy.
- Testing and integration are supported (integration and testing directories), emphasizing continuous integration practices (GitHub workflows under “.github/workflows”).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External Entity
    ExternalClients["External Clients"]:::external

    %% API Layer
    subgraph "API Layer"
        API["API Endpoints"]:::api
    end

    %% Consensus Module
    subgraph "Consensus Module"
        PBFT["PBFT Module"]:::consensus
        Raft["Raft Module"]:::consensus
    end

    %% Core Node & Networking
    subgraph "Core Node & Networking"
        Head["Head Node"]:::node
        Worker["Worker Node"]:::node
        Host["Host (Discovery/Publisher)"]:::node
    end

    %% Executor/Worker
    subgraph "Executor/Worker"
        Executor["Executor Service"]:::executor
    end

    %% Storage
    subgraph "Storage"
        FStore["File Store"]:::storage
        Store["State Store"]:::storage
    end

    %% Cryptography
    subgraph "Cryptography"
        Crypto["Crypto Services"]:::crypto
    end

    %% Command-line Interfaces
    subgraph "Command-line Interfaces"
        CLI["CLI Tools"]:::cli
    end

    %% Connections
    ExternalClients -->|"calls"| API
    API -->|"processes"| Head
    Head -->|"delegates to"| Worker
    Head -->|"syncs with"| PBFT
    Head -->|"syncs with"| Raft
    Head -->|"delegates tasks"| Executor
    Head -->|"persists to"| FStore
    Head -->|"persists to"| Store
    API -->|"secureComm"| Crypto
    PBFT -->|"validateWith"| Crypto
    Raft -->|"validateWith"| Crypto
    Worker -->|"discoveryVia"| Host
    Host <-->|"p2pComm"| Head
    PBFT -->|"logsTo"| FStore
    Raft -->|"logsTo"| Store
    CLI -->|"commands"| Head

    %% Click Events
    click API "https://github.com/blessnetwork/b7s/tree/main/api/"
    click PBFT "https://github.com/blessnetwork/b7s/tree/main/consensus/pbft/"
    click Raft "https://github.com/blessnetwork/b7s/tree/main/consensus/raft/"
    click Head "https://github.com/blessnetwork/b7s/tree/main/node/"
    click Worker "https://github.com/blessnetwork/b7s/tree/main/node/"
    click Host "https://github.com/blessnetwork/b7s/tree/main/host/"
    click Executor "https://github.com/blessnetwork/b7s/tree/main/executor/"
    click FStore "https://github.com/blessnetwork/b7s/tree/main/fstore/"
    click Store "https://github.com/blessnetwork/b7s/tree/main/store/"
    click Crypto "https://github.com/blessnetwork/b7s/tree/main/crypto/"
    click CLI "https://github.com/blessnetwork/b7s/tree/main/cmd/"

    %% Styles
    classDef external fill:#fefefe,stroke:#333,stroke-width:2px;
    classDef api fill:#cce5ff,stroke:#1a75ff,stroke-width:2px;
    classDef consensus fill:#d1e7dd,stroke:#0f5132,stroke-width:2px;
    classDef node fill:#fff3cd,stroke:#ffc107,stroke-width:2px;
    classDef executor fill:#fde2e2,stroke:#d9534f,stroke-width:2px;
    classDef storage fill:#e2e3e5,stroke:#6c757d,stroke-width:2px;
    classDef crypto fill:#e2f0d9,stroke:#28a745,stroke-width:2px;
    classDef cli fill:#f8d7da,stroke:#dc3545,stroke-width:2px;
```
