# usainbluntmx/atlas architecture

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

- Interactive diagram: https://gitdiagram.com/usainbluntmx/atlas
- Repository: https://github.com/usainbluntmx/atlas

## Overview

1. **Repo shape: two main runtimes**
   - This is a Solana dApp with a hard split between:
     - **On-chain program** in `programs/atlas` (Rust + Anchor)
     - **Client/game app** in `frontend` (Next.js + TypeScript + Phaser)
   - There is no custom backend or database; persistent state lives on Solana.

2. **On-chain core: the `atlas` Anchor program**
   - `programs/atlas/src/lib.rs` is the protocol boundary.
   - It exposes the world logic described in the README: initialize the shared world, initialize the leaderboard, mint a character NFT for a wallet, and collect resources.
   - This program is the source of truth for:
     - global world state
     - per-wallet character state
     - leaderboard updates
     - resource availability / depletion

3. **State model: PDA-backed accounts**
   - The architecture centers on deterministic PDAs:
     - `WorldState` seeded by `["world"]`
     - `Character` seeded by `["character", owner]`
     - `Leaderboard` seeded by `["leaderboard"]`
   - These account boundaries are important because the frontend reads and writes them directly via Anchor; there is no intermediary API layer.

4. **Frontend shell: Next.js as orchestration layer**
   - `frontend/app/page.tsx` is the main client entry point and likely coordinates wallet state, game state, and on-chain actions.
   - `frontend/app/layout.tsx` and `frontend/app/globals.css` provide the app shell and global styling.
   - `frontend/components/WalletProvider.tsx` wraps Solana wallet connectivity, which is the root dependency for all chain interactions.

5. **Game rendering: Phaser embedded inside React**
   - `frontend/components/GameCanvas.tsx` mounts the Phaser game inside the Next.js UI.
   - The actual game runtime is in `frontend/game/main.ts`, with scenes under `frontend/game/scenes/`.
   - `BootScene.ts` is the startup/bootstrap layer, and `WorldScene.ts` is the active play world.
   - `frontend/game/objects/Player.ts` defines the player entity and movement/animation behavior.

6. **UI overlay: game HUD and transaction feedback**
   - `frontend/components/HUD.tsx` provides the in-game interface: score, progress, and likely world status.
   - `frontend/components/TxToast.tsx` surfaces transaction hashes/links so user actions remain verifiable on Solscan.
   - `frontend/components/Landing.tsx` is the non-game presentation layer for onboarding and protocol explanation.

7. **Chain interaction layer**
   - `frontend/lib/anchor.ts` is the client-side Anchor integration layer: program ID, IDL access, and PDA helpers.
   - `frontend/lib/constants.ts` centralizes protocol and app configuration.
   - `frontend/lib/arweave.ts` handles NFT metadata/storage integration, which matters because character minting depends on off-chain asset metadata even though ownership/state are on Solana.

8. **Primary data flow: wallet → game action → transaction → updated state**
   - User connects a wallet through the provider.
   - The UI/game emits actions such as mint character or collect resource.
   - The frontend constructs an Anchor transaction and sends it to Solana Devnet.
   - The program mutates PDA accounts.
   - The frontend re-reads account state and updates the HUD/game world; tx hashes are surfaced to the player.

9. **Gameplay-state coupling**
   - The Phaser world is not just cosmetic; it reflects shared on-chain state.
   - Resource collection affects persistent world availability, not just local score.
   - The leaderboard is also on-chain, so competition is globally shared across sessions and devices.

10. **Deployment and network assumptions**
    - The protocol is configured for **Solana Devnet**, not mainnet.
    - `migrations/deploy.ts` is the Anchor deployment path for the program.
    - The README’s program ID and Solscan links indicate the deployed on-chain artifacts are part of the architecture, not just local dev scaffolding.

11. **Testing and verification**
    - `tests/atlas.ts` is the program test suite, likely validating instruction behavior and PDA/account transitions.
    - The repo also includes `docs/architecture.png`, reinforcing that the intended architecture is a small set of deterministic on-chain accounts with a thin interactive client.

12. **Diagram boundary summary**
    - Draw three major boxes:
      - **Solana/Anchor program** for authoritative state and rules
      - **Next.js client shell** for wallet, app state, and UI composition
      - **Phaser game runtime** embedded in the client for rendering and input
    - Then show two external integrations:
      - **Wallet adapter / Phantom-compatible wallets**
      - **Arweave** for NFT metadata
    - The key architectural principle is that the game is persistent and shared because the world state is stored on-chain, while the frontend is a stateless presenter and transaction initiator.

Main entry points: [`programs/atlas/src/lib.rs`](https://github.com/usainbluntmx/atlas/blob/main/programs/atlas/src/lib.rs) (atlas program), [`frontend/app/page.tsx`](https://github.com/usainbluntmx/atlas/blob/main/frontend/app/page.tsx) (App page), [`frontend/game/scenes/WorldScene.ts`](https://github.com/usainbluntmx/atlas/blob/main/frontend/game/scenes/WorldScene.ts) (World scene), [`frontend/lib/anchor.ts`](https://github.com/usainbluntmx/atlas/blob/main/frontend/lib/anchor.ts) (Anchor client)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_onchain["Solana program"]
  node_program_lib["atlas program<br/>Anchor program<br/>[lib.rs]"]
  node_world_state[("World state<br/>PDA account<br/>[lib.rs]")]
  node_character_state[("Character state<br/>PDA account<br/>[lib.rs]")]
  node_leaderboard_state[("Leaderboard<br/>PDA account<br/>[lib.rs]")]
  node_world_rules{{"World logic<br/>game rules<br/>[lib.rs]"}}
  node_character_mint{{"Mint character<br/>instruction<br/>[lib.rs]"}}
  node_leaderboard_logic{{"Score updates<br/>instruction<br/>[lib.rs]"}}
end

subgraph group_client["Frontend client"]
  node_app_page["App page<br/>Next.js entry<br/>[page.tsx]"]
  node_app_layout["App shell<br/>Next.js layout<br/>[layout.tsx]"]
  node_wallet_provider["Wallet provider<br/>wallet adapter<br/>[WalletProvider.tsx]"]
  node_game_canvas["Game canvas<br/>React host<br/>[GameCanvas.tsx]"]
  node_hud["HUD<br/>game overlay<br/>[HUD.tsx]"]
  node_landing["Landing<br/>onboarding UI<br/>[Landing.tsx]"]
  node_tx_toast["Tx toast<br/>feedback UI<br/>[TxToast.tsx]"]
  node_anchor_client["Anchor client<br/>chain SDK<br/>[anchor.ts]"]
  node_app_constants["Constants<br/>config module<br/>[constants.ts]"]
  node_arweave_client["Arweave client<br/>metadata storage<br/>[arweave.ts]"]
  node_phaser_main["Game runtime<br/>Phaser entry<br/>[main.ts]"]
  node_boot_scene["Boot scene<br/>Phaser scene<br/>[BootScene.ts]"]
  node_world_scene["World scene<br/>Phaser scene<br/>[WorldScene.ts]"]
  node_player_obj["Player<br/>game entity<br/>[Player.ts]"]
end

subgraph group_ops["Build and tests"]
  node_deploy_script["Deploy script<br/>Anchor deploy<br/>[deploy.ts]"]
  node_tests_suite["Program tests<br/>test suite<br/>[atlas.ts]"]
end

subgraph group_external["External services"]
  node_wallets(("Wallets<br/>external dependency"))
  node_solana(("Solana Devnet<br/>network"))
  node_arweave(("Arweave<br/>storage network"))
end

node_program_lib -->|"owns"| node_world_state
node_program_lib -->|"owns"| node_character_state
node_program_lib -->|"owns"| node_leaderboard_state
node_program_lib -->|"exposes"| node_world_rules
node_program_lib -->|"exposes"| node_character_mint
node_program_lib -->|"exposes"| node_leaderboard_logic
node_app_page -->|"uses"| node_wallet_provider
node_app_page -->|"hosts"| node_game_canvas
node_app_page -->|"renders"| node_hud
node_app_page -->|"shows"| node_landing
node_app_page -->|"surfaces"| node_tx_toast
node_game_canvas -->|"boots"| node_phaser_main
node_phaser_main -->|"starts"| node_boot_scene
node_boot_scene -->|"hands off"| node_world_scene
node_world_scene -->|"spawns"| node_player_obj
node_world_scene -->|"reads/writes"| node_anchor_client
node_anchor_client -->|"calls"| node_program_lib
node_anchor_client -->|"configures"| node_app_constants
node_anchor_client -->|"fetches"| node_arweave_client
node_wallet_provider -->|"connects"| node_wallets
node_anchor_client -->|"submits"| node_solana
node_arweave_client -->|"stores"| node_arweave
node_deploy_script -->|"deploys"| node_program_lib
node_tests_suite -->|"verifies"| node_program_lib
node_world_scene -->|"syncs"| node_world_state
node_world_scene -->|"syncs"| node_character_state
node_world_scene -->|"syncs"| node_leaderboard_state
node_app_page -->|"orchestrates"| node_anchor_client

click node_program_lib "https://github.com/usainbluntmx/atlas/blob/main/programs/atlas/src/lib.rs"
click node_world_state "https://github.com/usainbluntmx/atlas/blob/main/programs/atlas/src/lib.rs"
click node_character_state "https://github.com/usainbluntmx/atlas/blob/main/programs/atlas/src/lib.rs"
click node_leaderboard_state "https://github.com/usainbluntmx/atlas/blob/main/programs/atlas/src/lib.rs"
click node_world_rules "https://github.com/usainbluntmx/atlas/blob/main/programs/atlas/src/lib.rs"
click node_character_mint "https://github.com/usainbluntmx/atlas/blob/main/programs/atlas/src/lib.rs"
click node_leaderboard_logic "https://github.com/usainbluntmx/atlas/blob/main/programs/atlas/src/lib.rs"
click node_app_page "https://github.com/usainbluntmx/atlas/blob/main/frontend/app/page.tsx"
click node_app_layout "https://github.com/usainbluntmx/atlas/blob/main/frontend/app/layout.tsx"
click node_wallet_provider "https://github.com/usainbluntmx/atlas/blob/main/frontend/components/WalletProvider.tsx"
click node_game_canvas "https://github.com/usainbluntmx/atlas/blob/main/frontend/components/GameCanvas.tsx"
click node_hud "https://github.com/usainbluntmx/atlas/blob/main/frontend/components/HUD.tsx"
click node_landing "https://github.com/usainbluntmx/atlas/blob/main/frontend/components/Landing.tsx"
click node_tx_toast "https://github.com/usainbluntmx/atlas/blob/main/frontend/components/TxToast.tsx"
click node_anchor_client "https://github.com/usainbluntmx/atlas/blob/main/frontend/lib/anchor.ts"
click node_app_constants "https://github.com/usainbluntmx/atlas/blob/main/frontend/lib/constants.ts"
click node_arweave_client "https://github.com/usainbluntmx/atlas/blob/main/frontend/lib/arweave.ts"
click node_phaser_main "https://github.com/usainbluntmx/atlas/blob/main/frontend/game/main.ts"
click node_boot_scene "https://github.com/usainbluntmx/atlas/blob/main/frontend/game/scenes/BootScene.ts"
click node_world_scene "https://github.com/usainbluntmx/atlas/blob/main/frontend/game/scenes/WorldScene.ts"
click node_player_obj "https://github.com/usainbluntmx/atlas/blob/main/frontend/game/objects/Player.ts"
click node_deploy_script "https://github.com/usainbluntmx/atlas/blob/main/migrations/deploy.ts"
click node_tests_suite "https://github.com/usainbluntmx/atlas/blob/main/tests/atlas.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_program_lib,node_world_state,node_character_state,node_leaderboard_state,node_world_rules,node_character_mint,node_leaderboard_logic toneBlue
class node_app_page,node_app_layout,node_wallet_provider,node_game_canvas,node_hud,node_landing,node_tx_toast,node_anchor_client,node_app_constants,node_arweave_client,node_phaser_main,node_boot_scene,node_world_scene,node_player_obj toneAmber
class node_deploy_script,node_tests_suite toneMint
class node_wallets,node_solana,node_arweave toneRose
```

## Components

### Solana program

Anchor-based source of truth for world state and gameplay rules.

- [atlas program](https://github.com/usainbluntmx/atlas/blob/main/programs/atlas/src/lib.rs): Anchor program · Protocol boundary and on-chain instruction entrypoint. · `programs/atlas/src/lib.rs`
- [World state](https://github.com/usainbluntmx/atlas/blob/main/programs/atlas/src/lib.rs): PDA account · Shared global world state seeded by world. · `programs/atlas/src/lib.rs`
- [Character state](https://github.com/usainbluntmx/atlas/blob/main/programs/atlas/src/lib.rs): PDA account · Per-wallet character account seeded by character and owner. · `programs/atlas/src/lib.rs`
- [Leaderboard](https://github.com/usainbluntmx/atlas/blob/main/programs/atlas/src/lib.rs): PDA account · Global ranking account seeded by leaderboard. · `programs/atlas/src/lib.rs`
- [World logic](https://github.com/usainbluntmx/atlas/blob/main/programs/atlas/src/lib.rs): game rules · Initializes world and handles resource collection and depletion. · `programs/atlas/src/lib.rs`
- [Mint character](https://github.com/usainbluntmx/atlas/blob/main/programs/atlas/src/lib.rs): instruction · Creates a character NFT tied to a wallet and metadata. · `programs/atlas/src/lib.rs`
- [Score updates](https://github.com/usainbluntmx/atlas/blob/main/programs/atlas/src/lib.rs): instruction · Updates the on-chain leaderboard from gameplay actions. · `programs/atlas/src/lib.rs`

### Frontend client

Next.js shell embedding the Phaser game and wallet interactions.

- [App page](https://github.com/usainbluntmx/atlas/blob/main/frontend/app/page.tsx): Next.js entry · Main client entry that coordinates wallet, game, and chain actions. · `frontend/app/page.tsx`
- [App shell](https://github.com/usainbluntmx/atlas/blob/main/frontend/app/layout.tsx): Next.js layout · Root UI layout for the client application. · `frontend/app/layout.tsx`
- [Wallet provider](https://github.com/usainbluntmx/atlas/blob/main/frontend/components/WalletProvider.tsx): wallet adapter · Wraps Solana wallet connectivity for the client UI. · `frontend/components/WalletProvider.tsx`
- [Game canvas](https://github.com/usainbluntmx/atlas/blob/main/frontend/components/GameCanvas.tsx): React host · Mounts the Phaser runtime inside the React interface. · `frontend/components/GameCanvas.tsx`
- [HUD](https://github.com/usainbluntmx/atlas/blob/main/frontend/components/HUD.tsx): game overlay · Displays score, progress, and world status. · `frontend/components/HUD.tsx`
- [Landing](https://github.com/usainbluntmx/atlas/blob/main/frontend/components/Landing.tsx): onboarding UI · Non-game presentation layer for onboarding and explanation. · `frontend/components/Landing.tsx`
- [Tx toast](https://github.com/usainbluntmx/atlas/blob/main/frontend/components/TxToast.tsx): feedback UI · Surfaces transaction hashes and verification links. · `frontend/components/TxToast.tsx`
- [Anchor client](https://github.com/usainbluntmx/atlas/blob/main/frontend/lib/anchor.ts): chain SDK · Program ID, IDL access, and PDA helper layer. · `frontend/lib/anchor.ts`
- [Constants](https://github.com/usainbluntmx/atlas/blob/main/frontend/lib/constants.ts): config module · Centralized protocol and application configuration. · `frontend/lib/constants.ts`
- [Arweave client](https://github.com/usainbluntmx/atlas/blob/main/frontend/lib/arweave.ts): metadata storage · Handles NFT metadata and off-chain asset storage integration. · `frontend/lib/arweave.ts`
- [Game runtime](https://github.com/usainbluntmx/atlas/blob/main/frontend/game/main.ts): Phaser entry · Bootstraps the embedded Phaser game. · `frontend/game/main.ts`
- [Boot scene](https://github.com/usainbluntmx/atlas/blob/main/frontend/game/scenes/BootScene.ts): Phaser scene · Startup and bootstrap scene for the game. · `frontend/game/scenes/BootScene.ts`
- [World scene](https://github.com/usainbluntmx/atlas/blob/main/frontend/game/scenes/WorldScene.ts): Phaser scene · Active gameplay scene that reflects on-chain world state. · `frontend/game/scenes/WorldScene.ts`
- [Player](https://github.com/usainbluntmx/atlas/blob/main/frontend/game/objects/Player.ts): game entity · Player movement and animation behavior. · `frontend/game/objects/Player.ts`

### Build and tests

Deployment and verification tooling around the main runtimes.

- [Deploy script](https://github.com/usainbluntmx/atlas/blob/main/migrations/deploy.ts): Anchor deploy · Program deployment path for the on-chain contract. · `migrations/deploy.ts`
- [Program tests](https://github.com/usainbluntmx/atlas/blob/main/tests/atlas.ts): test suite · Validates instructions and account transitions. · `tests/atlas.ts`

### External services

Wallets, Solana network, and off-chain metadata storage.

- **Wallets**: external dependency · Phantom-compatible wallets used for signing transactions.
- **Solana Devnet**: network · Target network for program state and transactions.
- **Arweave**: storage network · External metadata storage used for character NFT assets.

## Connections

- atlas program → World state: owns · Defines and mutates the shared world PDA.
- atlas program → Character state: owns · Defines and mutates per-wallet character accounts.
- atlas program → Leaderboard: owns · Defines and mutates the global leaderboard PDA.
- atlas program → World logic: exposes · Exports world initialization and resource collection logic.
- atlas program → Mint character: exposes · Exports the character minting instruction.
- atlas program → Score updates: exposes · Exports leaderboard update behavior.
- App page → Wallet provider: uses · Relies on wallet connection for all chain actions.
- App page → Game canvas: hosts · Composes the embedded game runtime.
- App page → HUD: renders · Surfaces gameplay and chain status.
- App page → Landing: shows · Provides onboarding before or outside gameplay.
- App page → Tx toast: surfaces · Shows transaction feedback to the player.
- Game canvas → Game runtime: boots · Creates the Phaser runtime inside the React host.
- Game runtime → Boot scene: starts · Initial scene bootstrap.
- Boot scene → World scene: hands off · Transitions into the active play scene.
- World scene → Player: spawns · Uses the player entity for movement and animation.
- World scene → Anchor client: reads/writes · Reads on-chain state and sends gameplay transactions.
- Anchor client → atlas program: calls · Builds transactions against the Anchor program.
- Anchor client → Constants: configures · Uses shared IDs, network, and app settings.
- Anchor client → Arweave client: fetches · Resolves metadata needed for character minting.
- Wallet provider → Wallets: connects · Integrates with external signing wallets.
- Anchor client → Solana Devnet: submits · Sends transactions and account reads to Solana Devnet.
- Arweave client → Arweave: stores · Uploads or resolves NFT metadata assets.
- Deploy script → atlas program: deploys · Deploys the on-chain program.
- Program tests → atlas program: verifies · Exercises instructions and PDA transitions.
- World scene → World state: syncs · Reflects persistent world availability in gameplay.
- World scene → Character state: syncs · Loads per-wallet progress and character status.
- World scene → Leaderboard: syncs · Displays global competition state.
- App page → Anchor client: orchestrates · Coordinates UI actions with chain requests.
