# regolith-labs/ore-boost architecture

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

- Interactive diagram: https://gitdiagram.com/regolith-labs/ore-boost
- Repository: https://github.com/regolith-labs/ore-boost

## Overview

##### Project Type and Overall Purpose
- This is a blockchain-related project (likely on Solana) that implements a liquidity mining program. It operates by enabling users (stakers) to deposit, withdraw, claim rewards, and manage stake accounts, while administrators can manage boosts and program configurations.
- The project is modular and composed of multiple components (API, CLI, and Program) that work together to deliver the desired staking functionality.

##### Key Components
a. API Layer:
- Contains shared code, constants, custom errors, instructions, and SDK functionalities.
- Files like consts.rs, error.rs, instruction.rs, and several state modules (boost.rs, config.rs, stake.rs) define and manage on-chain state representations.
- Acts as the foundational library used by both the CLI and Program modules.

b. CLI (Command-Line Interface):
- Provides a user-facing interface with specific commands for actions (such as claim, close, deposit, open, rotate, withdraw) as well as administrative tasks (activate, deactivate, initialize, new, update).
- The CLI calls into the underlying libraries (from API) and may trigger blockchain transactions via the program.

c. Program Module (Smart Contract Logic):
- Implements the blockchain instructions corresponding to both user and admin operations.
- Files in this module (activate.rs, claim.rs, close.rs, etc.) are the smart contract endpoints that interact with on-chain state.
- This module processes transactions and updates the global accounts (Config) and individual accounts (Boost, Stake) based on instructions.

d. State:
- Represented by dedicated state accounts that store persistent on-chain data.
- Components include Boost (tracking incentives per mint), Config (singleton for program-wide variables), and Stake (tracks user-specific staked tokens).
- These states are shared by the API definitions and manipulated by the program instructions.

e. Tests:
- The tests directory (within the program subdirectory) contains integration tests (like test_rewards.rs) to validate the program’s behavior using the Solana toolchain.

##### Relationships and Interactions
- The CLI serves as an external entry point (or client) that packages user/admin commands.
- CLI commands utilize the API (via libraries such as the SDK and defined instructions) to form appropriate transactions that are sent to the Program.
- The Program receives and handles these instructions, updating the state accounts (Boost, Config, Stake) as needed.
- Errors and events defined in the API help with debugging, logging, and ensuring proper flow.
- The test suite interacts with the Program and APIs to simulate real-world use cases and confirm expected behavior.

##### Architectural Patterns and Design Principles
- Clear Separation of Concerns: The project is cleanly divided into API (business rules and state definitions), CLI (user interface layer), and Program (smart contract implementation).
- Modularity: Each directory targets a specific domain (interface, library code, on-chain logic), facilitating reusability and ease of maintenance.
- Use of Rust/Cargo for dependency and build management — note configuration files like Cargo.toml and Cargo.lock.

## Diagram (Mermaid)

```mermaid
flowchart TD
    CLI["CLI: Command Interface (User & Admin Commands)"]:::cli
    API["API: Shared Library (Constants, Errors, State Definitions, SDK)"]:::api
    Program["Program: On-chain Smart Contract Logic (Transaction Handlers/Instructions)"]:::program
    State["State: On-chain Accounts (Boost, Config, Stake)"]:::state
    Tests["Tests: Integration Tests using Solana toolchain"]:::tests

    CLI -->|"invokes"| API
    API -->|"sendsInstruction"| Program
    Program <-->|"read/write"| State
    Tests -->|"validates"| Program

    click CLI "https://github.com/regolith-labs/ore-boost/tree/master/cli/src"
    click API "https://github.com/regolith-labs/ore-boost/tree/master/api/src"
    click Program "https://github.com/regolith-labs/ore-boost/tree/master/program/src"
    click State "https://github.com/regolith-labs/ore-boost/tree/master/api/src/state"
    click Tests "https://github.com/regolith-labs/ore-boost/tree/master/program/tests"

    classDef cli fill:#e0f7fa,stroke:#006064,stroke-width:2px;
    classDef api fill:#ffecb3,stroke:#ff6f00,stroke-width:2px;
    classDef program fill:#dcedc8,stroke:#33691e,stroke-width:2px;
    classDef state fill:#f8bbd0,stroke:#880e4f,stroke-width:2px;
    classDef tests fill:#d1c4e9,stroke:#311b92,stroke-width:2px;
```
