# yunfie-twitter/pallasync architecture

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

- Interactive diagram: https://gitdiagram.com/yunfie-twitter/pallasync
- Repository: https://github.com/yunfie-twitter/pallasync

## Overview

PallaSync Server is an HTTP relay for encrypted sync events and control logs. Clients call the Axum v2 API to create and manage chains and devices, then submit and fetch records using cursor-based pagination. The server initializes SQLite before serving requests; API handlers use the database for relay state. Signature verification and JSON canonicalization form a separate protocol-security layer. Several handler internals are unsampled, so the API-to-cryptography relationship is shown as unverified rather than asserted.

Main entry points: [`src/lib.rs`](https://github.com/yunfie-twitter/pallasync/blob/main/src/lib.rs) (Route setup), [`src/db/mod.rs`](https://github.com/yunfie-twitter/pallasync/blob/main/src/db/mod.rs) (SQLite state), [`src/main.rs`](https://github.com/yunfie-twitter/pallasync/blob/main/src/main.rs) (HTTP server), [`src/api/sync.rs`](https://github.com/yunfie-twitter/pallasync/blob/main/src/api/sync.rs) (Capability checks)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Server runtime"]
  node_server["HTTP server<br/>[main.rs]"]
  node_router["Route setup<br/>[lib.rs]"]
end

subgraph group_api["Relay API"]
  node_health["Health endpoint<br/>[sync.rs]"]
  node_chain["Chain management<br/>[sync.rs]"]
  node_devices["Device management<br/>[sync.rs]"]
  node_records["Record relay<br/>[sync.rs]"]
  node_capability["Capability checks<br/>[sync.rs]"]
end

subgraph group_storage["Persistence"]
  node_dbinit["Database setup<br/>[mod.rs]"]
  node_schema["SQLite schema<br/>[schema.sql]"]
  node_sqlite[("SQLite state<br/>[mod.rs]")]
end

subgraph group_security["Protocol security"]
  node_verification["Signature verification<br/>[verify.rs]"]
  node_canonicalization["JSON canonicalization<br/>[jcs.rs]"]
end

node_client(("Sync client"))

node_client -->|"sends HTTP requests"| node_server
node_server -->|"initializes database"| node_dbinit
node_server -->|"serves app"| node_router
node_router -->|"routes health"| node_health
node_router -->|"routes chain operations"| node_chain
node_router -->|"routes device operations"| node_devices
node_router -->|"routes record operations"| node_records
node_dbinit -->|"opens and migrates"| node_sqlite
node_dbinit -->|"loads schema"| node_schema
node_chain -->|"reads and writes"| node_sqlite
node_devices -->|"reads and writes"| node_sqlite
node_records -->|"reads and writes"| node_sqlite
node_capability -->|"checks replay state"| node_sqlite
node_canonicalization -->|"canonicalizes signed JSON"| node_verification
node_capability -.->|"verifies signatures"| node_verification

click node_server "https://github.com/yunfie-twitter/pallasync/blob/main/src/main.rs"
click node_router "https://github.com/yunfie-twitter/pallasync/blob/main/src/lib.rs"
click node_health "https://github.com/yunfie-twitter/pallasync/blob/main/src/api/sync.rs"
click node_chain "https://github.com/yunfie-twitter/pallasync/blob/main/src/api/sync.rs"
click node_devices "https://github.com/yunfie-twitter/pallasync/blob/main/src/api/sync.rs"
click node_records "https://github.com/yunfie-twitter/pallasync/blob/main/src/api/sync.rs"
click node_capability "https://github.com/yunfie-twitter/pallasync/blob/main/src/api/sync.rs"
click node_dbinit "https://github.com/yunfie-twitter/pallasync/blob/main/src/db/mod.rs"
click node_schema "https://github.com/yunfie-twitter/pallasync/blob/main/src/db/schema.sql"
click node_sqlite "https://github.com/yunfie-twitter/pallasync/blob/main/src/db/mod.rs"
click node_verification "https://github.com/yunfie-twitter/pallasync/blob/main/src/crypto/verify.rs"
click node_canonicalization "https://github.com/yunfie-twitter/pallasync/blob/main/src/crypto/jcs.rs"

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_server,node_router,node_client toneBlue
class node_health,node_chain,node_devices,node_records,node_capability toneAmber
class node_dbinit,node_schema,node_sqlite toneMint
class node_verification,node_canonicalization toneRose
```

## Components

### Server runtime

- [HTTP server](https://github.com/yunfie-twitter/pallasync/blob/main/src/main.rs): `src/main.rs`
- [Route setup](https://github.com/yunfie-twitter/pallasync/blob/main/src/lib.rs): `src/lib.rs`

### Relay API

- [Health endpoint](https://github.com/yunfie-twitter/pallasync/blob/main/src/api/sync.rs): `src/api/sync.rs`
- [Chain management](https://github.com/yunfie-twitter/pallasync/blob/main/src/api/sync.rs): `src/api/sync.rs`
- [Device management](https://github.com/yunfie-twitter/pallasync/blob/main/src/api/sync.rs): `src/api/sync.rs`
- [Record relay](https://github.com/yunfie-twitter/pallasync/blob/main/src/api/sync.rs): `src/api/sync.rs`
- [Capability checks](https://github.com/yunfie-twitter/pallasync/blob/main/src/api/sync.rs): `src/api/sync.rs`

### Persistence

- [Database setup](https://github.com/yunfie-twitter/pallasync/blob/main/src/db/mod.rs): `src/db/mod.rs`
- [SQLite schema](https://github.com/yunfie-twitter/pallasync/blob/main/src/db/schema.sql): `src/db/schema.sql`
- [SQLite state](https://github.com/yunfie-twitter/pallasync/blob/main/src/db/mod.rs): `src/db/mod.rs`

### Protocol security

- [Signature verification](https://github.com/yunfie-twitter/pallasync/blob/main/src/crypto/verify.rs): `src/crypto/verify.rs`
- [JSON canonicalization](https://github.com/yunfie-twitter/pallasync/blob/main/src/crypto/jcs.rs): `src/crypto/jcs.rs`

### Other components

- **Sync client**

## Connections

- Sync client → HTTP server: sends HTTP requests (evidence: `README.md`)
- HTTP server → Database setup: initializes database (evidence: `src/main.rs`)
- HTTP server → Route setup: serves app (evidence: `src/main.rs`)
- Route setup → Health endpoint: routes health (evidence: `src/lib.rs`)
- Route setup → Chain management: routes chain operations (evidence: `src/lib.rs`)
- Route setup → Device management: routes device operations (evidence: `src/lib.rs`)
- Route setup → Record relay: routes record operations (evidence: `src/lib.rs`)
- Database setup → SQLite state: opens and migrates (evidence: `src/db/mod.rs`)
- Database setup → SQLite schema: loads schema (evidence: `src/db/mod.rs`)
- Chain management → SQLite state: reads and writes (evidence: `src/api/sync.rs`)
- Device management → SQLite state: reads and writes (evidence: `src/api/sync.rs`)
- Record relay → SQLite state: reads and writes (evidence: `src/api/sync.rs`)
- Capability checks → SQLite state: checks replay state (evidence: `src/api/sync.rs`)
- JSON canonicalization → Signature verification: canonicalizes signed JSON (evidence: `src/crypto/verify.rs`)
- Capability checks → Signature verification: verifies signatures
