# appflowy-io/appflowy-cloud architecture

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

- Interactive diagram: https://gitdiagram.com/appflowy-io/appflowy-cloud
- Repository: https://github.com/appflowy-io/appflowy-cloud

## Overview

##### Main Components
- Frontend:
- The “admin_frontend” directory is the dedicated admin interface. It contains assets, template files, and its own Dockerfile and Cargo configuration. This represents the user-facing web app for administration and dashboard purposes.
- Backend Services:
- Core Server Application: The “src” directory houses the main API endpoints (e.g., /api/access_request.rs, /api/user.rs, /api/ws.rs) that serve RESTful and WebSocket endpoints.
- Microservices: Under the “services” directory, there are at least two key services:
– appflowy-collaborate: Handles real-time communication, collaboration logic, and synchronization using Actix WebSocket and various sub-modules (collab, group, snapshot, etc.).
– appflowy-worker: Handles background tasks such as email notifications, indexing, file imports, and data processing.
- Shared Libraries (libs):
- The “libs” folder contains many sub-crates (e.g., authentication, client-api, database, mailer, access-control, etc.) that encapsulate domain logic and infrastructural functionality shared across different parts of the system.
- Infrastructure & External Integrations:
- Database: The project uses PostgreSQL. Migrations are maintained in the “migrations” directory.
- Storage: Minio is referenced for file storage.
- Caching & Message Queues: Redis is used, as hinted by debugging instructions and scripts.
- Real-time and collaboration protocols: There are dedicated libraries for WebSocket interactions and real-time collaboration (e.g., client-websocket, collab-rt-entity).
- External Tools: PgAdmin, Portainer, and a debug-friendly Nginx reverse proxy (from the nginx folder and Docker files) are also in play.

##### Relationships and Interactions
- The admin frontend interacts with the backend APIs to manage user sessions, authentication, and administration tasks.
- The main server (in “src” and core libraries) communicates with the microservices via defined API endpoints and/or WS protocols.
- The appflowy-collaborate service manages real-time communication with clients via WebSockets, using shared libraries for consistent data formats.
- The appflowy-worker processes asynchronous jobs (indexing, email notifications, file processing) and interacts with the database, object storage, and external messaging queues.
- The shared libraries are used across these components to enforce consistent business logic, authentication (libs/authentication), and error handling (libs/app-error).

##### Architectural Patterns and Design Principles
- Modular Design and Microservice Architecture: Separation between frontend, backend APIs, and independent worker processes.
- Domain-driven / layered design: Business logic is encapsulated in “biz” modules and shared crates.
- Real-time Data Flow: Use of WebSocket components in both the API layer and dedicated real-time collaboration libraries.
- Infrastructure-as-Code: Multiple Docker Compose files, Dockerfiles, and scripts ease deployment and testing.
- Testing: A wide range of tests (unit tests in “tests”, integration tests in “services/*/tests”) ensures each module and service works as expected.

##### Technologies and Frameworks
- Rust as the main programming language.
- Actix Web and Actix WebSocket for backend API and real-time communications.
- sqlx for database connectivity and migration management.
- Docker for containerizing services.
- External integrations include PgAdmin for Postgres, Redis CLI, Minio for storage, and Portainer for container management.

## Diagram (Mermaid)

```mermaid
flowchart TD

    subgraph "User Interface Layer"
        A["Admin Frontend (Admin UI)"]:::frontend
    end

    subgraph "Backend Services"
        B["Core Server Application (API)"]:::backend
        C["Collaborate Microservice (Real-Time)"]:::microservice
        D["Worker Microservice (Background)"]:::microservice
    end

    subgraph "Shared Libraries"
        E["Shared Libraries (Domain & Auth)"]:::library
        F["Client-WebSocket Library"]:::library
    end

    subgraph "Infrastructure & External Systems"
        G["PostgreSQL Database (Migrations)"]:::database
        H["Minio (Object Storage)"]:::external
        I["Redis (Caching/Queues)"]:::external
        J["Nginx (Reverse Proxy)"]:::external
        K["PgAdmin (DB Tool)"]:::external
        L["Portainer (Container Mgmt)"]:::external
    end

    A -->|"calls"| B
    B -->|"uses"| E
    B -->|"ws_comm"| F
    B <-->|"ws_sync"| C
    C -->|"uses"| E
    C -->|"ws_comm"| F
    B -->|"jobs"| D
    D -->|"uses"| E
    B -->|"db_access"| G
    D -->|"db_access"| G
    D -->|"caching"| I
    A -->|"retrieves"| H
    J -->|"proxies"| A
    J -->|"proxies"| B
    K ---|"manages"| G
    L ---|"manages"| G

    classDef frontend fill:#AED6F1,stroke:#1B4F72,color:#000;
    classDef backend fill:#FAD7A0,stroke:#9A7D0A,color:#000;
    classDef microservice fill:#D5F5E3,stroke:#1E8449,color:#000;
    classDef library fill:#F9E79F,stroke:#B7950B,color:#000;
    classDef database fill:#F5B7B1,stroke:#922B21,color:#000;
    classDef external fill:#D6EAF8,stroke:#2874A6,color:#000;

    click A "https://github.com/appflowy-io/appflowy-cloud/tree/main/admin_frontend"
    click B "https://github.com/appflowy-io/appflowy-cloud/tree/main/src"
    click C "https://github.com/appflowy-io/appflowy-cloud/tree/main/services/appflowy-collaborate"
    click D "https://github.com/appflowy-io/appflowy-cloud/tree/main/services/appflowy-worker"
    click E "https://github.com/appflowy-io/appflowy-cloud/tree/main/libs"
    click F "https://github.com/appflowy-io/appflowy-cloud/tree/main/libs/client-websocket"
    click G "https://github.com/appflowy-io/appflowy-cloud/tree/main/migrations"
    click H "https://github.com/appflowy-io/appflowy-cloud/tree/main/admin_frontend/assets/minio"
    click I "https://github.com/appflowy-io/appflowy-cloud/tree/main/script/redis"
    click J "https://github.com/appflowy-io/appflowy-cloud/tree/main/nginx"
    click K "https://github.com/appflowy-io/appflowy-cloud/tree/main/docker/pgadmin"
    click L "https://github.com/appflowy-io/appflowy-cloud/tree/main/docker/portainer"
```
