How manudasari265/anchor works
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