# dojoengine/dojo architecture

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

- Interactive diagram: https://gitdiagram.com/dojoengine/dojo
- Repository: https://github.com/dojoengine/dojo

## Overview

##### Main components
- Core Framework & Libraries: These are located in the “crates/dojo” directory (dojo/core, dojo/lang, dojo/types, dojo/utils, dojo/world, etc.). They constitute the fundamental abstractions, language extensions, and smart contract interfaces needed for provable applications.
- Smart Contract and Blockchain Components: Contracts and chain specifications are spread across directories like “crates/katana/contracts”, “crates/dojo/core/src/contract”, “crates/dojo/world/src/contracts”, and various “Scarb.toml” files that manage contract building. These components focus on the provable and verifiable aspects of onchain computation.
- API and Integration Layers: Tools for interacting with the blockchain (RPC endpoints, gRPC services, GraphQL), as well as indexers (e.g., torii under crates/torii, katana’s RPC components) that fetch, process, and serve blockchain data.
- Developer Tools & Infrastructure: These include the devcontainer definitions, CI/CD workflows (.github/workflows), testing benches, xtask generators, and various scripts that support building, formatting, testing, and deploying both Cairo contracts and Rust binaries.

##### Relationships and interactions
- The CLI tools (katana, sozo, torii) serve as the primary entry points for developers. They interact with the core libraries (dojo/core, dojo/lang, dojo/types, etc.) and with smart contract code deployed on-chain.
- The smart contract modules written in Cairo form the secure “backend” which is provable and are built and managed using the Scarb/Cargo configurations. They interact with blockchain data layers provided by components like storage providers (see “crates/katana/storage” and “crates/dojo/world”).
- The API layers (RPC, gRPC, GraphQL) are designed to serve external requests and facilitate communication between onchain contracts and offchain applications.
- The indexer and messaging layers (present in directories like “crates/katana/indexer” and messaging-related folders) process events and data between the decentralized contracts and user-facing applications.
- Supporting developer infrastructure (CI definitions, scripts, examples) helps integrate, test, and deploy the system both locally (via devcontainer, xtask) and in production.

##### Important architectural patterns and technologies
- Modularity and separation of concerns: The project is split into many small, composable crates and binaries. This emphasizes a plugin-like architecture where extensions (e.g., language bindgen, blockchain integrations) are clearly separated and configurable.
- Layered architecture: At the lowest layer, smart contracts and core libraries implement the provable computation; above that are CLI tools and APIs that orchestrate interactions. Finally, integration and developer-experience tools sit at the outer layer.
- Use of Rust (with Cargo) for tooling and backend libraries; use of Cairo for on-chain smart contracts.
- CI/CD, testing benches, and developer container support create an environment that validates both offchain and onchain code.

##### Elements
- Clear labels for each main subsystem:
- Core Libraries (dojo/core, dojo/lang, dojo/types, etc.)
- Smart Contracts (Dojo contracts and chain-spec components)
- CLI Tools (katana, sozo, torii, language server)
- API Layers (RPC, GraphQL, gRPC to facilitate blockchain interactions)
- Developer Infrastructure (CI workflows, scripts, devcontainers, examples)
- CLI → Core Libraries
- Core Libraries → Smart Contracts (deployment/build & migration)
- API Services ↔ Indexers ↔ Blockchain nodes/storage
- Annotations of key technologies (Cargo, Scarb, Rust, Cairo) near related components

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% CLI Tools Subgraph
    subgraph "CLI Tools"
        DSL["Dojo Language Server"]:::rust
        KC["Katana CLI"]:::rust
        SC["Sozo CLI"]:::rust
        TC["Torii CLI"]:::rust
    end

    %% Core Framework & Libraries Subgraph
    subgraph "Core Framework & Libraries"
        DCL["Dojo Core Libraries"]:::rust
    end

    %% Smart Contracts Subgraph
    subgraph "Smart Contracts (Cairo)"
        KCn["Katana Contracts"]:::cairo
        DCC["Dojo Core Contracts"]:::cairo
        DWC["Dojo World Contracts"]:::cairo
    end

    %% API & Integration Layers Subgraph
    subgraph "API & Integration Layers"
        RPC["RPC API"]:::infra
        GQL["GraphQL API"]:::infra
        IDX["Indexer"]:::infra
    end

    %% Developer Tools & Infrastructure Subgraph
    subgraph "Developer Tools & Infrastructure"
        DEV["Devcontainer"]:::dev
        CICD["CI/CD Workflows"]:::dev
        XTS["Xtask Build Scripts"]:::dev
        SCR["Scripts"]:::dev
    end

    %% Connections between CLI Tools and Core Libraries
    DSL -->|"invokes"| DCL
    KC -->|"invokes"| DCL
    SC -->|"invokes"| DCL
    TC -->|"invokes"| DCL

    %% Connections between Core Libraries and Smart Contracts
    DCL -->|"builds"| KCn
    DCL -->|"builds"| DCC
    DCL -->|"builds"| DWC

    %% Connections from Smart Contracts to API & Integration Layers
    KCn -->|"exposes"| RPC
    DWC -->|"exposes"| RPC
    DCC -->|"emits"| IDX

    %% Interactions within API & Integration Layers
    RPC -- "data" --> IDX
    IDX -- "queries" --> GQL

    %% Developer Tools supporting CLI Tools and Core Libraries
    DEV ---|"configures"| DSL
    CICD ---|"deploys"| KC
    XTS ---|"builds"| DCL
    SCR ---|"scripts"| DCL

    %% Styling Classes
    classDef rust fill:#AED6F1,stroke:#1B4F72,stroke-width:2px;
    classDef cairo fill:#FAD7A0,stroke:#B9770E,stroke-width:2px;
    classDef infra fill:#D2B4DE,stroke:#6C3483,stroke-width:2px;
    classDef dev fill:#82E0AA,stroke:#1E8449,stroke-width:2px;

    %% Click Events for CLI Tools
    click DSL "https://github.com/dojoengine/dojo/tree/main/bin/dojo-language-server"
    click KC "https://github.com/dojoengine/dojo/tree/main/bin/katana"
    click SC "https://github.com/dojoengine/dojo/tree/main/bin/sozo"
    click TC "https://github.com/dojoengine/dojo/tree/main/bin/torii"

    %% Click Event for Core Framework & Libraries
    click DCL "https://github.com/dojoengine/dojo/tree/main/crates/dojo"

    %% Click Events for Smart Contracts
    click KCn "https://github.com/dojoengine/dojo/tree/main/crates/katana/contracts"
    click DCC "https://github.com/dojoengine/dojo/tree/main/crates/dojo/core/src/contract"
    click DWC "https://github.com/dojoengine/dojo/tree/main/crates/dojo/world/src/contracts"

    %% Click Events for API & Integration Layers
    click RPC "https://github.com/dojoengine/dojo/tree/main/crates/katana/rpc"
    click GQL "https://github.com/dojoengine/dojo/tree/main/crates/torii/graphql"
    click IDX "https://github.com/dojoengine/dojo/tree/main/crates/torii/indexer"

    %% Click Events for Developer Tools & Infrastructure
    click DEV "https://github.com/dojoengine/dojo/blob/main/.devcontainer"
    click CICD "https://github.com/dojoengine/dojo/tree/main/.github/workflows"
    click XTS "https://github.com/dojoengine/dojo/tree/main/xtask"
    click SCR "https://github.com/dojoengine/dojo/tree/main/scripts"
```
