# yorkie-team/yorkie architecture

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

- Interactive diagram: https://gitdiagram.com/yorkie-team/yorkie
- Repository: https://github.com/yorkie-team/yorkie

## Overview

##### Main Components

a) Client Layer:
- Multiple client SDKs (JS, iOS, Android, Go)
- Local document replicas with CRDT support
- Client-side operations (offline editing capability)

b) Server Layer:
- API Server components (/server/rpc)
- Authentication & Authorization (/server/rpc/auth)
- Document synchronization engine (/server/backend/sync)
- Project management (/server/projects)
- Housekeeping services (/server/backend/housekeeping)

c) Storage Layer:
- MongoDB or MemDB support
- Change storage
- Snapshot management
- Document state persistence

##### Key Interactions to Highlight

- Bi-directional sync between clients and server
- Document change propagation
- Authentication flow
- Storage operations
- Background processes

##### Specific Implementation Details

Specialized components:
**┌─────────────────────────────────────────────────────────┐**
- Client Layer                                            │
- ┤
- Document CRDT Implementation                          │
- Local Cache                                          │
- Change Detection & Sync                              │
- ┘

**┌─────────────────────────────────────────────────────────┐**
- Server Layer                                            │
- ┤
- API Services:                                           │
- Document Management                                   │
- Project Management                                    │
- User Management                                       │

- Core Services:                                          │
- Sync Coordinator                                      │
- CRDT Operations                                       │
- Authentication                                        │
- Housekeeping                                         │
- ┘

**┌─────────────────────────────────────────────────────────┐**
- Storage Layer                                           │
- ┤
- Document Store                                        │
- Change History                                        │
- Snapshots                                            │
- User Data                                            │
- ┘

##### Additional Elements

Sections for:
- API Gateway
- Load Balancers
- Monitoring & Metrics
- Security Components
- Background Jobs

##### Notes

Annotations for:
- Scaling considerations
- Security implementations
- Performance optimizations
- High availability setup
- Disaster recovery

## Diagram (Mermaid)

```mermaid
graph TB
    %% Style Definitions
    classDef client fill:#b3d1ff,stroke:#333,stroke-width:2px
    classDef server fill:#90EE90,stroke:#333,stroke-width:2px
    classDef storage fill:#FFB366,stroke:#333,stroke-width:2px
    classDef auth fill:#DDA0DD,stroke:#333,stroke-width:2px
    classDef monitoring fill:#FFD700,stroke:#333,stroke-width:2px
    
    subgraph ClientLayer["Client Layer"]
        SDK["Client SDK"]:::client
        DocOps["Document Operations"]:::client
        CRDT["CRDT Implementation"]:::client
        LocalCache["Local Cache"]:::client
        PresenceSystem["Presence System"]:::client
    end

    subgraph ServerLayer["Server Layer"]
        APIServer["API Server"]:::server
        AuthSystem["Authentication System"]:::auth
        SyncEngine["Document Sync Engine"]:::server
        ProjectMgmt["Project Management"]:::server
        HouseKeeping["Housekeeping Service"]:::server
        DocCore["Document Core"]:::server
        Backend["Server Backend"]:::server
        ChangeMgmt["Change Management"]:::server
    end

    subgraph StorageLayer["Storage Layer"]
        MongoDB[(MongoDB Storage)]:::storage
        MemDB[(In-Memory Storage)]:::storage
        DBSharding["Database Sharding"]:::storage
    end

    subgraph MonitoringLayer["Monitoring Layer"]
        Monitor["Monitoring System"]:::monitoring
    end

    %% Relationships
    SDK --> APIServer
    DocOps --> SyncEngine
    CRDT --> DocCore
    LocalCache --> SyncEngine
    PresenceSystem --> Backend

    APIServer --> AuthSystem
    APIServer --> SyncEngine
    APIServer --> ProjectMgmt
    SyncEngine --> ChangeMgmt
    ChangeMgmt --> MongoDB
    ChangeMgmt --> MemDB
    HouseKeeping --> StorageLayer
    Monitor --> ServerLayer

    %% Click Events
    click SDK "https://github.com/yorkie-team/yorkie/blob/main/client/client.go"
    click DocOps "https://github.com/yorkie-team/yorkie/tree/main/pkg/document/operations"
    click AuthSystem "https://github.com/yorkie-team/yorkie/tree/main/server/rpc/auth"
    click SyncEngine "https://github.com/yorkie-team/yorkie/tree/main/server/backend/sync"
    click ProjectMgmt "https://github.com/yorkie-team/yorkie/tree/main/server/projects"
    click HouseKeeping "https://github.com/yorkie-team/yorkie/tree/main/server/backend/housekeeping"
    click MongoDB "https://github.com/yorkie-team/yorkie/tree/main/server/backend/database/mongo"
    click MemDB "https://github.com/yorkie-team/yorkie/tree/main/server/backend/database/memory"
    click CRDT "https://github.com/yorkie-team/yorkie/tree/main/pkg/document/crdt"
    click APIServer "https://github.com/yorkie-team/yorkie/tree/main/server/rpc"
    click ChangeMgmt "https://github.com/yorkie-team/yorkie/tree/main/pkg/document/change"
    click PresenceSystem "https://github.com/yorkie-team/yorkie/tree/main/pkg/document/presence"
    click DocCore "https://github.com/yorkie-team/yorkie/blob/main/pkg/document/document.go"
    click Backend "https://github.com/yorkie-team/yorkie/tree/main/server/backend"
    click Monitor "https://github.com/yorkie-team/yorkie/tree/main/build/charts/yorkie-monitoring"
    click DBSharding "https://github.com/yorkie-team/yorkie/tree/main/build/docker/sharding"

    %% Legend
    subgraph Legend
        Client["Client Component"]:::client
        Server["Server Component"]:::server
        Storage["Storage Component"]:::storage
        Auth["Auth Component"]:::auth
        Monitoring["Monitoring Component"]:::monitoring
    end
```
