graph TB
    subgraph Network["Hyperledger Besu Network<br/>QBFT Consensus<br/>4 Validator Nodes"]
        V1["🔐 Validator Node 1<br/>Port: 8545<br/>RPC Endpoint"]
        V2["🔐 Validator Node 2<br/>Port: 8546"]
        V3["🔐 Validator Node 3<br/>Port: 8547"]
        V4["🔐 Validator Node 4<br/>Port: 8548"]
    end

    subgraph SmartContracts["Smart Contracts"]
        LicenseNFT["📋 LicenseRequestNFT<br/>(ERC-721 Soulbound)<br/>• tokenId<br/>• licenseHash<br/>• metadata URI<br/>• issuerDept"]
        ApprovalMgr["✅ ApprovalManager<br/>• recordApproval()<br/>• rejectRequest()<br/>• requestChanges()<br/>• getApprovalChain()"]
        DeptRegistry["🏢 DepartmentRegistry<br/>• registerDept()<br/>• setApprovers()<br/>• getApprovers()<br/>• deptMetadata"]
        WorkflowRegistry["⚙️ WorkflowRegistry<br/>• defineWorkflow()<br/>• getWorkflow()<br/>• workflowStates<br/>• transitions"]
    end

    subgraph OnChain["On-Chain Data"]
        Accounts["💰 Accounts & Balances"]
        NFTState["🎖️ NFT State<br/>tokenId → Owner<br/>tokenId → Metadata"]
        Approvals["✅ Approval Records<br/>licenseHash → ApprovalChain"]
    end

    subgraph OffChain["Off-Chain Data<br/>PostgreSQL + MinIO"]
        DocMeta["📄 Document Metadata<br/>• documentId<br/>• licenseHash<br/>• uploadedBy<br/>• uploadDate<br/>• status"]
        LicenseReq["📋 License Request Details<br/>• requestId<br/>• applicantInfo<br/>• documents<br/>• notes"]
        WorkflowState["⚙️ Workflow State<br/>• currentState<br/>• stateHistory<br/>• timestamps<br/>• transitions"]
        DocFiles["📦 Actual Files<br/>• PDFs (MinIO)<br/>• Images<br/>• Proofs"]
    end

    subgraph DataLink["Data Linking"]
        Hash["🔗 Content Hashing<br/>SHA-256<br/>Document → Hash<br/>Immutable Link"]
    end

    subgraph Consensus["Consensus: QBFT"]
        QBFTInfo["Quorum Byzantine<br/>Fault Tolerant<br/>Requires 3/4 validators<br/>~1 block/12s"]
    end

    V1 -->|Peer Connection| V2
    V1 -->|Peer Connection| V3
    V1 -->|Peer Connection| V4
    V2 -->|Peer Connection| V3
    V2 -->|Peer Connection| V4
    V3 -->|Peer Connection| V4

    V1 -->|Deploy/Call| SmartContracts
    V2 -->|Deploy/Call| SmartContracts
    V3 -->|Deploy/Call| SmartContracts
    V4 -->|Deploy/Call| SmartContracts

    SmartContracts -->|Store State| OnChain
    LicenseNFT -->|Emit Events| OnChain
    ApprovalMgr -->|Record| OnChain
    DeptRegistry -->|Maintain| OnChain
    WorkflowRegistry -->|Track| OnChain

    Hash -->|Link Via Hash| LicenseReq
    Hash -->|Store Hash| OnChain
    DocMeta -->|Contains Hash| Hash
    LicenseReq -->|Store Details| OffChain
    WorkflowState -->|Track Off-Chain| OffChain
    DocFiles -->|Reference Via Hash| OffChain

    Hash -.->|Immutable Anchor| NFTState
    LicenseReq -.->|Linked to NFT| LicenseNFT

    V1 -->|Consensus| Consensus
    V2 -->|Consensus| Consensus
    V3 -->|Consensus| Consensus
    V4 -->|Consensus| Consensus

    style Network fill:#dc2626,stroke:#991b1b,stroke-width:2px,color:#fff
    style SmartContracts fill:#2563eb,stroke:#1e40af,stroke-width:2px,color:#fff
    style OnChain fill:#7c3aed,stroke:#5b21b6,stroke-width:2px,color:#fff
    style OffChain fill:#8b5cf6,stroke:#6d28d9,stroke-width:2px,color:#fff
    style DataLink fill:#06b6d4,stroke:#0891b2,stroke-width:2px,color:#fff
    style Consensus fill:#f59e0b,stroke:#d97706,stroke-width:2px,color:#fff
