# daimo-eth/daimo architecture

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

- Interactive diagram: https://gitdiagram.com/daimo-eth/daimo
- Repository: https://github.com/daimo-eth/daimo

## Overview

##### Major Components
- Mobile App – under apps/daimo-mobile. This is a React Native/Expo project that includes both a native layer (for interfacing with device hardware like the secure enclave for key management) and a Typescript React Native layer (UI, navigation, and business logic).
- Web App – under apps/daimo-web. It is a NextJS project that displays deep links, onboarding, and web functionalities.
- API Server – under packages/daimo-api. A Node/TypeScript application that runs a TRPC API, handles business logic, integrates with a Postgres database (and an indexer) and interacts with blockchain contracts.
- Smart Contracts – under packages/contract (and also daimo-contract). These consist of Solidity contracts built with Forge. They implement ERC-4337 account abstraction along with additional functionality such as account factories, paymaster, and the contract wallet.
- Common Code/Models – under packages/daimo-common. This layer encapsulates shared data models and utilities that are used across the mobile app, web app, and API.
- Hardware Enclave & Passkeys – represented by packages/daimo-expo-enclave and packages/daimo-expo-passkeys. These integrate native modules (in Kotlin/Swift) with the Expo ecosystem to facilitate secure key storage and crypto operations.
- User Operation Logic – in packages/daimo-userop for account abstraction handling (helps build and send “user ops” for transactions).
- Testing & CI/CD – tools like Maestro (with configuration files in apps/daimo-mobile/.maestro), GitHub workflows (.github/workflows), and various test folders (for example, in apps/daimo-mobile/test) indicate automated end-to-end testing.
- Auxiliary Tools – a scratchpad app, documentation, auditing reports (PDFs under audits), and more to support rapid development and diagnostics.

##### Out the Relationships and Interactions
- Clients (mobile and web) are the primary interfaces. They send requests (transactions or API calls) to the backend.
- The mobile app communicates with the API on localhost:3000 (or via a hosted API), and it also might take direct actions with the local hardware (via the expo-enclave/passkeys modules) to sign transactions.
- The API (daimo-api) serves as a bridge between the user-facing apps and the blockchain. It processes requests, performs validations, queries the database, and interacts with smart contracts.
- Smart contracts are deployed on the Base blockchain and manage account abstraction (ERC-4337 functionality). They are called by both the API and sometimes directly by the clients.
- Shared libraries in daimo-common ensure consistency in data models, cryptographic functions, and configuration between the various parts.
- CI/CD, testing (e.g., Maestro for mobile tests) and audit artifacts ensure that the high level of security and quality is maintained across releases.

##### Important Architectural Patterns and Technologies
- Full-Stack Separation: Clear distinction among client (mobile/web), API/backend, and blockchain contract layers.
- Micro-modular Design: Each major function is split into packages (API, contracts, common utilities, enclave interfaces, and user op building) that interact via well-defined interfaces.
- Secure and Non-Custodial Design: Emphasizing client device key storage inside secure enclaves and leveraging passkeys for authentication.
- Account Abstraction (ERC-4337): The smart contracts implement advanced wallet functionalities.
- Infrastructure & DevOps: Presence of CI/CD pipelines, automated testing (Maestro and GitHub workflows), and Foundry tooling for contract development.

##### Final Checklist
- Every component (mobile app, web app, API, blockchain contracts, shared libraries, testing frameworks) is present and clearly labeled.
- Element with technology stack information (e.g., Typescript, Expo, NextJS, Solidity, Foundry, etc.).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client Layer
    subgraph "Client Layer"
        MA["Mobile App (Expo+React Native)"]:::client
        HE["Hardware Enclave (Native Module)"]:::client
        PK["Passkeys (Native Module)"]:::client
        WA["Web App (NextJS)"]:::client
    end

    %% Backend Layer
    subgraph "Backend Layer"
        API["API Server (TRPC, Node/TypeScript)"]:::backend
        UO["User Operation Logic (Account Abstraction)"]:::backend
        DB["Postgres DB"]:::backend
        IX["Blockchain Indexer"]:::backend
    end

    %% Blockchain Layer
    subgraph "Blockchain Layer"
        SC1["Smart Contracts (Solidity+Forge)"]:::blockchain
        SC2["Smart Contracts - Additional (Solidity+Forge)"]:::blockchain
    end

    %% Shared Libraries
    COMMON["Common Code/Models (Shared)"]:::shared

    %% DevOps Layer
    subgraph "DevOps & Testing"
        MAES["Maestro (Mobile Testing)"]:::auxiliary
        GH["GitHub Workflows (CI/CD)"]:::auxiliary
    end

    %% Data flow
    MA -->|"APIcalls"| API
    WA -->|"APIcalls"| API

    API -->|"Queries"| DB
    API -->|"Monitors"| IX
    API -->|"Builds UserOps"| UO
    API -->|"Invokes"| SC1
    API -->|"Invokes"| SC2

    MA ---|"Direct Blockchain Calls"| SC1
    MA ---|"Direct Blockchain Calls"| SC2

    MA -->|"Uses"| HE
    MA -->|"Uses"| PK

    MA ---|"Uses"| COMMON
    WA ---|"Uses"| COMMON
    API ---|"Uses"| COMMON

    %% DevOps supports
    MAES ---|"Tests"| MA
    GH ---|"Deploys and Tests"| API

    %% Class definitions for colors
    classDef client fill:#d0e9ff,stroke:#0277bd,stroke-width:2px;
    classDef backend fill:#dcedc8,stroke:#558b2f,stroke-width:2px;
    classDef blockchain fill:#fff9c4,stroke:#f9a825,stroke-width:2px;
    classDef shared fill:#ffe0b2,stroke:#ef6c00,stroke-width:2px;
    classDef auxiliary fill:#e1bee7,stroke:#6a1b9a,stroke-width:2px;

    %% Click Events
    click MA "https://github.com/daimo-eth/daimo/tree/master/apps/daimo-mobile"
    click WA "https://github.com/daimo-eth/daimo/tree/master/apps/daimo-web"
    click API "https://github.com/daimo-eth/daimo/tree/master/packages/daimo-api"
    click SC1 "https://github.com/daimo-eth/daimo/tree/master/packages/contract"
    click SC2 "https://github.com/daimo-eth/daimo/tree/master/packages/daimo-contract"
    click COMMON "https://github.com/daimo-eth/daimo/tree/master/packages/daimo-common"
    click HE "https://github.com/daimo-eth/daimo/tree/master/packages/daimo-expo-enclave"
    click PK "https://github.com/daimo-eth/daimo/tree/master/packages/daimo-expo-passkeys"
    click UO "https://github.com/daimo-eth/daimo/tree/master/packages/daimo-userop"
    click MAES "https://github.com/daimo-eth/daimo/blob/master/apps/daimo-mobile/.maestro"
    click GH "https://github.com/daimo-eth/daimo/tree/master/.github/workflows"
```
