# carvajalrjc/boeno-arqui-blockchain architecture

> Architecture diagram of the GitHub repository carvajalrjc/boeno-arqui-blockchain, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-11-28). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/carvajalrjc/boeno-arqui-blockchain
- Repository: https://github.com/carvajalrjc/boeno-arqui-blockchain

## Overview

##### Project Type and Purpose
- This is a full-stack traceability system built on a private Hyperledger Besu blockchain.
- Frontend: React + Vite dashboard for managing providers, products, movements, and token info.
- Backend: Node.js + Express REST API that validates and relays requests to smart contracts via ethers.js.
- Smart Contracts: Solidity contracts (ERC-20 token + business logic) deployed with Hardhat.
- Blockchain: Three-node Besu network using IBFT 2.0 consensus, run via Docker Compose.

##### Key Components
a. User / Browser
b. Frontend application (React + Vite)
c. Backend API server (Node.js + Express)
d. Smart Contract layer (TrazaToken.sol, Trazabilidad.sol)
e. Blockchain network (Besu nodes 1, 2, 3)
f. Utility scripts (Hardhat deploy, seed-data)
g. Container orchestration (Docker Compose)

##### Interactions and Data Flows
- User → Frontend: HTTP(S) via browser (ports 5173).
- Frontend → Backend: REST calls to /api/* (port 3001).
- Backend → Blockchain: JSON-RPC calls through ethers.js to node RPC endpoints (ports 8545-8565).
- Smart Contracts → Blockchain: Deployed bytecode and transaction execution within Besu nodes.
- Besu Node peers: P2P communication under IBFT 2.0 consensus.
- Deployment & Seeding: scripts/deploy/deploy.js runs Hardhat migrations; scripts/seed-data.js populates initial data.

##### Architectural Patterns and Principles
- Layered architecture: Presentation (React), Application (Express REST), Blockchain (EVM contracts).
- Separation of concerns: UI components live in frontend/src; API logic in backend/server.js; contract logic in contracts/.
- Infrastructure as code: Dockerfiles per service + docker-compose.yml + genesis.json + hardhat.config.js.
- Immutable data store: blockchain ensures tamper-proof records.

##### Technologies & Frameworks to Call Out
- React 18 + Vite for fast HMR and development server.
- Node.js + Express for RESTful API and validation.
- Ethers.js for Web3 integration.
- Solidity 0.8.19 + OpenZeppelin ERC-20 for token.
- Hyperledger Besu private network with IBFT 2.0 for consensus.
- Docker & Docker Compose for service orchestration.
- Hardhat for contract compilation, testing, and deployment.

##### Detailed Elements
- Labels on each component (e.g., “React App (5173)”, “Express API (3001)”, “Node1 RPC:8545”).
- Arrowheads indicating call direction and data flow.
- Notes on ports, file locations (e.g., frontend/src, backend/server.js, contracts/).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% User Layer
    User["User / Browser"]:::user

    %% Frontend Layer
    subgraph "Frontend Layer"
        React["React App (5173)"]:::frontend
    end

    %% Backend Layer
    subgraph "Backend Layer"
        Express["Express API (3001)"]:::backend
    end

    %% Smart Contracts Layer
    subgraph "Smart Contracts"
        Contracts["Solidity Contracts"]:::contracts
        HardhatCfg["Hardhat Config"]:::utility
    end

    %% DevOps Scripts
    subgraph "DevOps Scripts"
        Deploy["deploy.js"]:::utility
        Seed["seed-data.js"]:::utility
    end

    %% Private Blockchain Network
    subgraph "Private Blockchain Network"
        direction TB
        Node1["Node1 RPC:8545"]:::block
        Node2["Node2 RPC:8555"]:::block
        Node3["Node3 RPC:8565"]:::block
        Node1 <-->|IBFT 2.0 P2P| Node2
        Node2 <-->|IBFT 2.0 P2P| Node3
        Node1 <-->|IBFT 2.0 P2P| Node3
    end

    %% Container Layer
    subgraph "Container Layer"
        Compose["Docker Compose"]:::infra
        Env[".env"]:::infra
    end

    %% Data Flows
    User -->|HTTP| React
    React -->|REST API| Express
    Express -->|JSON-RPC via ethers.js| Node1
    Express -->|JSON-RPC via ethers.js| Node2
    Express -->|JSON-RPC via ethers.js| Node3
    Deploy -->|Hardhat deploy| Contracts
    Contracts -->|Deployed bytecode| Node1

    %% Click Events
    click React "https://github.com/carvajalrjc/boeno-arqui-blockchain/tree/main/frontend/"
    click Express "https://github.com/carvajalrjc/boeno-arqui-blockchain/blob/main/backend/server.js"
    click Contracts "https://github.com/carvajalrjc/boeno-arqui-blockchain/tree/main/contracts/"
    click HardhatCfg "https://github.com/carvajalrjc/boeno-arqui-blockchain/blob/main/hardhat.config.js"
    click Deploy "https://github.com/carvajalrjc/boeno-arqui-blockchain/blob/main/scripts/deploy/deploy.js"
    click Seed "https://github.com/carvajalrjc/boeno-arqui-blockchain/blob/main/scripts/seed-data.js"
    click Node1 "https://github.com/carvajalrjc/boeno-arqui-blockchain/tree/main/nodes/node1/"
    click Node2 "https://github.com/carvajalrjc/boeno-arqui-blockchain/tree/main/nodes/node2/"
    click Node3 "https://github.com/carvajalrjc/boeno-arqui-blockchain/tree/main/nodes/node3/"
    click Compose "https://github.com/carvajalrjc/boeno-arqui-blockchain/blob/main/docker-compose.yml"
    click Env "https://github.com/carvajalrjc/boeno-arqui-blockchain/blob/main/.env"

    %% Styles
    classDef user fill:#f9f,stroke:#333,color:#000
    classDef frontend fill:#bbdefb,stroke:#0d47a1,color:#000
    classDef backend fill:#c8e6c9,stroke:#1b5e20,color:#000
    classDef contracts fill:#ffe0b2,stroke:#e65100,color:#000
    classDef utility fill:#eeeeee,stroke:#757575,color:#000
    classDef block fill:#e0e0e0,stroke:#424242,color:#000,shape:cylinder
    classDef infra fill:#d1c4e9,stroke:#4527a0,color:#000,shape:cloud
```
