# raydium-io/raydium-cpi-example architecture

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

- Interactive diagram: https://gitdiagram.com/raydium-io/raydium-cpi-example
- Repository: https://github.com/raydium-io/raydium-cpi-example

## Overview

##### Main Components
- Three Primary CPI Programs: Represent each subproject as separate components:
- AMM (amm-cpi)
- CLMM (clmm-cpi)
- CPMM (cpmm-cpi)
- External Raydium Contracts: Since the CPIs rely on calls to Raydium’s production contracts, include an external block (or blocks) that represent these Raydium liquidity pool contracts with separate labels (AMM, CLMM, CPMM). You may also denote the specific accounts (AmmConfig, FeeReceiver, etc.) mentioned in the README.
- Build/Deployment Environment: Include elements like the Anchor CLI, solana-cli, and any build scripts (e.g. build.sh) to indicate how code is compiled and deployed. You might add a label for the “devnet/mainnet” environment based on provided account configurations.

##### Architectural Patterns and Technologies
- That the project leverages the Anchor framework, which standardizes the program structure and configuration (see Anchor.toml files).
- The modular organization (each protocol type in its own folder) hints at separation of concerns: each CPI program is self-contained and targets a specific liquidity pool model.
- The presence of external configuration files (Cargo.toml, Anchor.toml) and test files indicates a robust deployment and testing strategy.

## Diagram (Mermaid)

```mermaid
flowchart TD
    A["Raydium CPI Example"]:::main
    B["Build/Deployment Environment"]:::build
    A --> B

    subgraph "AMM CPI"
        A1["AMM CPI Program"]:::cpi
        A2["AMM Instructions"]:::instructions
        A1 --> A2
    end

    subgraph "CLMM CPI"
        C1["CLMM CPI Program"]:::cpi
        C2["CLMM Instructions"]:::instructions
        C1 --> C2
    end

    subgraph "CPMM CPI"
        D1["CPMM CPI Program"]:::cpi
        D2["CPMM Instructions"]:::instructions
        D1 --> D2
    end

    subgraph "Raydium Liquidity Contracts"
        X1["Raydium AMM Contract"]:::external
        X2["Raydium CLMM Contract"]:::external
        X3["Raydium CPMM Contract"]:::external
    end

    E["Client/Test Environment (CPMM Tests)"]:::client

    %% Connections from Client to each CPI Program
    E -->|"InvokeOperations"| A1
    E -->|"InvokeOperations"| C1
    E -->|"InvokeOperations"| D1

    %% CPI Instructions call External Raydium Contracts
    A2 -->|"CPI_call"| X1
    C2 -->|"CPI_call"| X2
    D2 -->|"CPI_call"| X3

    %% Styles
    classDef main fill:#f9c,stroke:#333,stroke-width:2px;
    classDef build fill:#ffd,stroke:#333,stroke-width:2px;
    classDef cpi fill:#ccf,stroke:#333,stroke-width:2px;
    classDef instructions fill:#cfc,stroke:#333,stroke-width:2px;
    classDef external fill:#fcc,stroke:#333,stroke-width:2px;
    classDef client fill:#ffd,stroke:#333,stroke-width:2px;

    %% Click Events
    click A1 "https://github.com/raydium-io/raydium-cpi-example/tree/master/amm-cpi/programs/amm-cpi"
    click A2 "https://github.com/raydium-io/raydium-cpi-example/tree/master/amm-cpi/programs/amm-cpi/src/instructions"
    click C1 "https://github.com/raydium-io/raydium-cpi-example/tree/master/clmm-cpi/programs/clmm-cpi"
    click C2 "https://github.com/raydium-io/raydium-cpi-example/tree/master/clmm-cpi/programs/clmm-cpi/src/instructions"
    click D1 "https://github.com/raydium-io/raydium-cpi-example/tree/master/cpmm-cpi/programs/cpmm-cpi"
    click D2 "https://github.com/raydium-io/raydium-cpi-example/tree/master/cpmm-cpi/programs/cpmm-cpi/src/instructions"
    click E "https://github.com/raydium-io/raydium-cpi-example/tree/master/cpmm-cpi/tests"
    click B "https://github.com/raydium-io/raydium-cpi-example/blob/master/build.sh"
```
