# zingolabs/zingolib architecture

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

- Interactive diagram: https://gitdiagram.com/zingolabs/zingolib
- Repository: https://github.com/zingolabs/zingolib

## Overview

##### Core Components
- Zingolib (Core Library)
- Zingo CLI (Command-line Interface)
- Lightwalletd Connection Layer
- Wallet Management System
- Transaction Processing System
- Synchronization System

##### External Dependencies
- Zcashd Node
- Lightwalletd Server
- Gemini Exchange (for price information)

##### Main Layers (Top to Bottom)

a. Client Interface Layer:
- Zingo CLI (zingocli/)
- API Interface (zingolib/src/lib.rs)
- Configuration Management (zingoconfig/)

b. Core Processing Layer:
- Wallet Management (zingolib/src/wallet/)
- Transaction Processing (zingolib/src/commands/)
- Key Management (zingolib/src/wallet/keys/)
- Management (zingolib/src/wallet/notes/)

c. Synchronization Layer:
- Block Sync (zingo-sync/)
- Transaction Sync
- Witness Tree Management (zingolib/src/data/witness_trees/)

d. Network Layer:
- GRPC Connector (zingolib/src/grpc_connector.rs)
- Network Utilities (zingo-netutils/)

- Bidirectional communication between Lightwalletd and the Network Layer
- Data flow from Network Layer through Sync Layer to Core Processing
- User interaction flow from CLI through Core Processing to Network Layer

##### Storage Components
- Wallet Data Storage
- Transaction Cache
- Witness Trees
- Configuration Storage

##### Special Features to Highlight
- Automatic Note Management
- Shielded Transaction Processing
- Multi-address Transaction Support
- Automatic Sapling Funds Shielding

Implementation Details:

##### Important subsystems
- Testing framework (darkside-tests/)
- Configuration management
- Error handling
- Logging system

##### Integration points
- Zcash network connection
- Lightwalletd server interface
- Price information retrieval
- Wallet backup/restore functionality

Remember to emphasize the privacy and security aspects of the system, as these are crucial features of a cryptocurrency wallet. Include notes about where sensitive operations occur and how data is protected throughout the system.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Define styles
    classDef interface fill:#90EE90,stroke:#333,stroke-width:2px
    classDef core fill:#ADD8E6,stroke:#333,stroke-width:2px
    classDef network fill:#FFD700,stroke:#333,stroke-width:2px
    classDef storage fill:#DDA0DD,stroke:#333,stroke-width:2px
    classDef external fill:#FF6B6B,stroke:#333,stroke-width:2px

    %% Client Interface Layer
    subgraph ClientLayer
        CLI["Zingo CLI"]
        API["API Interface"]
        Config["Configuration Management"]
    end

    %% Core Processing Layer
    subgraph CoreLayer
        WalletMgmt["Wallet Management"]
        KeyMgmt["Key Management"]
        NoteMgmt["Note Management"]
        TxProc["Transaction Processing"]
        LightClient["Lightclient Implementation"]
        TxProposal["Transaction Proposal"]
        TxSend["Transaction Sending"]
    end

    %% Synchronization Layer
    subgraph SyncLayer
        BlockSync["Block Sync"]
        TxSync["Transaction Sync"]
        WitnessMgmt["Witness Management"]
    end

    %% Network Layer
    subgraph NetworkLayer
        GRPC["GRPC Connector"]
        NetUtils["Network Utilities"]
    end

    %% Storage Components
    subgraph Storage
        WalletStore[(Wallet Data)]
        TxCache[(Transaction Cache)]
        WitnessTree[(Witness Trees)]
        ConfigStore[(Config Storage)]
    end

    %% External Services
    subgraph External
        Lightwalletd{{"Lightwalletd Server"}}
        Zcashd{{"Zcashd Node"}}
        Gemini{{"Gemini Exchange"}}
    end

    %% Connections
    CLI --> API
    API --> WalletMgmt
    Config --> ConfigStore
    
    WalletMgmt --> KeyMgmt
    WalletMgmt --> NoteMgmt
    WalletMgmt --> TxProc
    
    TxProc --> TxProposal
    TxProposal --> TxSend
    TxSend --> GRPC
    
    BlockSync --> WitnessMgmt
    TxSync --> WalletMgmt
    
    GRPC --> Lightwalletd
    Lightwalletd --> Zcashd
    NetUtils --> Gemini
    
    WalletMgmt --> WalletStore
    TxProc --> TxCache
    WitnessMgmt --> WitnessTree
    
    %% Click events
    click CLI "https://github.com/zingolabs/zingolib/blob/dev/zingocli/src/main.rs"
    click API "https://github.com/zingolabs/zingolib/blob/dev/zingolib/src/lib.rs"
    click Config "https://github.com/zingolabs/zingolib/tree/dev/zingoconfig/"
    click WalletMgmt "https://github.com/zingolabs/zingolib/tree/dev/zingolib/src/wallet/"
    click KeyMgmt "https://github.com/zingolabs/zingolib/tree/dev/zingolib/src/wallet/keys/"
    click NoteMgmt "https://github.com/zingolabs/zingolib/tree/dev/zingolib/src/wallet/notes/"
    click TxProc "https://github.com/zingolabs/zingolib/tree/dev/zingolib/src/commands/"
    click BlockSync "https://github.com/zingolabs/zingolib/tree/dev/zingo-sync/src/sync/"
    click TxSync "https://github.com/zingolabs/zingolib/blob/dev/zingo-sync/src/scan/transactions.rs"
    click WitnessMgmt "https://github.com/zingolabs/zingolib/blob/dev/zingo-sync/src/witness.rs"
    click GRPC "https://github.com/zingolabs/zingolib/blob/dev/zingolib/src/grpc_connector.rs"
    click NetUtils "https://github.com/zingolabs/zingolib/blob/dev/zingo-netutils/src/lib.rs"
    click WitnessTree "https://github.com/zingolabs/zingolib/tree/dev/zingolib/src/data/witness_trees/"
    click LightClient "https://github.com/zingolabs/zingolib/tree/dev/zingolib/src/lightclient/"
    click TxProposal "https://github.com/zingolabs/zingolib/blob/dev/zingolib/src/wallet/propose.rs"
    click TxSend "https://github.com/zingolabs/zingolib/blob/dev/zingolib/src/wallet/send.rs"

    %% Legend
    subgraph Legend
        UI["User Interface"]:::interface
        Core["Core Processing"]:::core
        Net["Network Component"]:::network
        Store["Storage"]:::storage
        Ext["External Service"]:::external
    end

    %% Apply styles
    class CLI,API,Config interface
    class WalletMgmt,KeyMgmt,NoteMgmt,TxProc,LightClient,TxProposal,TxSend core
    class GRPC,NetUtils network
    class WalletStore,TxCache,WitnessTree,ConfigStore storage
    class Lightwalletd,Zcashd,Gemini external
```
