# appflowy-io/appflowy-web architecture

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

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

## Overview

##### Main Components
- User Interface (Frontend)
– Indicate the rich modular structure (e.g., components/app, components/global-comment, components/ai-chat, etc.) and emphasize how each of these modules contributes to overall user interaction.
- Application / Domain Layer
– Represent the “Application” logic that is in the src/application folder. This includes domain elements such as:
- Collaborative editing (handled by modules like slate-yjs and ydoc for real-time updates),
- Database operations (interfacing with AppFlowy Cloud and abstracted in src/application/db),
- Session, authentication, and publishing functionalities.
– Highlight support for different field types (text, number, relation, select-option, etc.) that facilitate creating rich documents.
- Services and Utilities Layer
– Show “Utility” modules (src/utils, src/lib) that support features such as logging, file handling, theming, and more.
- External Integration and Backend Connectivity
– Create a component for “AppFlowy Cloud” which is an external service providing the backend API (the README describes this dependency, particularly for authentication, database sync, and collaboration).
- Deployment & Infrastructure
– Include a “Deployment” section detailing Docker, Nginx, and the server files found under deploy/. This shows how the application is containerized and deployed.
– Optionally note the CI/CD pipelines (GitHub workflows under .github/workflows) which automate building, testing, and deploying the project.
- Testing & Quality Assurance
– Represent testing layers such as Cypress (end-to-end tests in cypress/), Jest (jest.config.cjs), and other mock files (__mocks__) which assure quality and stability.

##### Relationships and Data Flows
- That interactions trigger application logic in the domain layer (e.g., writing in the editor sends signals through collaborative services like Yjs).
- How API calls flow from the application’s services layer to the AppFlowy Cloud backend.

##### Architectural Patterns & Design Principles
- Separation of concerns through a layered architecture (UI, application/domain, services/integration).
- Use of modular component design (React components organized into domain-specific folders).
- Use of collaborative editing patterns (real-time syncing using Yjs and integration with Slate).
- Standard front-end patterns such as context providers (e.g., for session management and global state) and utility abstractions.

##### Relevant Technologies and Frameworks
- React and TypeScript for the frontend.
- Yjs and Slate for real-time, collaborative editing.
- Docker & Nginx for containerization and deployment.
- Testing frameworks like Cypress and Jest.
- Node.js-based services (as indicated by scripts and server.ts in deploy/).

## Diagram (Mermaid)

```mermaid
flowchart TD
    U["User"]:::external

    subgraph "Presentation Layer (React UI)"
        A["Editor Interface"]:::frontend
        B["Database Views"]:::frontend
        C["Global Comments Module"]:::frontend
        D["Login Module"]:::frontend
        E["Publish Module"]:::frontend
    end

    subgraph "Application/Domain Layer"
        F["Core Application Logic"]:::app
        G["Collaborative Editing (Slate-Yjs)"]:::app
        H["Database Operations"]:::app
        I["Session & Authentication"]:::app
        J["Publishing Functionality"]:::app
    end

    subgraph "Services & Utilities"
        K["Services Implementation"]:::services
        L["JS Services"]:::services
        M["Utility Modules"]:::services
        N["Library Modules"]:::services
    end

    O["AppFlowy Cloud API"]:::external

    subgraph "Deployment & Infrastructure"
        P["Deployment Scripts & Configurations"]:::deployment
        Q["CI/CD Pipelines"]:::deployment
    end

    subgraph "Testing & Quality Assurance"
        R["End-to-End Tests"]:::testing
        S["Unit Testing"]:::testing
    end

    %% User flow to Presentation Layer
    U -->|"uses"| A

    %% Presentation Layer interactions with Application/Domain Layer
    A -->|"triggers"| G
    A -->|"notifies"| F
    B -->|"fetches"| H
    C -->|"communicates"| F
    D -->|"authenticates"| I
    E -->|"initiates"| J

    %% Application/Domain to Services & Utilities
    F -->|"delegates"| K
    H -->|"queries"| K

    %% Services interactions
    K -->|"syncs with"| O
    K --> L

    %% Deployment flows
    Q --> P

    %% Testing links (dashed lines for QA feedback)
    R -.-> F
    S -.-> F

    %% Styles
    classDef frontend fill:#ADD8E6,stroke:#333,stroke-width:2px;
    classDef app fill:#90EE90,stroke:#333,stroke-width:2px;
    classDef services fill:#FFB6C1,stroke:#333,stroke-width:2px;
    classDef external fill:#FFD700,stroke:#333,stroke-width:2px;
    classDef deployment fill:#DDA0DD,stroke:#333,stroke-width:2px;
    classDef testing fill:#F0E68C,stroke:#333,stroke-width:2px;

    %% Click Events
    click A "https://github.com/appflowy-io/appflowy-web/tree/main/src/components/editor"
    click B "https://github.com/appflowy-io/appflowy-web/tree/main/src/components/database"
    click C "https://github.com/appflowy-io/appflowy-web/tree/main/src/components/global-comment"
    click D "https://github.com/appflowy-io/appflowy-web/tree/main/src/components/login"
    click E "https://github.com/appflowy-io/appflowy-web/tree/main/src/components/publish"
    click F "https://github.com/appflowy-io/appflowy-web/tree/main/src/application"
    click G "https://github.com/appflowy-io/appflowy-web/tree/main/src/application/slate-yjs"
    click H "https://github.com/appflowy-io/appflowy-web/tree/main/src/application/db"
    click I "https://github.com/appflowy-io/appflowy-web/tree/main/src/application/session"
    click J "https://github.com/appflowy-io/appflowy-web/tree/main/src/application/publish"
    click K "https://github.com/appflowy-io/appflowy-web/tree/main/src/application/services"
    click L "https://github.com/appflowy-io/appflowy-web/tree/main/src/application/services/js-services"
    click M "https://github.com/appflowy-io/appflowy-web/tree/main/src/utils"
    click N "https://github.com/appflowy-io/appflowy-web/tree/main/src/lib"
    click P "https://github.com/appflowy-io/appflowy-web/tree/main/deploy/"
    click Q "https://github.com/appflowy-io/appflowy-web/tree/main/.github/workflows"
    click R "https://github.com/appflowy-io/appflowy-web/tree/main/cypress/"
    click S "https://github.com/appflowy-io/appflowy-web/blob/main/jest.config.cjs"
```
