# safe-global/safe-wallet-monorepo architecture

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

- Interactive diagram: https://gitdiagram.com/safe-global/safe-wallet-monorepo
- Repository: https://github.com/safe-global/safe-wallet-monorepo

## Overview

This repository is a sophisticated monorepo for Safe{Wallet} that contains multiple workspaces (apps and packages) managed by Yarn Workspaces. The core components include:

##### Apps
- The web application (in apps/web), built with Next.js and React, serves as the primary user interface for desktop users.
- The mobile application (in apps/mobile) uses Expo (thus React Native) to serve mobile platforms.
- Both apps share similar design principles like testing (Jest, Cypress) and linting/formatting.

##### Packages
- Shared libraries such as “packages/store” and “packages/utils” provide state management, common utilities, and shared business logic.
- These packages abstract shared functionality, making it reusable across the different apps in the monorepo.

##### Configuration & Tooling
- The “config” directory and various scripts within the repository (e.g., GitHub actions workflows, husky hooks) manage CI/CD, linting, testing, and deployment.
- Yarn Workspaces are leveraged to coordinate dependency management and script execution across the apps and packages.

##### Additional Elements
- A rich testing infrastructure exists (with unit tests, end-to-end tests, storybook, etc.) ensuring quality throughout.
- There are various third-party integrations (Expo for mobile, Next.js for web, analytics, push notifications, etc.) that can be noted as external services/components.

- “Safe{Wallet} Web App” (Next.js/React) – Represented as a primary frontend component.
- “Safe{Wallet} Mobile App” (Expo/React Native) – Another standalone frontend component.
- “Shared Packages & Libraries” – Group together packages like “store” (state management, API interfaces) and “utils” (utilities, common functions).
- “Configuration/Tooling” – This can be a smaller section that encompasses CI/CD workflows (GitHub Actions), scripts, pre-commit hooks (Husky/ESLint/Prettier), and Yarn’s workspace management.

B. Show the relationships and interactions:
- That both apps rely upon a common “state management” layer (from the packages/store) and domain-specific utilities (from packages/utils).
- Data flows from users interacting with the apps that, in turn, communicate with external APIs or blockchain services through these shared packages.

C. Highlight architectural patterns and design principles:
- Monorepo structure with Yarn Workspaces for dependency management and unified versioning.
- Separation of concerns: distinct apps for web and mobile, with shared libraries for business logic and common code.
- Emphasis on testing and continuous integration using GitHub Actions and pre-commit hooks.
- Usage of modern frameworks (Next.js and Expo) that provide their own internal abstraction layers.

D. Incorporate key technologies and frameworks:
- Next.js, React, and TypeScript for the web frontend.
- Expo/React Native for the mobile frontend.
- Yarn Workspaces, ESLint, Prettier, Jest, and Cypress integrated as part of the development and deployment workflow.
- Shared packages utilizing modern JavaScript/TypeScript patterns and possibly core SDK integrations for blockchain interactions (e.g., safeCoreSDK provided in hooks and services).

- Optionally, include a section for GitHub workflows (e.g., “cypress tests”, “release pipelines”, “mobile deployment”) to showcase the DevOps workflow.

F. Final guidelines:
- Notable technologies next to their respective components (e.g., “Next.js + React” for the web, “Expo” for mobile, “Yarn Workspaces” for repository management).
- If there are any APIs or blockchain communication modules (for signing transactions, notifications, etc.), note them as external connectors.

## Diagram (Mermaid)

```mermaid
flowchart TD

    %% Applications Subgraph
    subgraph "Applications"
        WEB["Safe{Wallet} Web App (Next.js+React)"]:::web
        MOBILE["Safe{Wallet} Mobile App (Expo/ReactNative)"]:::mobile
    end

    %% Shared Packages & Libraries Subgraph
    subgraph "Shared Packages & Libraries"
        STORE["Store (State Management)"]:::shared
        UTILS["Utils (Common Utilities)"]:::shared
    end

    %% Configuration & Tooling Subgraph
    subgraph "Configuration & Tooling"
        GITHUB["GitHub Actions (.github)"]:::config
        CONFIG["Config Files (config)"]:::config
        HUSKY["Husky Hooks (husky)"]:::config
    end

    %% Testing Infrastructure Subgraph
    subgraph "Testing Infrastructure"
        WEBTEST["Web Tests"]:::test
        MOBILETEST["Mobile Tests"]:::test
        CONFIGTEST["Config Tests"]:::test
    end

    %% External Services Node
    EXT["Third Party Services (Analytics,PushNotifications,safeCoreSDK)"]:::external

    %% Relationships
    WEB -->|"uses"| STORE
    WEB -->|"uses"| UTILS
    MOBILE -->|"uses"| STORE
    MOBILE -->|"uses"| UTILS

    STORE -->|"communicates"| EXT
    UTILS -->|"communicates"| EXT

    GITHUB -->|"deploys"| WEB
    GITHUB -->|"deploys"| MOBILE
    GITHUB -->|"deploys"| STORE
    GITHUB -->|"deploys"| UTILS

    CONFIG -->|"configures"| WEB
    CONFIG -->|"configures"| MOBILE
    CONFIG -->|"configures"| STORE
    CONFIG -->|"configures"| UTILS

    WEBTEST -->|"validates"| WEB
    MOBILETEST -->|"validates"| MOBILE
    CONFIGTEST -->|"validates"| CONFIG

    %% Click Events
    click WEB "https://github.com/safe-global/safe-wallet-monorepo/tree/dev/apps/web"
    click MOBILE "https://github.com/safe-global/safe-wallet-monorepo/tree/dev/apps/mobile"
    click STORE "https://github.com/safe-global/safe-wallet-monorepo/tree/dev/packages/store"
    click UTILS "https://github.com/safe-global/safe-wallet-monorepo/tree/dev/packages/utils"
    click GITHUB "https://github.com/safe-global/safe-wallet-monorepo/blob/dev/.github"
    click CONFIG "https://github.com/safe-global/safe-wallet-monorepo/tree/dev/config"
    click HUSKY "https://github.com/safe-global/safe-wallet-monorepo/tree/dev/husky"
    click WEBTEST "https://github.com/safe-global/safe-wallet-monorepo/tree/dev/apps/web/src/tests"
    click MOBILETEST "https://github.com/safe-global/safe-wallet-monorepo/tree/dev/apps/mobile/tests"
    click CONFIGTEST "https://github.com/safe-global/safe-wallet-monorepo/tree/dev/config/test"

    %% Styles
    classDef web fill:#add8e6,stroke:#000,stroke-width:2px;
    classDef mobile fill:#90ee90,stroke:#000,stroke-width:2px;
    classDef shared fill:#ffdab9,stroke:#000,stroke-width:2px;
    classDef config fill:#d3d3d3,stroke:#000,stroke-width:2px;
    classDef test fill:#fdfd96,stroke:#000,stroke-width:2px;
    classDef external fill:#ffa07a,stroke:#000,stroke-width:2px,shape:cylinder;
```
