# syncthing/syncthing architecture

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

- Interactive diagram: https://gitdiagram.com/syncthing/syncthing
- Repository: https://github.com/syncthing/syncthing

## Overview

Syncthing is a continuous file-synchronization program. Its principal workflow is to discover peer devices, establish secure connections, exchange folder indexes, scan and compare files, and transfer updates while maintaining local index state. The graph also preserves configuration/API and GUI, discovery and connection infrastructure, and the independent discovery and relay services. Edges reflect explicit README statements or source-index references; where runtime wiring is not shown, relationships are omitted rather than inferred.

Main entry points: [`lib/scanner/walk.go`](https://github.com/syncthing/syncthing/blob/main/lib/scanner/walk.go) (File scanner), [`lib/model/indexhandler.go`](https://github.com/syncthing/syncthing/blob/main/lib/model/indexhandler.go) (Index exchange), [`lib/protocol/protocol.go`](https://github.com/syncthing/syncthing/blob/main/lib/protocol/protocol.go) (Sync protocol), [`lib/connections/service.go`](https://github.com/syncthing/syncthing/blob/main/lib/connections/service.go) (Connection manager)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_sync["Synchronization engine"]
  node_daemon["Syncthing CLI<br/>[main.go]"]
  node_app["Application runtime<br/>[syncthing.go]"]
  node_model["Folder model<br/>[model.go]"]
  node_index["Index exchange<br/>[indexhandler.go]"]
  node_scanner["File scanner<br/>[walk.go]"]
end

subgraph group_network["Peer networking"]
  node_protocol["Sync protocol<br/>[protocol.go]"]
  node_connections["Connection manager<br/>[service.go]"]
  node_discovery["Device discovery<br/>[manager.go]"]
end

subgraph group_control["Configuration and interface"]
  node_config["Configuration<br/>[config.go]"]
  node_api["HTTP API<br/>[api.go]"]
  node_gui["Web GUI"]
end

subgraph group_services["Network services"]
  node_discosrv["Global discovery server<br/>[main.go]"]
  node_discodb[("Discovery database<br/>[database.go]")]
  node_relaysrv["Relay server<br/>[main.go]"]
  node_relaypool["Relay pool server<br/>[main.go]"]
end

subgraph group_storage["Persistence and files"]
  node_db[("Index database<br/>[db_service.go]")]
  node_filesystem["Filesystem layer<br/>[filesystem.go]"]
  node_ignore["Ignore rules<br/>[ignore.go]"]
end

node_user(("User"))

node_user -->|"starts"| node_daemon
node_daemon -->|"starts runtime"| node_app
node_model -.->|"handles indexes"| node_index
node_index -->|"reads and writes"| node_db
node_index -->|"exchanges indexes"| node_protocol
node_scanner -->|"walks files"| node_filesystem
node_scanner -->|"checks exclusions"| node_ignore
node_scanner -->|"creates file data"| node_protocol
node_connections -->|"resolves peers"| node_discovery
node_connections -.->|"connects devices"| node_protocol
node_discosrv -->|"starts database"| node_discodb
node_gui -.->|"uses API"| node_api
node_user -.->|"manages"| node_gui

click node_daemon "https://github.com/syncthing/syncthing/blob/main/cmd/syncthing/main.go"
click node_app "https://github.com/syncthing/syncthing/blob/main/lib/syncthing/syncthing.go"
click node_model "https://github.com/syncthing/syncthing/blob/main/lib/model/model.go"
click node_index "https://github.com/syncthing/syncthing/blob/main/lib/model/indexhandler.go"
click node_scanner "https://github.com/syncthing/syncthing/blob/main/lib/scanner/walk.go"
click node_protocol "https://github.com/syncthing/syncthing/blob/main/lib/protocol/protocol.go"
click node_connections "https://github.com/syncthing/syncthing/blob/main/lib/connections/service.go"
click node_discovery "https://github.com/syncthing/syncthing/blob/main/lib/discover/manager.go"
click node_config "https://github.com/syncthing/syncthing/blob/main/lib/config/config.go"
click node_api "https://github.com/syncthing/syncthing/blob/main/lib/api/api.go"
click node_gui "https://github.com/syncthing/syncthing/blob/main/gui/default/syncthing/core/syncthingController.js"
click node_db "https://github.com/syncthing/syncthing/blob/main/internal/db/sqlite/db_service.go"
click node_filesystem "https://github.com/syncthing/syncthing/blob/main/lib/fs/filesystem.go"
click node_ignore "https://github.com/syncthing/syncthing/blob/main/lib/ignore/ignore.go"
click node_discosrv "https://github.com/syncthing/syncthing/blob/main/cmd/stdiscosrv/main.go"
click node_discodb "https://github.com/syncthing/syncthing/blob/main/cmd/stdiscosrv/database.go"
click node_relaysrv "https://github.com/syncthing/syncthing/blob/main/cmd/strelaysrv/main.go"
click node_relaypool "https://github.com/syncthing/syncthing/blob/main/cmd/infra/strelaypoolsrv/main.go"

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_daemon,node_app,node_model,node_index,node_scanner,node_user toneBlue
class node_protocol,node_connections,node_discovery toneAmber
class node_config,node_api,node_gui toneMint
class node_discosrv,node_discodb,node_relaysrv,node_relaypool toneRose
class node_db,node_filesystem,node_ignore toneIndigo
```

## Components

### Synchronization engine

- [Syncthing CLI](https://github.com/syncthing/syncthing/blob/main/cmd/syncthing/main.go): `cmd/syncthing/main.go`
- [Application runtime](https://github.com/syncthing/syncthing/blob/main/lib/syncthing/syncthing.go): `lib/syncthing/syncthing.go`
- [Folder model](https://github.com/syncthing/syncthing/blob/main/lib/model/model.go): `lib/model/model.go`
- [Index exchange](https://github.com/syncthing/syncthing/blob/main/lib/model/indexhandler.go): `lib/model/indexhandler.go`
- [File scanner](https://github.com/syncthing/syncthing/blob/main/lib/scanner/walk.go): `lib/scanner/walk.go`

### Peer networking

- [Sync protocol](https://github.com/syncthing/syncthing/blob/main/lib/protocol/protocol.go): `lib/protocol/protocol.go`
- [Connection manager](https://github.com/syncthing/syncthing/blob/main/lib/connections/service.go): `lib/connections/service.go`
- [Device discovery](https://github.com/syncthing/syncthing/blob/main/lib/discover/manager.go): `lib/discover/manager.go`

### Configuration and interface

- [Configuration](https://github.com/syncthing/syncthing/blob/main/lib/config/config.go): `lib/config/config.go`
- [HTTP API](https://github.com/syncthing/syncthing/blob/main/lib/api/api.go): `lib/api/api.go`
- [Web GUI](https://github.com/syncthing/syncthing/blob/main/gui/default/syncthing/core/syncthingController.js): `gui/default/syncthing/core/syncthingController.js`

### Network services

- [Global discovery server](https://github.com/syncthing/syncthing/blob/main/cmd/stdiscosrv/main.go): `cmd/stdiscosrv/main.go`
- [Discovery database](https://github.com/syncthing/syncthing/blob/main/cmd/stdiscosrv/database.go): `cmd/stdiscosrv/database.go`
- [Relay server](https://github.com/syncthing/syncthing/blob/main/cmd/strelaysrv/main.go): `cmd/strelaysrv/main.go`
- [Relay pool server](https://github.com/syncthing/syncthing/blob/main/cmd/infra/strelaypoolsrv/main.go): `cmd/infra/strelaypoolsrv/main.go`

### Persistence and files

- [Index database](https://github.com/syncthing/syncthing/blob/main/internal/db/sqlite/db_service.go): `internal/db/sqlite/db_service.go`
- [Filesystem layer](https://github.com/syncthing/syncthing/blob/main/lib/fs/filesystem.go): `lib/fs/filesystem.go`
- [Ignore rules](https://github.com/syncthing/syncthing/blob/main/lib/ignore/ignore.go): `lib/ignore/ignore.go`

### Other components

- **User**

## Connections

- User → Syncthing CLI: starts (evidence: `cmd/syncthing/main.go`)
- Syncthing CLI → Application runtime: starts runtime (evidence: `cmd/syncthing/main.go`)
- Folder model → Index exchange: handles indexes
- Index exchange → Index database: reads and writes (evidence: `lib/model/indexhandler.go`)
- Index exchange → Sync protocol: exchanges indexes (evidence: `lib/model/indexhandler.go`)
- File scanner → Filesystem layer: walks files (evidence: `lib/scanner/walk.go`)
- File scanner → Ignore rules: checks exclusions (evidence: `lib/scanner/walk.go`)
- File scanner → Sync protocol: creates file data (evidence: `lib/scanner/walk.go`)
- Connection manager → Device discovery: resolves peers (evidence: `lib/connections/service.go`)
- Connection manager → Sync protocol: connects devices
- Global discovery server → Discovery database: starts database (evidence: `cmd/stdiscosrv/main.go`)
- Web GUI → HTTP API: uses API
- User → Web GUI: manages
