How dojoengine/dojo works
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