# magicblock-labs/super-smart-contracts architecture

> Architecture diagram of the GitHub repository magicblock-labs/super-smart-contracts, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-08-25). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/magicblock-labs/super-smart-contracts
- Repository: https://github.com/magicblock-labs/super-smart-contracts

## Overview

#### Purpose and Entry Points
This is an Anchor/Solana example of “Super Smart Contracts”: on-chain agents delegate natural-language reasoning to an off-chain OpenAI-backed oracle, then receive an on-chain callback to act on the result. The main deployable surfaces are the oracle program, example agent programs, the oracle worker, and a React UI.
- `programs/solana-gpt-oracle/src/lib.rs`
- `llm_oracle/src/main.rs`
- `app/src/index.tsx`

#### On-Chain Oracle Interface
The `solana-gpt-oracle` Anchor program is the protocol boundary between agent contracts and the off-chain LLM executor. Agents create LLM context accounts and submit interactions through CPI, supplying their own callback program/instruction information. It owns the request/context state needed to correlate asynchronous oracle work with a destination callback.
- `programs/solana-gpt-oracle/src/lib.rs`
- `programs/solana-gpt-oracle/Cargo.toml`

#### Off-Chain LLM Oracle Worker
The Rust `llm_oracle` binary is the trusted off-chain execution stage: it observes or retrieves pending oracle interactions, maintains relevant memory/state, calls OpenAI, and returns results to Solana so the requesting program’s callback can run. This is the material trust and availability boundary: OpenAI output is not produced or verified by deterministic on-chain execution.
- `llm_oracle/src/main.rs`
- `llm_oracle/src/memory.rs`
- `llm_oracle/Cargo.toml`

#### Agent Programs and Callback Policy
Two Anchor programs demonstrate how application-specific policy is layered above the generic oracle. Each creates/configures an LLM context, invokes the oracle with CPI, and exposes a callback that consumes the response. `simple-agent` primarily demonstrates response handling; `agent-minter` demonstrates an LLM-gated token-dispensing action, making callback validation and authority checks architecturally critical.
- `programs/simple-agent/src/lib.rs`
- `programs/agent-minter/src/lib.rs`
- `programs/agent-minter/Cargo.toml`

#### Primary Interaction Flow
1. A user or client initializes an agent/context on Solana.
2. The client submits text to an agent instruction.
3. The agent CPIs into `solana-gpt-oracle`, creating an interaction linked to its callback.
4. The off-chain oracle worker obtains the interaction/context, invokes OpenAI, and submits a Solana transaction carrying the response.
5. The oracle invokes the agent callback; the agent logs the result or applies its domain policy, such as minting/dispensing tokens.
The callback must treat the oracle-controlled signer/identity as the authorization boundary rather than trusting arbitrary callers.

#### User Interface
The React application is a focused client for interacting with the token-dispensing agent. It contains wallet connectivity/signing UI, input/response presentation, and transaction-feedback components; it is not the oracle itself.
- `app/src/App.tsx`
- `app/src/components/Wallet.tsx`
- `app/src/components/Signature.tsx`
- `app/src/components/Response.tsx`

#### Runtime and Deployment Boundaries
On-chain code is Rust/Anchor and targets Solana; the UI is TypeScript/React; the oracle is a separate Rust process requiring Solana RPC/network access and OpenAI API access. Docker and Fly configuration indicate deployable service infrastructure for the off-chain worker, while Anchor migration code supports program deployment/setup.
- `Dockerfile`
- `fly.toml`
- `fly-mainnet.toml`
- `migrations/deploy.ts`

Main entry points: [`programs/solana-gpt-oracle/src/lib.rs`](https://github.com/magicblock-labs/super-smart-contracts/blob/main/programs/solana-gpt-oracle/src/lib.rs) (GPT oracle program), [`llm_oracle/src/main.rs`](https://github.com/magicblock-labs/super-smart-contracts/blob/main/llm_oracle/src/main.rs) (LLM oracle worker), [`app/src/App.tsx`](https://github.com/magicblock-labs/super-smart-contracts/blob/main/app/src/App.tsx) (React UI), [`programs/agent-minter/src/lib.rs`](https://github.com/magicblock-labs/super-smart-contracts/blob/main/programs/agent-minter/src/lib.rs) (Agent minter)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_onchain["Solana / Anchor"]
  node_agent_minter["Agent minter<br/>Anchor agent<br/>[lib.rs]"]
  node_simple_agent["Simple agent<br/>Anchor agent<br/>[lib.rs]"]
  node_oracle_program["GPT oracle program<br/>Anchor protocol<br/>[lib.rs]"]
  node_interaction_state[("Interaction context<br/>on-chain state<br/>[lib.rs]")]
  node_callback["Agent callback<br/>callback instruction<br/>[lib.rs]"]
  node_anchor_deploy["Anchor deployment<br/>migration setup<br/>[deploy.ts]"]
end

subgraph group_worker["Oracle Service"]
  node_worker_binary{{"LLM oracle worker<br/>Rust service<br/>[main.rs]"}}
  node_memory[("Oracle memory<br/>worker state<br/>[memory.rs]")]
  node_deployment["Worker deployment<br/>Docker / Fly"]
end

subgraph group_client["Client"]
  node_ui["React UI<br/>React client<br/>[App.tsx]"]
  node_wallet["Wallet UI<br/>wallet signing<br/>[Wallet.tsx]"]
  node_feedback["Transaction feedback<br/>UI components<br/>[Signature.tsx]"]
end

node_user(("User<br/>actor"))
node_openai{{"OpenAI<br/>LLM API"}}
node_solana_rpc{{"Solana RPC<br/>network access"}}

node_user -->|"uses"| node_ui
node_ui -->|"connects and signs"| node_wallet
node_ui -->|"submits text transaction"| node_agent_minter
node_ui -->|"renders result"| node_feedback
node_agent_minter -->|"CPI request"| node_oracle_program
node_simple_agent -->|"CPI request"| node_oracle_program
node_oracle_program -->|"creates pending interaction"| node_interaction_state
node_worker_binary -->|"reads and submits transactions"| node_solana_rpc
node_solana_rpc -.->|"retrieves pending request"| node_interaction_state
node_worker_binary -->|"maintains context"| node_memory
node_worker_binary -->|"invokes LLM"| node_openai
node_worker_binary -->|"submits LLM response"| node_oracle_program
node_oracle_program -->|"invokes configured callback"| node_callback
node_callback -->|"authorizes and dispenses"| node_agent_minter
node_deployment -->|"deploys"| node_worker_binary
node_anchor_deploy -->|"deploys"| node_oracle_program
node_anchor_deploy -->|"deploys"| node_agent_minter
node_anchor_deploy -->|"deploys"| node_simple_agent

click node_ui "https://github.com/magicblock-labs/super-smart-contracts/blob/main/app/src/App.tsx"
click node_wallet "https://github.com/magicblock-labs/super-smart-contracts/blob/main/app/src/components/Wallet.tsx"
click node_feedback "https://github.com/magicblock-labs/super-smart-contracts/blob/main/app/src/components/Signature.tsx"
click node_agent_minter "https://github.com/magicblock-labs/super-smart-contracts/blob/main/programs/agent-minter/src/lib.rs"
click node_simple_agent "https://github.com/magicblock-labs/super-smart-contracts/blob/main/programs/simple-agent/src/lib.rs"
click node_oracle_program "https://github.com/magicblock-labs/super-smart-contracts/blob/main/programs/solana-gpt-oracle/src/lib.rs"
click node_interaction_state "https://github.com/magicblock-labs/super-smart-contracts/blob/main/programs/solana-gpt-oracle/src/lib.rs"
click node_callback "https://github.com/magicblock-labs/super-smart-contracts/blob/main/programs/agent-minter/src/lib.rs"
click node_worker_binary "https://github.com/magicblock-labs/super-smart-contracts/blob/main/llm_oracle/src/main.rs"
click node_memory "https://github.com/magicblock-labs/super-smart-contracts/blob/main/llm_oracle/src/memory.rs"
click node_deployment "https://github.com/magicblock-labs/super-smart-contracts/blob/main/Dockerfile"
click node_anchor_deploy "https://github.com/magicblock-labs/super-smart-contracts/blob/main/migrations/deploy.ts"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_agent_minter,node_simple_agent,node_oracle_program,node_interaction_state,node_callback,node_anchor_deploy toneBlue
class node_worker_binary,node_memory,node_deployment toneAmber
class node_ui,node_wallet,node_feedback toneMint
class node_user,node_openai,node_solana_rpc toneNeutral
```

## Components

### Solana / Anchor

Programs execute on-chain and communicate through instructions and CPI.

- [Agent minter](https://github.com/magicblock-labs/super-smart-contracts/blob/main/programs/agent-minter/src/lib.rs): Anchor agent · Applies callback policy before token-dispensing actions. · `programs/agent-minter/src/lib.rs`
- [Simple agent](https://github.com/magicblock-labs/super-smart-contracts/blob/main/programs/simple-agent/src/lib.rs): Anchor agent · Demonstrates LLM response handling. · `programs/simple-agent/src/lib.rs`
- [GPT oracle program](https://github.com/magicblock-labs/super-smart-contracts/blob/main/programs/solana-gpt-oracle/src/lib.rs): Anchor protocol · Creates correlated interaction/context state and routes callbacks. · `programs/solana-gpt-oracle/src/lib.rs`
- [Interaction context](https://github.com/magicblock-labs/super-smart-contracts/blob/main/programs/solana-gpt-oracle/src/lib.rs): on-chain state · Stores pending request, context, and callback destination. · `programs/solana-gpt-oracle/src/lib.rs`
- [Agent callback](https://github.com/magicblock-labs/super-smart-contracts/blob/main/programs/agent-minter/src/lib.rs): callback instruction · Must authorize the oracle-controlled signer or identity. · `programs/agent-minter/src/lib.rs`
- [Anchor deployment](https://github.com/magicblock-labs/super-smart-contracts/blob/main/migrations/deploy.ts): migration setup · Supports Solana program deployment and setup. · `migrations/deploy.ts`

### Oracle Service

Trusted off-chain LLM execution boundary.

- [LLM oracle worker](https://github.com/magicblock-labs/super-smart-contracts/blob/main/llm_oracle/src/main.rs): Rust service · Retrieves pending interactions and submits response transactions. · `llm_oracle/src/main.rs`
- [Oracle memory](https://github.com/magicblock-labs/super-smart-contracts/blob/main/llm_oracle/src/memory.rs): worker state · Maintains relevant off-chain context for LLM requests. · `llm_oracle/src/memory.rs`
- [Worker deployment](https://github.com/magicblock-labs/super-smart-contracts/blob/main/Dockerfile): Docker / Fly · Deploys the separate oracle worker service. · `Dockerfile`

### Client

React client for the token-dispensing agent.

- [React UI](https://github.com/magicblock-labs/super-smart-contracts/blob/main/app/src/App.tsx): React client · Wallet-connected interface for agent-minter interactions. · `app/src/App.tsx`
- [Wallet UI](https://github.com/magicblock-labs/super-smart-contracts/blob/main/app/src/components/Wallet.tsx): wallet signing · `app/src/components/Wallet.tsx`
- [Transaction feedback](https://github.com/magicblock-labs/super-smart-contracts/blob/main/app/src/components/Signature.tsx): UI components · Displays transaction signatures and oracle responses. · `app/src/components/Signature.tsx`

### Other components

- **User**: actor
- **OpenAI**: LLM API · Non-deterministic external reasoning provider.
- **Solana RPC**: network access · Worker reads chain state and submits signed transactions.

## Connections

- User → React UI: uses
- React UI → Wallet UI: connects and signs
- React UI → Agent minter: submits text transaction
- React UI → Transaction feedback: renders result
- Agent minter → GPT oracle program: CPI request
- Simple agent → GPT oracle program: CPI request
- GPT oracle program → Interaction context: creates pending interaction
- LLM oracle worker → Solana RPC: reads and submits transactions
- Solana RPC → Interaction context: retrieves pending request
- LLM oracle worker → Oracle memory: maintains context
- LLM oracle worker → OpenAI: invokes LLM
- LLM oracle worker → GPT oracle program: submits LLM response
- GPT oracle program → Agent callback: invokes configured callback
- Agent callback → Agent minter: authorizes and dispenses
- Worker deployment → LLM oracle worker: deploys
- Anchor deployment → GPT oracle program: deploys
- Anchor deployment → Agent minter: deploys
- Anchor deployment → Simple agent: deploys
