# pragalbhmandaokar/finance-supply-chain-3rd-blockchain architecture

> Architecture diagram of the GitHub repository pragalbhmandaokar/finance-supply-chain-3rd-blockchain, 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/pragalbhmandaokar/finance-supply-chain-3rd-blockchain
- Repository: https://github.com/pragalbhmandaokar/finance-supply-chain-3rd-blockchain

## Overview

##### Project Type and Purpose
- This is a blockchain-integrated full-stack application for finance supply chain management. The README highlights a Hardhat use case for developing and deploying smart contracts. The project incorporates blockchain logic (via Hardhat and chaincode scripts) alongside typical application backend code, suggesting a hybrid architecture that deals with both conventional REST API logic and blockchain-based ledger operations.

##### Analyzing the File Structure
- The top-level structure shows several major directories:
- app – Contains application code such as utilities, controllers, services, routers, models, and configuration files. This layer implements the business logic (e.g., BankController, CompanyController, FinanceController, InvoiceController) and handles inbound API requests.
- blockchain – Holds Hardhat configurations, deployment scripts, contract artifacts, and other blockchain-specific utilities. It’s where smart contracts are compiled, deployed, and interacted with.
- hyperleader – Appears to extend the blockchain functionality with components like chaincode, smart contract interactions, and even wallet integrations (e.g., Bank and Finance directories, chaincode libraries). This layer might be used for a Hyperledger Fabric style network integration alongside Ethereum-based components.
- company-wallet – Stores wallet IDs that likely correspond to individual identities interacting with the blockchain network.
- dist and server.js – Represent the deployment/build outputs and the main server entry point, indicating how the backend is packaged and run.
- Notice configuration files (in app/config and hyperleader/config) that include connection profiles and export configurations which are critical for establishing connectivity with blockchain networks.

##### Key Architecture Components
a. Frontend / Client Layer (not explicitly shown, but consider external clients or web UIs connecting via APIs).
b. Application/API Server:
- Modules like Controllers, Services, Routers, Models, and Utilities (from the app directory).
- The controllers and routers handle incoming HTTP requests; services (e.g., bank_service, finance_service, etc.) encapsulate business logic; models represent data entities.
c. Blockchain Integration Layer:
- A dedicated blockchain layer that involves the “blockchain” directory (with Hardhat, contract artifacts, and deployment scripts) to represent the smart contract development environment.
- Separate chain components (e.g., BankChain, CompanyChain, FinanceChain, InvoiceChain from app/blockchainservice) to indicate distinct smart contract interactions.
d. Hyperledger / Advanced Blockchain Components:
- “hyperleader” directory elements which include chaincode, financial modules, and additional contract libraries (e.g., CompanyContract, FinancialContract). This may suggest an integration with a Fabric-based network or an enhanced blockchain network that coexists with the Hardhat-based contracts.
e. Wallet and Identity Management:
f. Database/Storage:
- Although not extensively elaborated, files like database.js and mongo_service.js in the app/service and app/config directories indicate a persistence layer (possibly MongoDB or another DB) that tracks application state or transaction histories.

##### Relationships and Interactions
- Inside the application server, map the flow from Routers → Controllers → Services.
- Have services interact in two key ways:
- With the database layer (for data persistence and retrieval).
- With the blockchain integration layer, invoking smart contract methods via blockchain service modules.
- From the blockchain layer, illustrate bidirectional interactions where deployment scripts (via Hardhat or Hyperledger chaincode modules) send contract transactions and receive responses.
- Configuration modules providing connection profiles to the blockchain and potentially to the Hyperledger components.

##### Architectural Patterns and Technologies
- Separation of Concerns: Clearly divide the system into an API layer (app/) and a blockchain integration layer (blockchain/ and hyperleader/).
- Microservices/Modularization: The separation into different chain modules (BankChain, CompanyChain, etc.) and service modules indicates a modular design.
- Use of Hardhat for contract compilation and deployment, and additional blockchain scripts to interact with contracts.
- Frameworks/Libraries: Hardhat, potential Node.js libraries for service location (app/lib/service_locator.js), and smart contract libraries in hyperleader.

## Diagram (Mermaid)

```mermaid
graph TD
    %% Client Layer
    Client["External Client"]:::client

    %% Application/API Server Layer
    subgraph "Application/API Server"
        API_Core["API Server & Business Logic"]:::business
        Router["API Router"]:::business
        Controller["API Controller"]:::business
        Service["API Service"]:::business
        Config["Configuration"]:::business
    end

    %% Database/Storage Layer
    subgraph "Database/Storage"
        DB_Config["Database Config"]:::db
        Mongo_Service["Mongo Service"]:::db
    end

    %% Blockchain Integration Layer (Hardhat)
    subgraph "Blockchain Integration (Hardhat)"
        Blockchain["Smart Contracts & Deployment Scripts"]:::blockchain
    end

    %% Advanced Blockchain (Hyperledger)
    subgraph "Advanced Blockchain (Hyperledger)"
        Chaincode["Chaincode & Contract Libraries"]:::hyperledger
        BankModule["Bank Module"]:::hyperledger
        FinanceModule["Finance Module"]:::hyperledger
    end

    %% Wallet and Identity Management
    Wallet["Wallet Manager"]:::blockchain

    %% Relationships
    Client -->|"API_request"| Router
    Router -->|"routes_to"| Controller
    Controller -->|"calls"| Service
    API_Core --> Router
    API_Core --> Controller
    API_Core --> Service
    Service -->|"persist_data"| DB_Config
    Service -->|"persist_data"| Mongo_Service
    Service -->|"invokes_contract"| Blockchain
    Service -->|"invokes_chaincode"| Chaincode
    Service -->|"verifies_id"| Wallet
    Config -->|"provides_settings"| Blockchain
    Config -->|"provides_settings"| Chaincode
    Blockchain <-->|"syncs_with"| Chaincode
    Chaincode -->|"accesses_module"| BankModule
    Chaincode -->|"accesses_module"| FinanceModule

    %% Click Events
    click API_Core "https://github.com/pragalbhmandaokar/finance-supply-chain-3rd-blockchain/tree/main/app"
    click Blockchain "https://github.com/pragalbhmandaokar/finance-supply-chain-3rd-blockchain/tree/main/blockchain"
    click Chaincode "https://github.com/pragalbhmandaokar/finance-supply-chain-3rd-blockchain/tree/main/hyperleader"
    click Wallet "https://github.com/pragalbhmandaokar/finance-supply-chain-3rd-blockchain/tree/main/company-wallet"
    click DB_Config "https://github.com/pragalbhmandaokar/finance-supply-chain-3rd-blockchain/blob/main/app/config/database.js"
    click Mongo_Service "https://github.com/pragalbhmandaokar/finance-supply-chain-3rd-blockchain/blob/main/app/service/mongo_service.js"

    %% Styles
    classDef business fill:#add8e6,stroke:#00008b,stroke-width:2px;
    classDef blockchain fill:#90ee90,stroke:#006400,stroke-width:2px;
    classDef hyperledger fill:#ffb6c1,stroke:#dc143c,stroke-width:2px;
    classDef db fill:#fffacd,stroke:#daa520,stroke-width:2px;
    classDef client fill:#d3d3d3,stroke:#696969,stroke-width:2px;
```
