# solana-foundation/solana-attestation-service architecture

> Architecture diagram of the GitHub repository solana-foundation/solana-attestation-service, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-29). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/solana-foundation/solana-attestation-service
- Repository: https://github.com/solana-foundation/solana-attestation-service

## Overview

##### Project type and purpose
- This is a blockchain-oriented service built on Solana: a Solana smart-contract (“program”) that implements an attestation service, plus all the associated tooling to generate IDL and client SDKs.
- Key purpose:
- program/: the on-chain Rust BPF program that defines state, instruction handlers, errors, events
- idl/: the JSON interface description of that program
- clients/: generated Rust and TypeScript SDKs that use the IDL to call the on-chain program
- integration_tests/: end-to-end tests that deploy the program and drive it via the SDK

##### File structure
- Top-level
- program/: main on-chain Rust code (entrypoint, instructions.rs, processor modules, state definitions)
- core/ & cereal_macro/: shared Rust crates for data types, serialization macros, helpers used by program and client codegen
- idl/: JSON file produced by Shank
- clients/: two subdirectories (rust and typescript) containing generated SDKs under src/generated
- scripts/: JavaScript scripts that invoke Shank and client generation
- integration_tests/: Rust tests that spin up a local cluster or test harness, invoke program instructions, assert behavior
- package.json & pnpm-lock.yaml: Node toolchain for TS client and scripts
- Cargo.toml(s): Rust workspace and individual crate definitions
- Patterns
- Macro-driven codegen (cereal_macro, Shank) to produce IDL and typed client code
- Clear separation: on-chain program vs off-chain client code vs IDL vs tests

##### README for additional insights
- Describes how to:
- build the on-chain program (`cargo-build-sbf`)
- run integration tests (which reuse the built BPF artifact)
- generate IDL via Shank CLI or pnpm script
- generate clients via pnpm script, consuming the IDL

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Shared Libraries
    Core["core/"]:::library
    Cereal["cereal_macro/"]:::library

    %% On-chain Zone
    subgraph "On-chain Zone"
        subgraph "Program Source"
            EP["entrypoint.rs"]:::onchain
            LIBP["lib.rs"]:::onchain
            INSTRS["instructions.rs"]:::onchain
            ERR["error.rs"]:::onchain
            EVT["events.rs"]:::onchain
            PROC["processor/"]:::onchain
            STATE["state/"]:::onchain
        end
        Build["cargo build-sbf → BPF Binary"]:::onchain
        Program["Deployed Program (BPF)"]:::onchain
        Cluster["Solana Cluster / RPC"]:::onchain
    end

    %% Off-chain Zone
    subgraph "Off-chain Zone"
        subgraph "Codegen & Tooling"
            ProcessIdl["process-idl.js"]:::tooling
            GenClients["generate-clients.js"]:::tooling
            Shank["Shank IDL Generator"]:::tooling
        end
        IDL["IDL: solana_attestation_service.json"]:::tooling
        subgraph "Client SDKs"
            RustSDK["Rust SDK"]:::client
            TS_SDK["TypeScript SDK"]:::client
        end
        Tests["Integration Tests"]:::tests
    end

    %% Connections
    Core --> EP
    Core --> ProcessIdl
    Cereal --> EP
    Cereal --> ProcessIdl

    LIBP --> Build
    INSTRS --> Build
    ERR --> Build
    EVT --> Build
    PROC --> Build
    STATE --> Build

    Build --> Program
    Program --> Cluster

    ProcessIdl --> Shank
    Shank --> IDL

    IDL --> GenClients
    GenClients --> RustSDK
    GenClients --> TS_SDK

    RustSDK --> Cluster
    TS_SDK --> Cluster

    Tests --> RustSDK
    Tests --> TS_SDK
    Tests --> Cluster

    %% Click Events
    click Core "https://github.com/solana-foundation/solana-attestation-service/blob/master/core/src/lib.rs"
    click Cereal "https://github.com/solana-foundation/solana-attestation-service/blob/master/cereal_macro/src/lib.rs"
    click EP "https://github.com/solana-foundation/solana-attestation-service/blob/master/program/src/entrypoint.rs"
    click LIBP "https://github.com/solana-foundation/solana-attestation-service/blob/master/program/src/lib.rs"
    click INSTRS "https://github.com/solana-foundation/solana-attestation-service/blob/master/program/src/instructions.rs"
    click ERR "https://github.com/solana-foundation/solana-attestation-service/blob/master/program/src/error.rs"
    click EVT "https://github.com/solana-foundation/solana-attestation-service/blob/master/program/src/events.rs"
    click PROC "https://github.com/solana-foundation/solana-attestation-service/tree/master/program/src/processor/"
    click STATE "https://github.com/solana-foundation/solana-attestation-service/tree/master/program/src/state/"
    click ProcessIdl "https://github.com/solana-foundation/solana-attestation-service/blob/master/scripts/process-idl.js"
    click GenClients "https://github.com/solana-foundation/solana-attestation-service/blob/master/scripts/generate-clients.js"
    click IDL "https://github.com/solana-foundation/solana-attestation-service/blob/master/idl/solana_attestation_service.json"
    click RustSDK "https://github.com/solana-foundation/solana-attestation-service/blob/master/clients/rust/src/lib.rs"
    click TS_SDK "https://github.com/solana-foundation/solana-attestation-service/blob/master/clients/typescript/package.json"
    click Tests "https://github.com/solana-foundation/solana-attestation-service/blob/master/integration_tests/tests/helpers/mod.rs"

    %% Styles
    classDef onchain fill:#e0f7fa,stroke:#006064,stroke-width:1px
    classDef tooling fill:#e8f5e9,stroke:#1b5e20,stroke-width:1px
    classDef client fill:#fff3e0,stroke:#e65100,stroke-width:1px
    classDef tests fill:#f3e5f5,stroke:#4a148c,stroke-width:1px
    classDef library fill:#f1f8e9,stroke:#33691e,stroke-width:1px
```
