# hyperledger-labs/cc-tools-demo architecture

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

- Interactive diagram: https://gitdiagram.com/hyperledger-labs/cc-tools-demo
- Repository: https://github.com/hyperledger-labs/cc-tools-demo

## Overview

##### Main Components
- Fabric Network: Illustrate the Fabric network environment as the blockchain platform. Note that there are configuration folders (fabric, fabric-private-chaincode) indicating setups for multi-org networks and private chaincode execution.
- Chaincode: Represent the chaincode as the backbone smart-contract layer. There are two main directories:
- The “chaincode” directory with the business logic, transaction definitions, asset types, events, and tests.
- The “ccapi” directory which acts as the gateway/REST API service to interact with the chaincode.
- Chaincode API Server (ccapi): Show this as a separate block that contains sub-components such as the routes, handlers, server, and web client (indicating a possible UI layer).
- Supporting Deployment & Management Scripts: You might include a deployment orchestration layer that shows the scripts (startDev.sh, upgradeCC.sh, generatePackage.sh, etc.) and CI/CD workflows (notably in the .github folder).

##### Relationships and Interactions
- The Fabric Network (block) should display its peers, orderer(s), Certificate Authorities (CAs), and the mechanisms (Docker Compose setups) that launch these components.
- Additionally, if the web-client is part of ccapi, show a directional relationship where an external client (e.g., a web browser or REST client) sends requests to the ccapi service.

##### Architectural Patterns/Technologies
- Microservice-like separation between the Chaincode (smart contract logic) and the REST API service.
- Use of Docker Compose and script automation for environment setup and upgrades.
- Integration with Fabric Private Chaincode for enhanced privacy – this might be indicated as an optional secure execution layer.
- Language and dependencies such as Go for both chaincode and API server, and configuration files for blockchain orchestration.
- Multi-organization capability (1 org for simple testing and 3 orgs for more advanced setups as indicated in the README).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client Tier
    Client["External REST Client/ Web Browser"]:::client

    %% API Tier
    subgraph "API Tier"
        ccapi["Chaincode API Server (ccapi)"]:::ccapi
        routes["REST Routes"]:::ccapi
        handlers["API Handlers"]:::ccapi
        server["Server Setup"]:::ccapi
        webClient["Web Client Interface"]:::ccapi
        sdk["Fabric SDK (fabsdk, gateway)"]:::ccapi
    end

    %% Blockchain Tier
    subgraph "Blockchain Tier"
        fabricNet["Fabric Network Environment"]:::fabric
        chaincode["Chaincode (Smart Contracts)"]:::chaincode
        fabricPvt["Fabric Private Chaincode Integration"]:::fabric
    end

    %% Deployment & Management Tier
    subgraph "Deployment & Management"
        startDev["startDev.sh"]:::deployment
        upgradeCC["upgradeCC.sh"]:::deployment
        generatePkg["generatePackage.sh"]:::deployment
        fabricScripts["Fabric Scripts (fabric/scripts)"]:::deployment
        githubWorkflows["CI/CD Workflows (.github/workflows)"]:::deployment
    end

    %% Connections between tiers
    Client -->|"sendsRequest"| ccapi
    ccapi -->|"processes"| routes
    ccapi -->|"processes"| handlers
    ccapi -->|"processes"| server
    ccapi -->|"processes"| webClient
    ccapi -->|"usesSDK"| sdk
    sdk -->|"invokes"| fabricNet
    fabricNet -->|"executes"| chaincode
    fabricNet -->|"providesResponse"| sdk
    fabricNet ---|"integrates"| fabricPvt

    %% Deployment scripts orchestrating Fabric network
    startDev -->|"orchestrates"| fabricNet
    upgradeCC -->|"orchestrates"| fabricNet
    generatePkg -->|"orchestrates"| fabricNet
    fabricScripts -->|"orchestrates"| fabricNet
    githubWorkflows -->|"manages"| fabricNet
    githubWorkflows -->|"manages"| ccapi

    %% Styles
    classDef client fill:#cce5ff,stroke:#333,stroke-width:2px;
    classDef ccapi fill:#ffd699,stroke:#333,stroke-width:2px;
    classDef fabric fill:#add8e6,stroke:#333,stroke-width:2px;
    classDef chaincode fill:#98fb98,stroke:#333,stroke-width:2px;
    classDef deployment fill:#e6b3ff,stroke:#333,stroke-width:2px;

    %% Click Events
    click fabricNet "https://github.com/hyperledger-labs/cc-tools-demo/tree/main/fabric"
    click fabricPvt "https://github.com/hyperledger-labs/cc-tools-demo/tree/main/fabric-private-chaincode"
    click chaincode "https://github.com/hyperledger-labs/cc-tools-demo/tree/main/chaincode"
    click ccapi "https://github.com/hyperledger-labs/cc-tools-demo/tree/main/ccapi"
    click startDev "https://github.com/hyperledger-labs/cc-tools-demo/blob/main/startDev.sh"
    click upgradeCC "https://github.com/hyperledger-labs/cc-tools-demo/blob/main/upgradeCC.sh"
    click generatePkg "https://github.com/hyperledger-labs/cc-tools-demo/blob/main/generatePackage.sh"
    click fabricScripts "https://github.com/hyperledger-labs/cc-tools-demo/tree/main/fabric/scripts"
    click githubWorkflows "https://github.com/hyperledger-labs/cc-tools-demo/tree/main/.github/workflows"
```
