# manudasari265/anchor architecture

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

- Interactive diagram: https://gitdiagram.com/manudasari265/anchor
- Repository: https://github.com/manudasari265/anchor

## Overview

##### Project Type and Purpose
- Anchor is a multi‐language, monorepo framework for Solana smart‐contract development.
- It provides:
- A Rust eDSL (`anchor-lang` and subcrates) for authoring on‐chain programs
- A CLI (`@coral-xyz/anchor-cli` in Rust + Node‐package glue) to build, deploy, generate IDL, and scaffold projects
- An IDL toolchain (Rust crates under `idl/`) to produce and convert program interface descriptions
- TypeScript client libraries (`ts/packages/*`) generated from IDL for Web or Node apps
- A version manager (`avm`) for Anchor toolchains
- Documentation (Next.js under `docs/app`) and example/test harnesses

##### High-Level Architecture Components
a. Core Rust Library Layer
- anchor-lang eDSL & derive crates (under `/lang`)
- anchor-client (Rust client API in `/client`)
- anchor-spl (CPI clients for SPL programs in `/spl`)
- IDL generator (`idl/` crate)
b. CLI & Tooling
- Rust CLI binaries (`cli/src/bin/main.rs`)
- Node “npm‐package” glue (`cli/npm-package/anchor.js`)
- AVM version manager (`avm/`)
c. TypeScript Packages
- Core TS client (`ts/packages/anchor`)
- SPL adapters (`spl‐*` under `ts/packages`)
- Shared TS test harness (`ts/tests`)
d. Documentation Frontend
- Next.js app (`docs/app`) consuming markdown/MDX under `docs/content`
e. Examples & Tests
- On‐chain program examples (`examples/tutorial`)
- Integration/end‐to‐end tests (`tests/*`) using generated IDL and TS/Rust clients
f. CI/CD & Build Orchestration
- Makefile, `bump-version.sh`
- GitHub Actions (`.github/workflows/*.yaml`)

##### Relationships & Data Flows
- Developer writes Rust program using `anchor-lang` →
Rust compiler + procedural macros (in `/lang`, `/lang/syn`, `/lang/derive`) produce BPF .so + IDL JSON.
- CLI reads IDL, invokes codegen (Rust→TS via `idl/src/convert.rs` or JS glue) →
Emits TypeScript client API in `ts/packages/…`
- Developer application imports TS client →
Makes RPC calls to Solana cluster →
On‐chain Anchor program executes via `anchor-lang` runtime + CPI clients (`anchor-spl`) →
Interacts with standard SPL programs
- AVM orchestrates correct version of CLI, Rust, and Node environments for consistent builds.
- Documentation site (`docs/app`) uses MDX content and live code snippets generated by CLI/tooling.
- CI workflows validate: building Rust crates, generating IDL, building TS packages, running tests (Rust & JS).

##### Architectural Patterns & Principles
- Monorepo with multi‐language workspaces (Cargo + npm/pnpm)
- Layered separation:
- Language layer (procedural macros & derive)
- Core runtime (Rust and TypeScript client libs)
- CLI orchestration layer
- Documentation/Examples/Test harness layer
- Code generation pipeline: Rust macros → IDL → TS codegen → client SDK
- Plugin‐style extensibility: SPL adapters are separate packages under `ts/packages` and `/spl`

## Diagram (Mermaid)

```mermaid
flowchart TD
  %% Developer Entry
  Dev["Developer IDE / CLI Entry Point"]:::start

  subgraph "Rust Workspaces"
    direction TB
    Lang["Rust eDSL & Derive Crates"]:::onchain
    ClientRust["Rust Client API"]:::offchain
    SPLRust["SPL CPI Clients"]:::onchain
    IDLGen["IDL Generator & Toolchain"]:::tooling
  end

  subgraph "Build Tools & CLI"
    direction TB
    CLI_Rust["Anchor CLI (Rust binary)"]:::tooling
    CLI_JS["Anchor CLI (Node npm glue)"]:::tooling
    AVM["AVM Version Manager"]:::tooling
  end

  subgraph "TypeScript Workspaces"
    direction TB
    TSCore["Core TS Client SDK"]:::offchain
    TSSPL["SPL Adapter TS Packages"]:::offchain
    TSTest["Shared TS Test Harness"]:::offchain
  end

  subgraph "Documentation"
    direction TB
    DocsApp["Documentation Frontend (Next.js)"]:::docs
    DocsContent["Documentation Content (MDX)"]:::docs
  end

  subgraph "Examples & Tests"
    direction TB
    Examples["Tutorial Examples"]:::examples
    E2E["Integration / E2E Tests"]:::tests
  end

  subgraph "CI/CD & Releases"
    direction TB
    CI["CI/CD Workflows"]:::tooling
    BuildTools["Build Orchestration & Helpers"]:::tooling
  end

  %% Other Components
  BPF["BPF Compiler"]:::onchain
  SoLib["Deployed .so Program"]:::onchain
  IDLJSON["IDL JSON"]:::tooling
  RPC["Solana RPC / Cluster"]:::external
  Ledger["Ledger State"]:::external

  %% Flows
  Dev -->|writes Rust program| Lang
  Lang -->|procedural macros| BPF
  BPF -->|produces| SoLib
  BPF -->|generates| IDLJSON
  IDLJSON --> IDLGen
  Dev -->|invokes CLI| CLI_Rust
  CLI_Rust -->|reads IDL| IDLGen
  IDLGen -->|invokes codegen| CLI_JS
  CLI_JS -->|emits| TSCore
  CLI_JS -->|emits| TSSPL
  TSCore -->|import in app| RPC
  TSSPL -->|import in app| RPC

  RPC -->|RPC call| SoLib
  SoLib -->|executes via| Lang
  SoLib -->|calls CPI| SPLRust
  SPLRust -->|interacts| Ledger

  AVM -->|manages versions| CLI_Rust
  AVM -->|manages versions| CLI_JS
  AVM -->|manages versions| Lang

  CLI_JS --> DocsApp
  DocsContent --> DocsApp

  Examples --> CLI_Rust
  CLI_Rust --> Examples

  E2E --> TSCore
  E2E --> ClientRust

  CI -->|triggers builds| Lang
  CI -->|triggers builds| TSCore
  CI -->|runs tests| E2E
  BuildTools -->|used by| CI

  %% Click Events
  click Lang "https://github.com/manudasari265/anchor/tree/master/lang/"
  click ClientRust "https://github.com/manudasari265/anchor/tree/master/client/"
  click SPLRust "https://github.com/manudasari265/anchor/tree/master/spl/"
  click IDLGen "https://github.com/manudasari265/anchor/tree/master/idl/"
  click CLI_Rust "https://github.com/manudasari265/anchor/blob/master/cli/src/bin/main.rs"
  click CLI_JS "https://github.com/manudasari265/anchor/blob/master/cli/npm-package/anchor.js"
  click AVM "https://github.com/manudasari265/anchor/tree/master/avm/"
  click TSCore "https://github.com/manudasari265/anchor/tree/master/ts/packages/anchor/"
  click TSSPL "https://github.com/manudasari265/anchor/tree/master/ts/packages/spl-*"
  click TSTest "https://github.com/manudasari265/anchor/tree/master/ts/tests/"
  click DocsApp "https://github.com/manudasari265/anchor/tree/master/docs/app/"
  click DocsContent "https://github.com/manudasari265/anchor/tree/master/docs/content/"
  click Examples "https://github.com/manudasari265/anchor/tree/master/examples/tutorial/"
  click CI "https://github.com/manudasari265/anchor/tree/master/.github/workflows/"
  click BuildTools "https://github.com/manudasari265/anchor/tree/master/Makefile"

  %% Styles
  classDef onchain fill:#bef2ad,stroke:#2d7a2d,color:#0a400a;
  classDef offchain fill:#c2e0ff,stroke:#005bb5,color:#003d7a;
  classDef tooling fill:#e0e0e0,stroke:#888888,color:#333333;
  classDef docs fill:#ffd699,stroke:#cc8400,color:#663f00;
  classDef examples fill:#e5ccff,stroke:#8c42ff,color:#4b0073;
  classDef tests fill:#ffe6cc,stroke:#ff7a00,color:#7a3d00;
  classDef external fill:#f0f0f0,stroke:#666666,color:#333333;
  classDef start fill:#ffffff,stroke:#000000,color:#000000;
```
