# cashierhq/cashier architecture

> Architecture diagram of the GitHub repository cashierhq/cashier, 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/cashierhq/cashier
- Repository: https://github.com/cashierhq/cashier

## Overview

##### Main Components
a. Cashier Backend Canister – Located in src/cashier_backend; this is the Rust canister containing various modules (actions, claims, links, users, transaction management, etc.) that encapsulate the core business logic.
b. Token Storage/Token Canister – Found in src/token_storage; it represents another canister (or service) handling token-related functionalities, with its own API and repository.
c. Cashier Frontend – Found in src/cashier_frontend; this is a client-side application built with modern web technologies (React components, Vite, ESLint configuration) that interacts with the canisters on the Internet Computer.
d. Shared Libraries – Located in src/lib (cashier-macros and cashier-types); these libraries provide shared definitions, types, and macros that aid in keeping consistency between canister interfaces and other modules.
e. Testing Framework – Two distinct testing areas exist:
- Integration Tests (in src/test) that mimic real canister deployments (generating artifacts like cashier_backend.wasm.gz and token_canister.wasm.gz, replicating the blockchain behavior, and interacting via DFX configuration).
- Unit Tests within Rust modules (in __tests__ folders) that simulate canister behavior using tokio and MockIcEnviroment.

##### Interactions and Relationships
c. Shared Libraries Usage – Both the backend and token storage canisters rely on common libraries (macros and types); indicate these as a shared component used by multiple parts of the system.

##### Architectural Patterns and Technologies
a. Separation of Concern – There is a clear boundary between frontend and backend (with separate directories and framework stacks), and further separation within the backend (modules for actions, claims, transactions, etc.), which is an instance of modular design.
b. Microservices-like Canister Architecture – Each canister (backend and token storage) runs independently on the Internet Computer, communicating via inter-canister calls.
d. Technologies Identified – Rust (for canister backend), WebAssembly (WASM binaries like cashier_backend.wasm.gz and token_canister.wasm.gz), and modern web frameworks (React, Vite) for the frontend. Note the use of Dfinity’s configuration files (dfx.json, canister_ids.json) to highlight that these components are meant to run on the Internet Computer blockchain.

##### Final Overview
– All major components and their responsibilities.
– Separation between production code (frontend, backend, token storage) and auxiliary constructs (shared libraries, tests, CI/CD pipelines).
– Annotation of deployment specifics (local vs staging) and testing strategies.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Frontend Layer"
        FE["Cashier Frontend"]:::frontend
    end

    subgraph "Backend Canisters"
        BE["Cashier Backend Canister"]:::backend
        TS["Token Storage Canister"]:::backend
    end

    subgraph "Shared Libraries"
        Macro["Macros"]:::library
        Types["Types"]:::library
    end

    subgraph "Testing & Deployment"
        IT["Integration Tests"]:::testing
        UT_Core["Unit Tests (Core)"]:::testing
        UT_Serv["Unit Tests (Services)"]:::testing
        CICD["CI/CD & Deployment Pipelines"]:::deployment
    end

    FE -->|"API_calls"| BE
    BE -->|"Delegates"| TS
    BE -->|"Uses"| Macro
    BE -->|"Uses"| Types
    TS -->|"Uses"| Macro
    TS -->|"Uses"| Types
    IT -->|"Simulate"| BE
    UT_Core -->|"Test"| BE
    UT_Serv -->|"Test"| BE
    CICD -->|"Deploys"| BE
    CICD -->|"Deploys"| TS

    click BE "https://github.com/cashierhq/cashier/tree/staging/src/cashier_backend"
    click TS "https://github.com/cashierhq/cashier/tree/staging/src/token_storage"
    click FE "https://github.com/cashierhq/cashier/tree/staging/src/cashier_frontend"
    click Macro "https://github.com/cashierhq/cashier/tree/staging/src/lib/cashier-macros"
    click Types "https://github.com/cashierhq/cashier/tree/staging/src/lib/cashier-types"
    click IT "https://github.com/cashierhq/cashier/tree/staging/src/test"
    click UT_Core "https://github.com/cashierhq/cashier/tree/staging/src/cashier_backend/src/core/__tests__"
    click UT_Serv "https://github.com/cashierhq/cashier/tree/staging/src/cashier_backend/src/services/__tests__"
    click CICD "https://github.com/cashierhq/cashier/tree/staging/.github/workflows"

    classDef frontend fill:#f9f,stroke:#333,stroke-width:2px;
    classDef backend fill:#ccf,stroke:#333,stroke-width:2px;
    classDef library fill:#cfc,stroke:#333,stroke-width:2px;
    classDef testing fill:#fcf,stroke:#333,stroke-width:2px;
    classDef deployment fill:#cff,stroke:#333,stroke-width:2px;
```
