# solana-program/token-2022 architecture

> Architecture diagram of the GitHub repository solana-program/token-2022, 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/solana-program/token-2022
- Repository: https://github.com/solana-program/token-2022

## Overview

##### Main Components
- On-Chain Program: Represented by the “program” directory that contains the Solana program’s source code (entrypoint, instructions, error handling, extensions like confidential transfer, memo transfer, etc.). This is the core blockchain component.
- Client Libraries: There are multiple client implementations:
– JS Client (in “clients/js” and “clients/js-legacy”) that interact with the on-chain program.
– CLI Client (in “clients/cli”) that likely provides direct command-line access.
– Rust Client (in “clients/rust” and “clients/rust-legacy”).
- Confidential Transfer Modules: The “confidential-transfer” folder includes submodules for ciphertext arithmetic, elgamal registry, proof extraction, proof generation, and related tests. These modules are critical for key aspects of confidential computations and extending the token program.
- Build, Test, and Deployment Tools: Various scripts (in “scripts/” and “.github/” folders) for building, testing, formatting, linting, IDL generation, client generation, and managing the local validator.
- External Dependencies & Validator Setup: The README discusses incorporating external programs (with specific program IDs) into the local validator configuration.

##### Establish Component Relationships
- Off-Chain Clients ↔ On-Chain Program:
- Confidential Transfer Modules ↔ On-Chain Program:
– Show how confidential transfer extensions (and cryptographic modules) integrate with or extend the core Solana program functionality.
- Build/CI/CD Pipelines ↔ Code Components:
- External Programs:
- Development & Testing Tools:
– Incorporate elements for running local validator (start/stop scripts) and additional testing frameworks (unit tests, end-to-end tests).

##### Architectural Patterns / Design Principles
- Separation of Concerns:
– Clearly separate the on-chain components (Solana program) from off-chain components (client libraries and scripts).
- Modular Design:
– Each client library and the confidential transfer module are developed as separate modules, allowing independent evolution of technology stacks (Rust vs JavaScript).
- CI/CD and Automation:
– Highlight the integration of build scripts and GitHub workflows for continuous integration and deployment.

##### Technologies, Frameworks, and Tools
- Programming Languages: Rust (for program logic and some clients), JavaScript/TypeScript (for client and tooling), and CLI tool in Rust.
- Build Tools: Cargo (Rust’s package manager), PNPM (for managing JS dependencies and scripts), and various scripts (MJS files).
- Deployment and Testing: GitHub Actions for CI/CD, local validator scripts for on-chain testing.
- Solana-specific Tools: Shank and/or Anchor for generating IDLs; external program dependencies integrated via addresses.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% On-Chain Layer
    subgraph "On-Chain Layer"
        onchain["On-Chain Program"]:::onchain
    end

    %% Off-Chain Clients
    subgraph "Off-Chain Clients"
        js["JS Client Libraries"]:::offchain
        cli["CLI Client Library"]:::offchain
        rust["Rust Client Libraries"]:::offchain
    end

    %% Supportive Modules
    subgraph "Supportive Modules"
        conf["Confidential Transfer Modules"]:::supportive
    end

    %% Build & CI/CD Tools
    subgraph "Build & CI/CD"
        build["Build, Test & Deployment Tools"]:::tooling
    end

    %% External Dependencies
    external["External Dependencies"]:::tooling

    %% Relationships: Client Libraries to On-Chain Program
    js -->|"API_Call/Transaction_Submission"| onchain
    cli -->|"API_Call/Transaction_Submission"| onchain
    rust -->|"API_Call/Transaction_Submission"| onchain

    %% Relationship: Confidential Transfer Modules to On-Chain Program
    conf -->|"Integration/Extension"| onchain

    %% Relationship: Build & CI/CD Tools automates builds/tests and IDL generation for other components
    build -->|"Build/Test/Generate_IDL"| onchain
    build -->|"Build/Test/Generate_IDL"| js
    build -->|"Build/Test/Generate_IDL"| cli
    build -->|"Build/Test/Generate_IDL"| rust
    build -->|"Build/Test/Generate_IDL"| conf

    %% External dependencies used by On-Chain Program for validator configuration
    external -->|"Validator_Setup"| onchain

    %% Click Events for Components
    click onchain "https://github.com/solana-program/token-2022/tree/main/program/"
    click js "https://github.com/solana-program/token-2022/tree/main/clients/js/"
    click js "https://github.com/solana-program/token-2022/tree/main/clients/js-legacy/"
    click cli "https://github.com/solana-program/token-2022/tree/main/clients/cli/"
    click rust "https://github.com/solana-program/token-2022/tree/main/clients/rust/"
    click rust "https://github.com/solana-program/token-2022/tree/main/clients/rust-legacy/"
    click conf "https://github.com/solana-program/token-2022/tree/main/confidential-transfer/"
    click build "https://github.com/solana-program/token-2022/tree/main/scripts/"
    click build "https://github.com/solana-program/token-2022/tree/main/.github/"

    %% Styles for Colour Coding
    classDef onchain fill:#ADD8E6,stroke:#000,stroke-width:1px;
    classDef offchain fill:#90EE90,stroke:#000,stroke-width:1px;
    classDef supportive fill:#FFA500,stroke:#000,stroke-width:1px;
    classDef tooling fill:#D3D3D3,stroke:#000,stroke-width:1px;
```
