# sadabx/gdsync architecture

> Architecture diagram of the GitHub repository sadabx/gdsync, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-09-17). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/sadabx/gdsync
- Repository: https://github.com/sadabx/gdsync

## Overview

#### Purpose and runtime
gdsync is a Linux Rust daemon/CLI for Git-ignore-aware, two-way synchronization between local directories and Google Drive. It uses inotify for near-real-time changes, SQLite for durable sync state, and Google Drive v3 REST APIs for transfers. The Cargo workspace is rooted at `Cargo.toml`; core logic is a library in `crates/gdsync-core/src/lib.rs`.

#### Entry points and user surfaces
The executable entry point is `crates/gdsync-cli/src/main.rs`, exposing direct commands such as `auth`, `init`, `sync`, `watch`, and service management. Running without a command enters the interactive terminal UI implemented in `crates/gdsync-cli/src/interactive.rs`. The CLI orchestrates the core library rather than owning sync behavior.

#### Configuration, identity, and persistent state
Configuration manages tracked local-to-remote mappings and user credentials, while authentication performs OAuth2 PKCE and persists tokens under the user configuration directory. SQLite stores path records, Drive file IDs, and checksums to compare observed local/remote state across runs.
- `crates/gdsync-core/src/config/mod.rs`
- `crates/gdsync-core/src/auth/mod.rs`
- `crates/gdsync-core/src/db/mod.rs`

#### Google Drive boundary
The Drive layer is the external-service adapter: it authenticates API calls using cached OAuth tokens and performs folder/file lookup, uploads, downloads, metadata comparison, and recoverable remote trashing. It owns Google Drive v3 REST interaction, including resumable/chunked transfers and retry/backoff behavior.
- `crates/gdsync-core/src/drive/mod.rs`
- `crates/gdsync-core/src/auth/mod.rs`

#### Ignore-aware local discovery
The filter stage evaluates `.gitignore` and `.gdsyncignore`, including nested rules, so scans and watcher events exclude generated or explicitly ignored content before it reaches planning or transfer logic. This boundary prevents unwanted files from entering synchronization.
- `crates/gdsync-core/src/filter/mod.rs`
- `crates/gdsync-core/src/sync/mod.rs`

#### Reconciliation and safety policy
The sync engine performs initial and explicit two-way reconciliation: it compares local files, remote Drive state, and persisted SQLite records; plans uploads/downloads/deletions; detects concurrent offline edits; preserves local conflicts; and applies deletion-safety thresholds unless forced. It also supports dry-run planning and bounded concurrent transfer execution.
- `crates/gdsync-core/src/sync/mod.rs`
- `crates/gdsync-core/src/db/mod.rs`
- `crates/gdsync-core/src/drive/mod.rs`

#### Daemon event flow and deployment
The watcher converts kernel inotify events into debounced sync work, reusing ignore filtering and sync policy rather than directly mutating Drive. It is intended to run persistently, including as a systemd user service managed through the CLI. Release automation is defined in `.github/workflows/release.yml`; Linux installation is packaged through `install.sh`.
- `crates/gdsync-core/src/watcher/mod.rs`
- `crates/gdsync-cli/src/main.rs`
- `.github/workflows/release.yml`

Main entry points: [`crates/gdsync-core/src/lib.rs`](https://github.com/sadabx/gdsync/blob/main/crates/gdsync-core/src/lib.rs) (Core API), [`crates/gdsync-core/src/sync/mod.rs`](https://github.com/sadabx/gdsync/blob/main/crates/gdsync-core/src/sync/mod.rs) (Sync engine), [`crates/gdsync-core/src/watcher/mod.rs`](https://github.com/sadabx/gdsync/blob/main/crates/gdsync-core/src/watcher/mod.rs) (Inotify watcher), [`crates/gdsync-cli/src/main.rs`](https://github.com/sadabx/gdsync/blob/main/crates/gdsync-cli/src/main.rs) (CLI commands)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_cli["User surface"]
  node_cli_main["CLI commands<br/>Rust binary<br/>[main.rs]"]
  node_interactive["Interactive terminal UI<br/>TUI<br/>[interactive.rs]"]
end

subgraph group_core["Core library"]
  node_core_lib["Core API<br/>Rust library<br/>[lib.rs]"]
  node_sync{{"Sync engine<br/>reconciliation<br/>[mod.rs]"}}
  node_filter["Ignore filter<br/>discovery policy<br/>[mod.rs]"]
  node_watcher["Inotify watcher<br/>daemon worker<br/>[mod.rs]"]
end

subgraph group_state["State and identity"]
  node_config["Tracked mappings config<br/>configuration<br/>[mod.rs]"]
  node_auth["OAuth token manager<br/>identity<br/>[mod.rs]"]
  node_db[("Sync state<br/>SQLite<br/>[mod.rs]")]
end

subgraph group_external["External integration"]
  node_drive["Google Drive adapter<br/>REST client<br/>[mod.rs]"]
  node_google_drive(("Google Drive v3<br/>external service"))
  node_systemd["systemd user service<br/>service runtime"]
end

subgraph group_delivery["Delivery"]
  node_release["Release workflow<br/>CI automation<br/>[release.yml]"]
  node_installer["Linux installer<br/>installation script<br/>[install.sh]"]
end

node_cli_main -->|"opens by default"| node_interactive
node_cli_main -->|"orchestrates"| node_core_lib
node_interactive -->|"uses"| node_core_lib
node_core_lib -->|"exposes"| node_sync
node_core_lib -->|"runs"| node_watcher
node_core_lib -->|"loads mappings"| node_config
node_sync -->|"filters local discovery"| node_filter
node_sync -->|"compares persisted state"| node_db
node_sync -->|"plans transfers"| node_drive
node_watcher -->|"filters events"| node_filter
node_watcher -->|"queues debounced work"| node_sync
node_drive -->|"uses cached tokens"| node_auth
node_drive -->|"Drive v3 REST"| node_google_drive
node_cli_main -->|"manages service"| node_systemd
node_systemd -->|"runs persistently"| node_watcher
node_release -.->|"publishes installation"| node_installer

click node_cli_main "https://github.com/sadabx/gdsync/blob/main/crates/gdsync-cli/src/main.rs"
click node_interactive "https://github.com/sadabx/gdsync/blob/main/crates/gdsync-cli/src/interactive.rs"
click node_core_lib "https://github.com/sadabx/gdsync/blob/main/crates/gdsync-core/src/lib.rs"
click node_sync "https://github.com/sadabx/gdsync/blob/main/crates/gdsync-core/src/sync/mod.rs"
click node_filter "https://github.com/sadabx/gdsync/blob/main/crates/gdsync-core/src/filter/mod.rs"
click node_watcher "https://github.com/sadabx/gdsync/blob/main/crates/gdsync-core/src/watcher/mod.rs"
click node_config "https://github.com/sadabx/gdsync/blob/main/crates/gdsync-core/src/config/mod.rs"
click node_auth "https://github.com/sadabx/gdsync/blob/main/crates/gdsync-core/src/auth/mod.rs"
click node_db "https://github.com/sadabx/gdsync/blob/main/crates/gdsync-core/src/db/mod.rs"
click node_drive "https://github.com/sadabx/gdsync/blob/main/crates/gdsync-core/src/drive/mod.rs"
click node_release "https://github.com/sadabx/gdsync/blob/main/.github/workflows/release.yml"
click node_installer "https://github.com/sadabx/gdsync/blob/main/install.sh"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_cli_main,node_interactive toneBlue
class node_core_lib,node_sync,node_filter,node_watcher toneAmber
class node_config,node_auth,node_db toneMint
class node_drive,node_google_drive,node_systemd toneRose
class node_release,node_installer toneIndigo
```

## Components

### User surface

- [CLI commands](https://github.com/sadabx/gdsync/blob/main/crates/gdsync-cli/src/main.rs): Rust binary · Provides auth, init, sync, watch, and service commands. · `crates/gdsync-cli/src/main.rs`
- [Interactive terminal UI](https://github.com/sadabx/gdsync/blob/main/crates/gdsync-cli/src/interactive.rs): TUI · Default surface when no command is supplied. · `crates/gdsync-cli/src/interactive.rs`

### Core library

- [Core API](https://github.com/sadabx/gdsync/blob/main/crates/gdsync-core/src/lib.rs): Rust library · Shared orchestration library for CLI and daemon flows. · `crates/gdsync-core/src/lib.rs`
- [Sync engine](https://github.com/sadabx/gdsync/blob/main/crates/gdsync-core/src/sync/mod.rs): reconciliation · Plans and executes safe two-way reconciliation. · `crates/gdsync-core/src/sync/mod.rs`
- [Ignore filter](https://github.com/sadabx/gdsync/blob/main/crates/gdsync-core/src/filter/mod.rs): discovery policy · Applies nested .gitignore and .gdsyncignore rules. · `crates/gdsync-core/src/filter/mod.rs`
- [Inotify watcher](https://github.com/sadabx/gdsync/blob/main/crates/gdsync-core/src/watcher/mod.rs): daemon worker · Debounces filesystem events into sync work. · `crates/gdsync-core/src/watcher/mod.rs`

### State and identity

- [Tracked mappings config](https://github.com/sadabx/gdsync/blob/main/crates/gdsync-core/src/config/mod.rs): configuration · Stores local-to-remote mappings and user settings. · `crates/gdsync-core/src/config/mod.rs`
- [OAuth token manager](https://github.com/sadabx/gdsync/blob/main/crates/gdsync-core/src/auth/mod.rs): identity · Runs OAuth2 PKCE and caches credentials. · `crates/gdsync-core/src/auth/mod.rs`
- [Sync state](https://github.com/sadabx/gdsync/blob/main/crates/gdsync-core/src/db/mod.rs): SQLite · Persists paths, Drive IDs, and checksums. · `crates/gdsync-core/src/db/mod.rs`

### External integration

- [Google Drive adapter](https://github.com/sadabx/gdsync/blob/main/crates/gdsync-core/src/drive/mod.rs): REST client · Handles Drive v3 metadata and resumable transfers. · `crates/gdsync-core/src/drive/mod.rs`
- **Google Drive v3**: external service
- **systemd user service**: service runtime · Runs persistent watcher-based synchronization.

### Delivery

- [Release workflow](https://github.com/sadabx/gdsync/blob/main/.github/workflows/release.yml): CI automation · `.github/workflows/release.yml`
- [Linux installer](https://github.com/sadabx/gdsync/blob/main/install.sh): installation script · `install.sh`

## Connections

- CLI commands → Interactive terminal UI: opens by default
- CLI commands → Core API: orchestrates
- Interactive terminal UI → Core API: uses
- Core API → Sync engine: exposes
- Core API → Inotify watcher: runs
- Core API → Tracked mappings config: loads mappings
- Sync engine → Ignore filter: filters local discovery
- Sync engine → Sync state: compares persisted state
- Sync engine → Google Drive adapter: plans transfers
- Inotify watcher → Ignore filter: filters events
- Inotify watcher → Sync engine: queues debounced work
- Google Drive adapter → OAuth token manager: uses cached tokens
- Google Drive adapter → Google Drive v3: Drive v3 REST
- CLI commands → systemd user service: manages service
- systemd user service → Inotify watcher: runs persistently
- Release workflow → Linux installer: publishes installation
