# ddvk/rmfakecloud architecture

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

- Interactive diagram: https://gitdiagram.com/ddvk/rmfakecloud
- Repository: https://github.com/ddvk/rmfakecloud

## Overview

##### Project Type and Purpose
- This is a full-stack, monolithic Go application with a React frontend that emulates the official reMarkable “cloud” sync service (rmfakecloud).
- It provides HTTP APIs for reMarkable tablets (diff-sync & file operations), a web UI for user management and document browsing, CLI utilities for administrative tasks, and optional integrations with Dropbox/FTP/WebDAV.

##### Key Architectural Components
A. Clients
- reMarkable Tablet (diff-sync v1/v15)
- Web Browser (React UI served by backend)
- CLI Tools (`cmd/*` Go binaries for history export, fake-cloud management, tests)
B. API Layer
- HTTP server built with Go (`internal/app/routes.go`, `handlers.go`)
- Middleware for logging, authentication, CORS (`internal/app/middleware.go`)
- JWT/Auth0 integration (`internal/messages/auth0.go`)
C. Sync Engine / Hub
- Real-time synchronization hub (`internal/app/hub/hub.go`)
- Diff-sync logic (old vs. new diff-sync15)
D. Storage Layer
- Local filesystem storage (`internal/storage/fs/*`)
- Data models (archives, hash trees, metadata) (`internal/storage/models/*`)
- Exporters for PDF, archive rendering (`internal/storage/exporter/*`)
E. Integrations (optional data backends)
- Dropbox, FTP, WebDAV, LocalFS connectors (`internal/integrations/*`)
F. Email Service
- SMTP client for user notifications (`internal/email/smtp.go`)
G. Configuration & CLI
- Central config loader (`internal/config/config.go`)
- CLI manager (`internal/cli/managerusers.go`)
H. Infrastructure
- Docker setup (`Dockerfile`, `dockerbuild.sh`, `dev.sh`)
- Helm chart for Kubernetes (`helm/Chart.yaml`, `templates/*.yaml`)

##### Relationships & Data Flows
- Tablets ⇄ HTTP API: diff-sync, document upload/download
- Browsers ⇄ HTTP API: user login (email), profile, document browser
- CLI Tools ⇄ HTTP API: administrative operations (set users, diff flags)
- API Layer → Storage Layer: read/write files, metadata
- API Layer → Sync Engine: publish/subscribe sync events
- API Layer → Email Service: send auth tokens or notifications
- Storage Layer ↔ Integrations: optional data replication to external services

##### Architectural Patterns & Principles
- Monolithic service with clear package boundaries (app, storage, integrations)
- MVC-like separation: handlers/routes (controller), storage/models (model), React UI (view)
- Dependency injection for connectors and SMTP client via `codeconnector.go`
- Configuration via environment variables and `internal/config`
- Container-first design with Docker and Kubernetes manifests

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Clients Layer
    subgraph "Clients" 
        direction TB
        Tablet["reMarkable Tablet<br/>(diff-sync)"]:::clients
        Browser["Web Browser<br/>(React UI)"]:::clients
        subgraph "CLI Tools" 
            direction TB
            CLI_H2G["history2git15"]:::clients
            CLI_RELINK["relinkfile15"]:::clients
            CLI_RMFC["rmfakecloud"]:::clients
            CLI_TEST["testclient"]:::clients
        end
    end

    %% API Server Layer
    subgraph "API Server" 
        direction TB
        API["API Server<br/>Go / Gorilla Mux / JWT"]:::api
        Routes["HTTP Server Entry & Routing"]:::api
        Middleware["Middleware<br/>Logging/Auth/CORS"]:::api
        Auth0["Auth0 / JWT Integration"]:::api
        SyncHub["Sync Engine / Hub"]:::api
    end

    %% Storage & Integrations Layer
    subgraph "Storage & Integrations"
        direction TB
        subgraph "Storage Subsystem"
            direction TB
            FS["Filesystem Storage<br/>FS + Hash docs"]:::storage
            Models["Data Models"]:::storage
            Exporters["Exporters<br/>PDF/Archive"]:::storage
        end
        Integrations["Integrations<br/>Dropbox/FTP/WebDAV/LocalFS"]:::external
        Email["Email Service<br/>SMTP"]:::api
    end

    %% Infrastructure
    subgraph "Infrastructure"
        direction TB
        Docker["Docker Setup"]:::infra
        Helm["Kubernetes / Helm Chart"]:::infra
        Config["Config Loader"]:::api
        CLI_MGR["CLI Manager"]:::clients
        WebUI["Web UI<br/>React / Vite"]:::api
    end

    %% Relationships
    Tablet -->|diff-sync| API
    Browser -->|HTTP Requests| API
    CLI_H2G -->|Admin API| API
    CLI_RELINK -->|Admin API| API
    CLI_RMFC -->|Admin API| API
    CLI_TEST -->|Test API| API
    CLI_MGR -->|Admin API| API
    WebUI -->|Served by| API

    API -->|read/write| FS
    API -->|model ops| Models
    API -->|export| Exporters
    API -->|send| Email
    API -->|sync events| SyncHub
    SyncHub -->|push events| Tablet
    API -->|replication| Integrations
    Config -->|configures| API
    Docker -->|packages| API
    Docker -->|packages| FS
    Helm -->|deploys| Docker

    %% Click Events
    click CLI_H2G "https://github.com/ddvk/rmfakecloud/blob/master/cmd/history2git15/main.go"
    click CLI_RELINK "https://github.com/ddvk/rmfakecloud/blob/master/cmd/relinkfile15/main.go"
    click CLI_RMFC "https://github.com/ddvk/rmfakecloud/blob/master/cmd/rmfakecloud/main.go"
    click CLI_TEST "https://github.com/ddvk/rmfakecloud/blob/master/cmd/testclient/main.go"
    click Tablet "https://github.com/ddvk/rmfakecloud/blob/master/internal/ui/backend10.go"
    click Tablet "https://github.com/ddvk/rmfakecloud/blob/master/internal/ui/backend15.go"
    click Routes "https://github.com/ddvk/rmfakecloud/blob/master/internal/app/app.go"
    click Routes "https://github.com/ddvk/rmfakecloud/blob/master/internal/app/routes.go"
    click Routes "https://github.com/ddvk/rmfakecloud/blob/master/internal/app/handlers.go"
    click Middleware "https://github.com/ddvk/rmfakecloud/blob/master/internal/app/middleware.go"
    click Auth0 "https://github.com/ddvk/rmfakecloud/blob/master/internal/messages/auth0.go"
    click SyncHub "https://github.com/ddvk/rmfakecloud/blob/master/internal/app/hub/hub.go"
    click FS "https://github.com/ddvk/rmfakecloud/blob/master/internal/storage/fs/app.go"
    click FS "https://github.com/ddvk/rmfakecloud/blob/master/internal/storage/fs/blobstore.go"
    click FS "https://github.com/ddvk/rmfakecloud/blob/master/internal/storage/fs/documentcreator.go"
    click FS "https://github.com/ddvk/rmfakecloud/blob/master/internal/storage/fs/documents.go"
    click FS "https://github.com/ddvk/rmfakecloud/blob/master/internal/storage/fs/localblobstorage.go"
    click FS "https://github.com/ddvk/rmfakecloud/blob/master/internal/storage/fs/metadata.go"
    click FS "https://github.com/ddvk/rmfakecloud/blob/master/internal/storage/fs/userstorage.go"
    click Models "https://github.com/ddvk/rmfakecloud/blob/master/internal/storage/models/archive.go"
    click Models "https://github.com/ddvk/rmfakecloud/blob/master/internal/storage/models/hashdoc.go"
    click Models "https://github.com/ddvk/rmfakecloud/blob/master/internal/storage/models/hashentry.go"
    click Models "https://github.com/ddvk/rmfakecloud/blob/master/internal/storage/models/hashtree.go"
    click Models "https://github.com/ddvk/rmfakecloud/blob/master/internal/storage/models/history.go"
    click Models "https://github.com/ddvk/rmfakecloud/blob/master/internal/storage/models/metadatafile.go"
    click Models "https://github.com/ddvk/rmfakecloud/blob/master/internal/storage/models/remotestorage.go"
    click Exporters "https://github.com/ddvk/rmfakecloud/blob/master/internal/storage/exporter/pdf.go"
    click Exporters "https://github.com/ddvk/rmfakecloud/blob/master/internal/storage/exporter/myarchive.go"
    click Exporters "https://github.com/ddvk/rmfakecloud/blob/master/internal/storage/exporter/render.go"
    click Exporters "https://github.com/ddvk/rmfakecloud/blob/master/internal/storage/exporter/license.go"
    click Integrations "https://github.com/ddvk/rmfakecloud/blob/master/internal/integrations/dropbox.go"
    click Integrations "https://github.com/ddvk/rmfakecloud/blob/master/internal/integrations/ftp.go"
    click Integrations "https://github.com/ddvk/rmfakecloud/blob/master/internal/integrations/webdav.go"
    click Integrations "https://github.com/ddvk/rmfakecloud/blob/master/internal/integrations/localfs.go"
    click Integrations "https://github.com/ddvk/rmfakecloud/blob/master/internal/integrations/integrations.go"
    click Email "https://github.com/ddvk/rmfakecloud/blob/master/internal/email/smtp.go"
    click Config "https://github.com/ddvk/rmfakecloud/blob/master/internal/config/config.go"
    click CLI_MGR "https://github.com/ddvk/rmfakecloud/blob/master/internal/cli/managerusers.go"
    click Docker "https://github.com/ddvk/rmfakecloud/tree/master/Dockerfile"
    click Docker "https://github.com/ddvk/rmfakecloud/blob/master/dockerbuild.sh"
    click Docker "https://github.com/ddvk/rmfakecloud/blob/master/dev.sh"
    click Helm "https://github.com/ddvk/rmfakecloud/blob/master/helm/Chart.yaml"
    click Helm "https://github.com/ddvk/rmfakecloud/blob/master/helm/templates/deployment.yaml"
    click Helm "https://github.com/ddvk/rmfakecloud/blob/master/helm/templates/service.yaml"
    click Helm "https://github.com/ddvk/rmfakecloud/blob/master/helm/templates/pvc.yml"
    click Helm "https://github.com/ddvk/rmfakecloud/blob/master/helm/values.yaml"
    click WebUI "https://github.com/ddvk/rmfakecloud/tree/master/ui/src"
    click WebUI "https://github.com/ddvk/rmfakecloud/blob/master/ui/package.json"
    click WebUI "https://github.com/ddvk/rmfakecloud/blob/master/ui/vite.config.ts"
    click WebUI "https://github.com/ddvk/rmfakecloud/tree/master/ui/public"

    %% Styles
    classDef clients fill:#d3c0f9,stroke:#5d3fd3,stroke-width:1px;
    classDef api fill:#aed6f1,stroke:#1f618d,stroke-width:1px;
    classDef storage fill:#abebc6,stroke:#1d8348,stroke-width:1px;
    classDef external fill:#f9e79f,stroke:#b7950b,stroke-width:1px;
    classDef infra fill:#d5dbdb,stroke:#566573,stroke-width:1px;
```
