# haiwen/seafile architecture

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

- Interactive diagram: https://gitdiagram.com/haiwen/seafile
- Repository: https://github.com/haiwen/seafile

## Overview

##### Project type and purpose
- This repository is the “sync client daemon” for Seafile, an open-source cloud-storage and file-sync system.
- Its job is to monitor local file changes, compute deltas, encrypt/ decrypt libraries, and sync with one or more Seafile servers over HTTP/RPC.

##### File structure
- Top-level binaries and entry points:
- app/seaf-cli — the command-line client wrapper
- daemon/seaf-daemon.c — the long-running sync daemon
- Core logic modules under common/ and lib/:
- common/ — low-level components: block-mgr, commit-mgr, branch-mgr, cdc (content-defined chunking), obj-store, fs-mgr, RPC service
- lib/ — higher-level interfaces: db (SQLite), net (HTTP/RPC), repo, task, utils, searpc marshalling
- Platform-specific watchers under daemon/wt-monitor-*.c
- Build and packaging:
- Autotools scripts (configure.ac, Makefile.am, m4/)
- Windows installer (msi/), macOS DMG layout (dmg/)
- Language bindings and tools:
- python/seafile/rpcclient.py — Python RPC client
- Tests and integration:
- integration-tests/ and tests/sync-auto-test/ harnesses

##### Readme insights
- Describes high-level features: selective sync, delta transfer, encryption, multi-server sync.
- Points out components interact with server core via HTTP/RPC.
- Emphasizes client-side chunking, encryption, and version control.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "seaf-daemon"
        style seaf-daemon stroke:#333,stroke-width:4px
        FSWatcher["File System Watcher (wt-monitor)"]:::local
        SyncMgr["Sync Manager (sync-mgr)"]:::local
        DeltaEngine["Chunking & Delta Engine"]:::local
        Crypto["Crypto Module (seafile-crypt)"]:::local
        LocalStorage["Local Storage & DB"]:::storage
        NetworkLayer["Network Layer (HTTP/RPC)"]:::network
    end

    seaf-cli["Command-line Interface (seaf-cli)"]:::cli
    SeafileServer["Seafile Server\n(HTTP/RPC Endpoints)"]:::server

    FSWatcher -->|"file events"| SyncMgr
    SyncMgr -->|"compute diffs"| DeltaEngine
    DeltaEngine -->|"encrypt/decrypt"| Crypto
    Crypto -->|"persist chunks"| LocalStorage
    SyncMgr -->|"sync updates"| NetworkLayer
    NetworkLayer <-->|"HTTP/RPC calls"| SeafileServer
    NetworkLayer -->|"apply remote changes"| LocalStorage
    seaf-cli -->|"RPC/commands"| FSWatcher

    click FSWatcher "https://github.com/haiwen/seafile/blob/master/daemon/wt-monitor.c"
    click SyncMgr "https://github.com/haiwen/seafile/blob/master/daemon/sync-mgr.c"
    click DeltaEngine "https://github.com/haiwen/seafile/tree/master/common/cdc/"
    click Crypto "https://github.com/haiwen/seafile/blob/master/common/seafile-crypt.c"
    click LocalStorage "https://github.com/haiwen/seafile/blob/master/lib/db.c"
    click NetworkLayer "https://github.com/haiwen/seafile/blob/master/daemon/http-tx-mgr.c"
    click seaf-cli "https://github.com/haiwen/seafile/tree/master/app/seaf-cli"

    classDef local fill:#ccffcc,stroke:#006600
    classDef network fill:#cceeff,stroke:#0044cc
    classDef storage fill:#ffcc99,stroke:#cc6600
    classDef cli fill:#ccccff,stroke:#000066
    classDef server fill:#cceeff,stroke:#0044cc,stroke-dasharray: 5 5
```
