# newham/fabric-iot architecture

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

- Interactive diagram: https://gitdiagram.com/newham/fabric-iot
- Repository: https://github.com/newham/fabric-iot

## Overview

##### Main Components
- Blockchain Network Environment – This encapsulates all the fabric-specific components configured in the “network” directory. It includes:
- Certificate Authorities (CA)
- Orderers and Peers (the blockchain nodes)
- Docker containers launched via numerous docker-compose files (e.g., docker-compose-ca.yaml, docker-compose-cli.yaml, etc.)
- Infrastructure scripts for generating certificates and config artifacts (see crypto-config.yaml, configtx.yaml, and related shell scripts)
- Chaincode (Smart Contracts) – Found in the “chaincode” directory (Golang implementation). This layer implements business logic for access control (multiple modules like AC, DC, M, PC, etc.).
- Client Application – Found in the “client/nodejs” directory. This client is used for enrolling users, invoking smart contracts, and managing interactions with the blockchain.
- Testing and Simulation – Although secondary, the “test” folder indicates components for consensus (Kafka, PoW) and TPS testing, showing experiments to validate performance and consensus mechanisms.

##### Relationships and Interactions
- The blockchain network itself is constructed via Docker containers (as managed in the “network/compose-files” directory). Represent these containers collectively as a “Dockerized Fabric Network” block.

##### Architectural Patterns & Technologies
- Fabric-based Distributed Ledger: Emphasize that the project follows the Hyperledger Fabric architecture including certificate issuance, membership services, channel configuration, and chaincode lifecycles.
- Smart Contract Design: Show that chaincode is modularized (several Go packages for different functions such as access control, policy management, etc.) following a typical chaincode deployment model.
- API & Client Integration: The Node.js client uses the Fabric SDK to interact with the blockchain, making the design clearly a full-stack blockchain application.
- Dockerized Microservices Deployment: The network is set up with Docker-compose files that structure components as individual containers.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Fabric Network Environment Subgraph
    subgraph "Fabric Network Environment"
        %% Deployment & Configuration Subgraph
        subgraph "Deployment & Configuration Scripts"
            bootstrap("bootstrap.sh"):::infra
            ccInstall("cc-install.sh"):::infra
            ccUpgrade("cc-upgrade.sh"):::infra
            ccpGenerate("ccp-generate.sh"):::infra
            down("down.sh"):::infra
            restart("restart.sh"):::infra
            scripts("scripts (script.sh & utils.sh)"):::infra
        end
        networkComponent("Dockerized Fabric Network (CA, Orderers, Peers)"):::infra
    end

    %% Chaincode Subgraph
    subgraph "Chaincode (Smart Contracts in Golang)"
        chaincodeAC("Access Control (AC)"):::chaincode
        chaincodeDC("Device Control (DC)"):::chaincode
        chaincodeM("Module (M)"):::chaincode
        chaincodePC("Policy Control (PC)"):::chaincode
    end

    %% Client Application and Testing/Simulation
    clientApp("Client Application (Node.js)"):::app
    testSim("Testing & Simulation (Consensus, TPS)"):::test

    %% Flow relationships
    bootstrap --> networkComponent
    ccInstall --> networkComponent
    ccUpgrade --> networkComponent
    ccpGenerate --> networkComponent
    down --> networkComponent
    restart --> networkComponent
    scripts --> networkComponent

    networkComponent -->|"deploys"| chaincodeAC
    networkComponent -->|"deploys"| chaincodeDC
    networkComponent -->|"deploys"| chaincodeM
    networkComponent -->|"deploys"| chaincodePC

    clientApp -->|"invokes"| networkComponent
    testSim -->|"simulates"| networkComponent

    %% Click Events
    click networkComponent "https://github.com/newham/fabric-iot/tree/master/network/compose-files"
    click bootstrap "https://github.com/newham/fabric-iot/blob/master/bootstrap.sh"
    click ccInstall "https://github.com/newham/fabric-iot/blob/master/network/cc-install.sh"
    click ccUpgrade "https://github.com/newham/fabric-iot/blob/master/network/cc-upgrade.sh"
    click ccpGenerate "https://github.com/newham/fabric-iot/blob/master/network/ccp-generate.sh"
    click down "https://github.com/newham/fabric-iot/blob/master/network/down.sh"
    click restart "https://github.com/newham/fabric-iot/blob/master/network/restart.sh"
    click scripts "https://github.com/newham/fabric-iot/tree/master/network/scripts"
    click chaincodeAC "https://github.com/newham/fabric-iot/tree/master/chaincode/go/ac"
    click chaincodeDC "https://github.com/newham/fabric-iot/tree/master/chaincode/go/dc"
    click chaincodeM "https://github.com/newham/fabric-iot/tree/master/chaincode/go/m"
    click chaincodePC "https://github.com/newham/fabric-iot/tree/master/chaincode/go/pc"
    click clientApp "https://github.com/newham/fabric-iot/tree/master/client/nodejs"
    click testSim "https://github.com/newham/fabric-iot/tree/master/test"

    %% Styles
    classDef infra fill:#f9e79f,stroke:#d4ac0d,stroke-width:2px;
    classDef chaincode fill:#aed6f1,stroke:#2471a3,stroke-width:2px;
    classDef app fill:#d5f5e3,stroke:#27ae60,stroke-width:2px;
    classDef test fill:#fadbd8,stroke:#c0392b,stroke-width:2px;
```
