# streetwriters/notesnook-sync-server architecture

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

- Interactive diagram: https://gitdiagram.com/streetwriters/notesnook-sync-server
- Repository: https://github.com/streetwriters/notesnook-sync-server

## Overview

##### Main Components
- Streetwriters.Identity – This service acts as the Identity Server. It manages user accounts, multi-factor authentication (MFA), account signups, and other authentication-related features. Notice many controllers (AccountController, MFAController, SignupController) and supporting services (TokenGenerationService, MFAService).
- Streetwriters.Messenger – This service provides the messaging infrastructure, including server-sent events (SSE) and heartbeat signaling. It is responsible for the real-time push or notification mechanisms.
- External dependencies – The README and docker-compose indicate dependencies such as MongoDB (for data storage) and Minio (for S3-compatible storage). Include these as external components that are critical to the system’s operation.

##### Out the Relationships
- Clients (e.g., the Notesnook client apps) will interface with one or more of these services. You want to show separate communication channels:
- Clients communicate with Notesnook.API for sync operations.
- Authentication/authorization flows pass through the Streetwriters.Identity service.
- Real-time notifications and server-sent event flows are managed by Streetwriters.Messenger.
- That Notesnook.API is likely a consumer of the MongoDB database (via Streetwriters.Data) for storing sync data and possibly also communicating with Minio/S3 for file or object storage.
- The Identity service similarly interacts with MongoDB and uses its own helper methods for token generation, email sending, and MFA.
- The Messenger service may also interact with the database or use in-memory/shared state to maintain heartbeat services and message dispatching.

##### Architectural Patterns & Design Principles
- The API project follows a layered (MVC-like) architecture separating Controllers, Models, Services, and Repositories.
- Use of real-time communication (via SignalR hubs and SSE endpoints) and an event-driven messaging design, with components like EventSources and MessageHandlers.

- Main services: Notesnook.API, Streetwriters.Identity, Streetwriters.Messenger.
- Shared libraries: Streetwriters.Common, Streetwriters.Data.
- External resources: MongoDB (document storage) and Minio (or S3-compatible storage).
- Service communications: API endpoints for sync, RESTful endpoints for identity, real-time hubs (SignalR/SSE) for Messenger.

##### Details
- Be explicit with labels for endpoints (e.g., specify that the API uses “Controllers,” “Hubs,” and “Authorization Extensions”).
- Including deployment details (Docker, docker-compose) to show how the orchestrator schedules each container and manages their interactions.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Clients
    Clients("Clients"):::client

    %% Microservices
    subgraph "Microservices"
        API["Notesnook.API (Sync Server)"]:::api
        Identity["Streetwriters.Identity (Identity Server)"]:::identity
        Messenger["Streetwriters.Messenger (Messaging Service)"]:::messenger
    end

    %% Shared Libraries
    subgraph "Shared Libraries"
        Common["Streetwriters.Common"]:::common
        Data["Streetwriters.Data"]:::data
    end

    %% External Dependencies
    subgraph "External Dependencies"
        MongoDB["MongoDB (Data Store)"]:::external
        Minio["Minio (S3 Storage)"]:::external
        Docker["Docker Compose Orchestration"]:::orchestration
    end

    %% Client to Service Communication
    Clients -->|"syncRequests"| API
    Clients -->|"authFlows"| Identity
    Clients -->|"realTimeNotifs"| Messenger

    %% Microservices Dependencies on Shared Libraries and External Resources
    API -->|"uses"| Common
    API -->|"uses"| Data
    API -->|"storesDataIn"| MongoDB
    API -->|"storesFilesIn"| Minio

    Identity -->|"uses"| Common
    Identity -->|"storesUserDataIn"| MongoDB

    Messenger -->|"mayUseDB"| MongoDB

    %% Orchestrator linking services
    Docker --> API
    Docker --> Identity
    Docker --> Messenger

    %% Inter-service Communication
    Identity -->|"emitsEvents"| Messenger

    %% Click Events
    click API "https://github.com/streetwriters/notesnook-sync-server/blob/master/Notesnook.API"
    click Identity "https://github.com/streetwriters/notesnook-sync-server/blob/master/Streetwriters.Identity"
    click Messenger "https://github.com/streetwriters/notesnook-sync-server/blob/master/Streetwriters.Messenger"
    click Common "https://github.com/streetwriters/notesnook-sync-server/blob/master/Streetwriters.Common"
    click Data "https://github.com/streetwriters/notesnook-sync-server/blob/master/Streetwriters.Data"
    click Docker "https://github.com/streetwriters/notesnook-sync-server/blob/master/docker-compose.yml"

    %% Styles
    classDef client fill:#ffe0b3,stroke:#d35400,stroke-width:2px;
    classDef api fill:#d6eaf8,stroke:#2874a6,stroke-width:2px;
    classDef identity fill:#e8daef,stroke:#8e44ad,stroke-width:2px;
    classDef messenger fill:#d5f5e3,stroke:#27ae60,stroke-width:2px;
    classDef common fill:#fcf3cf,stroke:#f1c40f,stroke-width:2px;
    classDef data fill:#fadbd8,stroke:#c0392b,stroke-width:2px;
    classDef external fill:#f0f3f4,stroke:#95a5a6,stroke-width:2px;
    classDef orchestration fill:#d0ece7,stroke:#16a085,stroke-width:2px;
```
