# bitcoin-computer/monorepo architecture

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

- Interactive diagram: https://gitdiagram.com/bitcoin-computer/monorepo
- Repository: https://github.com/bitcoin-computer/monorepo

## Overview

##### Main Components
- Core Modules: At the heart of the system are libraries and core modules that power smart contract functionality. For example, the “Lib” package is a JavaScript library for smart contracts, “Node” provides the server-side infrastructure, and “NakamotoJS” handles transaction parsing and building.
- Standard Contract Implementations: These include packages like “TBC20” (fungible token standard), “TBC721” (non-fungible token standard), and “Swap” (for swap/sale contracts). These are key for enabling different smart contract standards.
- Applications: There are several client-facing and service applications. For instance, “Wallet,” “Explorer,” “Chat,” “NFT,” and even “Chess App”—each of these has its own frontend code (often built with React or similar frameworks, as indicated by files like App.tsx, index.html, and vite.config.ts) that interacts with the underlying smart contract logic.
- Additional Components: There are also packages for components (reusable UI elements), templates (for Node.js and React), documentation (“Docs” and “Website”), and even a “node” package to set up chains (support for Bitcoin, BCH, DOGE, LTC, etc.) with corresponding configuration files.
- Infrastructure & DevOps: Note the presence of Dockerfiles, GitHub workflows, husky hooks, and Turbo configuration files that indicate CI/CD, testing, and deployment processes.

##### Out Relationships
- Standard contract packages (TBC20, TBC721, Swap) sit on top of the core modules. They implement specific token standards by leveraging functions from the core libraries.
- The “Components” package, along with documentation (“Docs” and “Website”), serves as supporting layers—for example, reusing UI components across several apps or providing developer/user guides.
- Infrastructure components like the “node” package (and its chain-setup directories) link the on-chain and off-chain worlds. They configure connections with Bitcoin, Litecoin, and other blockchain networks; these should be depicted as external systems that the smart contract engine (via Node) communicates with.

##### Architectural Patterns & Design Principles
- Modularity and Separation of Concerns: The monorepo neatly separates core logic, contract standards, user interfaces, and utility components. Visually emphasize separate modules or layers.
- Reusability and Extensibility: For instance, the “Components” package and templates indicate that there’s a reusable design pattern across apps.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Backend & Core Layer
    subgraph "Backend & Core"
        Lib["Lib – Smart Contract Library"]
        Node["Node – Server-Side Infrastructure"]
        NakamotoJS["NakamotoJS – Transaction Parser/Builder"]
    end

    %% Standard Contracts
    subgraph "Standard Contracts"
        TBC20["TBC20 – Fungible Token Standard"]
        TBC721["TBC721 – Non-Fungible Token Standard"]
        Swap["Swap – Swap/Sale Contract"]
    end

    %% Applications Layer
    subgraph "Applications"
        Wallet["Wallet – Application Frontend"]
        Explorer["Explorer – Blockchain Explorer"]
        Chat["Chat – Application Interface"]
        NFT["NFT – NFT App"]
        ChessApp["Chess App – Chess Game"]
    end

    %% UI/Presentation Layer
    subgraph "UI/Presentation"
        Components["Components – Reusable UI Elements"]
        NodejsTemplate["Node.js Template"]
        ViteTemplate["Vite Template – React/Vite App"]
        Docs["Docs – Documentation"]
        Website["Website – Developer/User Facing"]
    end

    %% DevOps & Infrastructure Layer
    subgraph "DevOps & Infrastructure"
        GitHubWorkflows["GitHub Workflows"]
        DockerMain["Dockerfile"]
        ChessDocker["Chess Server Dockerfile"]
        Turbo["Turbo Config"]
    end

    %% External Blockchain Networks
    Blockchain["Blockchain Networks"]

    %% Connections between Core and Contracts
    Lib -->|"supports"| TBC20
    Lib -->|"supports"| TBC721
    Lib -->|"supports"| Swap

    Node -->|"integrates"| Lib
    Node -->|"processes"| NakamotoJS

    %% Connections from Applications to Core
    Wallet -->|"interacts"| Node
    Explorer -->|"interacts"| Node
    Chat -->|"interacts"| Node
    NFT -->|"interacts"| Node
    ChessApp -->|"interacts"| Node

    %% Connections from Applications to UI/Presentation
    Wallet -->|"utilizes"| Components
    Explorer -->|"utilizes"| Components
    Chat -->|"utilizes"| Components
    NFT -->|"utilizes"| Components
    ChessApp -->|"utilizes"| Components

    NodejsTemplate -->|"provides"| Node
    ViteTemplate -->|"provides"| Wallet

    Docs -->|"guides"| Wallet
    Docs -->|"guides"| Explorer
    Docs -->|"guides"| Chat
    Docs -->|"guides"| NFT
    Docs -->|"guides"| ChessApp

    Website -->|"presents"| Wallet
    Website -->|"presents"| Explorer
    Website -->|"presents"| Chat
    Website -->|"presents"| NFT
    Website -->|"presents"| ChessApp

    %% Communication with Blockchain Networks
    Node <-->|"communicates"| Blockchain

    %% DevOps Automations
    GitHubWorkflows -->|"automates"| Node
    DockerMain -->|"containers"| Node
    ChessDocker -->|"containers"| Node
    Turbo -->|"manages"| Node

    GitHubWorkflows -->|"automates"| Wallet
    GitHubWorkflows -->|"automates"| Explorer
    GitHubWorkflows -->|"automates"| Chat
    GitHubWorkflows -->|"automates"| NFT
    GitHubWorkflows -->|"automates"| ChessApp
    DockerMain -->|"supports"| Wallet
    DockerMain -->|"supports"| Explorer
    DockerMain -->|"supports"| Chat
    DockerMain -->|"supports"| NFT
    DockerMain -->|"supports"| ChessApp
    ChessDocker -->|"supports"| Wallet
    ChessDocker -->|"supports"| Explorer
    ChessDocker -->|"supports"| Chat
    ChessDocker -->|"supports"| NFT
    ChessDocker -->|"supports"| ChessApp
    Turbo -->|"manages"| Wallet
    Turbo -->|"manages"| Explorer
    Turbo -->|"manages"| Chat
    Turbo -->|"manages"| NFT
    Turbo -->|"manages"| ChessApp

    %% Styles
    classDef core fill:#f9f,stroke:#333,stroke-width:2px;
    classDef app fill:#bbf,stroke:#333,stroke-width:2px,rx:5,ry:5;
    classDef ui fill:#bfb,stroke:#333,stroke-width:2px;
    classDef infra fill:#ff9,stroke:#333,stroke-width:2px;
    classDef blockchain fill:#fc9,stroke:#333,stroke-width:2px,stroke-dasharray: 5 5;

    class Lib,Node,NakamotoJS,TBC20,TBC721,Swap core;
    class Wallet,Explorer,Chat,NFT,ChessApp app;
    class Components,NodejsTemplate,ViteTemplate,Docs,Website ui;
    class GitHubWorkflows,DockerMain,ChessDocker,Turbo infra;
    class Blockchain blockchain;

    %% Click Events
    click Lib "https://github.com/bitcoin-computer/monorepo/tree/main/packages/lib"
    click Node "https://github.com/bitcoin-computer/monorepo/tree/main/packages/node"
    click NakamotoJS "https://github.com/bitcoin-computer/monorepo/tree/main/packages/nakamotojs"
    click TBC20 "https://github.com/bitcoin-computer/monorepo/tree/main/packages/TBC20"
    click TBC721 "https://github.com/bitcoin-computer/monorepo/tree/main/packages/TBC721"
    click Swap "https://github.com/bitcoin-computer/monorepo/tree/main/packages/swap"
    click Wallet "https://github.com/bitcoin-computer/monorepo/tree/main/packages/wallet"
    click Explorer "https://github.com/bitcoin-computer/monorepo/tree/main/packages/explorer"
    click Chat "https://github.com/bitcoin-computer/monorepo/tree/main/packages/chat"
    click NFT "https://github.com/bitcoin-computer/monorepo/tree/main/packages/nft"
    click ChessApp "https://github.com/bitcoin-computer/monorepo/tree/main/packages/chess-app"
    click Components "https://github.com/bitcoin-computer/monorepo/tree/main/packages/components"
    click NodejsTemplate "https://github.com/bitcoin-computer/monorepo/tree/main/packages/nodejs-template"
    click ViteTemplate "https://github.com/bitcoin-computer/monorepo/tree/main/packages/vite-template"
    click Docs "https://github.com/bitcoin-computer/monorepo/tree/main/packages/docs"
    click Website "https://github.com/bitcoin-computer/monorepo/tree/main/packages/website"
    click GitHubWorkflows "https://github.com/bitcoin-computer/monorepo/tree/main/.github/workflows"
    click DockerMain "https://github.com/bitcoin-computer/monorepo/tree/main/Dockerfile"
    click ChessDocker "https://github.com/bitcoin-computer/monorepo/tree/main/packages/chess-server/Dockerfile"
    click Turbo "https://github.com/bitcoin-computer/monorepo/blob/main/turbo.json"
```
