# regolith-labs/steel architecture

> Architecture diagram of the GitHub repository regolith-labs/steel, 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/steel
- Repository: https://github.com/regolith-labs/steel

## Overview

##### Project Type and Purpose
- Steel is a developer-oriented framework written in Rust.
- Its purpose is to facilitate building safe and maintainable smart contracts on the Solana blockchain.
- The project includes a CLI tool that scaffolds new project templates and a core library that provides helper functions, macros, and standard patterns for Solana development.

##### File Structure
- Top-Level Components:
- Root-level files (Cargo.toml, Cargo.lock, README.md) denote a workspace.
- The “cli” directory is dedicated to the command-line tool used to initialize, build, and clean projects.
- The “lib” directory holds the core library providing functionalities for account management, CPIs (Cross-Program Invocations), error handling, logging, etc.
- The “lib” folder is organized into modules such as account, spl (Solana Program Library utilities), and utils, showing a modular approach for handling different aspects of smart contract development.

##### README for Architectural Insights
- The README elaborates on the recommended project structure (splitting code into “api” and “program”), which serves as a guideline for users building their own smart contracts with Steel.
- It provides examples for key macros (account!, instruction!, error!, event!) and emphasizes separation of concerns – a hint toward modularity.
- The instructions and examples illustrate how the framework ties together CLI operations with smart contract implementation through a structured division of components.

a. Main Components to Represent:
– CLI Component:
▪ Represents the Steel command-line interface.
▪ Contains modules like new_project, build_project, clean_project, and the templating system.
– Library (Core) Component:
▪ Contains modules for account management (account validation, deserialization, lamports handling), error logging, macros, and specialized Solana integrations (SPL helpers).
– Generated/Target Project Template:
▪ Outlines the recommended file structure for a Solana smart contract project with separate “api” and “program” sections.
– External Dependencies:
▪ Solana blockchain and its toolchain.
▪ External libraries such as SPL tokens.

b. Relationships and Interactions:
– The CLI component’s commands trigger the creation of new projects by pulling template files (from cli/src/template) that have a clear separation between the API and program portions.
– The generated project uses the Steel library (lib) for core functionalities during compilation and runtime on the Solana blockchain.
– The CLI acts as an orchestrator for build, test, and deployment tasks that link back to both the generated project structure and the library’s functionalities.

c. Architectural Patterns:
– Modular Design: Clear separation between CLI (tooling) and Lib (core functionality) with a generated project template following an MVC-like separation or layered architecture (interface/API vs. implementation/program).
– Template-based Scaffold: The use of predefined templates in the CLI to enforce a well-structured project layout.

d. Relevant Technologies and Frameworks:
– Rust as the programming language.
– Cargo for package and dependency management (with workspace setup).
– Solana SDK and Solana’s toolchain.
– SPL (Solana Program Library) for token-related functions.

##### Instructing the Principal Software Engineer
– Use clear labels for each component (e.g., “Steel CLI”, “Steel Core Library”, “Project Template: API”, “Project Template: Program”, “Solana Blockchain”, “SPL Integration”).
▪ From the CLI to the Project Template to indicate the generation of new projects.
▪ From the Project Template to the Core Library, showing dependency injection or usage.
▪ Between the Core Library and external services (Solana and SPL) to denote runtime interactions.
▪ Rectangles for major modules (CLI, Library, Project Template).
▪ Rounded rectangles for external dependencies and subsystems.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Steel CLI"
        CLI_Main["Steel CLI"]
        CLI_Args["CLI: Args"]
        NewProject["New Project"]
        BuildProject["Build Project"]
        CleanProject["Clean Project"]
        CLITemplate["CLI: Template"]
    end

    subgraph "Project Template"
        Template_API["Project Template: API"]
        Template_Program["Project Template: Program"]
    end

    subgraph "Steel Core Library"
        Steel_Core_Library["Steel Core Library"]
        Account["Account Module"]
        SPL["SPL Module"]
        Macros["Macros Module"]
        Log["Log Module"]
        Utils["Utils Module"]
    end

    subgraph "External Dependencies"
        Solana_BC["Solana Blockchain"]
        SPL_Integration["SPL Integration"]
    end

    %% CLI generates project templates
    NewProject -->|"generates"| Template_API
    CLITemplate -->|"generates"| Template_Program

    %% CLI orchestrates core library usage
    CLI_Main -->|"orchestrates"| Steel_Core_Library

    %% Project templates integrate core library functionalities
    Template_API -->|"integrates"| Steel_Core_Library
    Template_Program -->|"integrates"| Steel_Core_Library

    %% Core library modules
    Steel_Core_Library --> Account
    Steel_Core_Library --> SPL
    Steel_Core_Library --> Macros
    Steel_Core_Library --> Log
    Steel_Core_Library --> Utils

    %% Core library interacts with external dependencies
    Steel_Core_Library -->|"deploys_on"| Solana_BC
    Steel_Core_Library -->|"uses"| SPL_Integration

    %% Click Events
    click CLI_Main "https://github.com/regolith-labs/steel/tree/master/cli/"
    click CLI_Args "https://github.com/regolith-labs/steel/blob/master/cli/src/args.rs"
    click NewProject "https://github.com/regolith-labs/steel/blob/master/cli/src/new_project.rs"
    click BuildProject "https://github.com/regolith-labs/steel/blob/master/cli/src/build_project.rs"
    click CleanProject "https://github.com/regolith-labs/steel/blob/master/cli/src/clean_project.rs"
    click CLITemplate "https://github.com/regolith-labs/steel/tree/master/cli/src/template"
    click Steel_Core_Library "https://github.com/regolith-labs/steel/tree/master/lib/"
    click Template_API "https://github.com/regolith-labs/steel/tree/master/cli/src/template"
    click Template_Program "https://github.com/regolith-labs/steel/tree/master/cli/src/template"

    %% Style Classes
    classDef cli fill:#add8e6,stroke:#000,stroke-width:2px;
    classDef library fill:#90ee90,stroke:#000,stroke-width:2px;
    classDef template fill:#ffd700,stroke:#000,stroke-width:2px;
    classDef external fill:#ffb6c1,stroke:#000,stroke-width:2px;

    class CLI_Main,CLI_Args,NewProject,BuildProject,CleanProject,CLITemplate cli;
    class Steel_Core_Library,Account,SPL,Macros,Log,Utils library;
    class Template_API,Template_Program template;
    class Solana_BC,SPL_Integration external;
```
