# phannhatminh/hodion_drive architecture

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

- Interactive diagram: https://gitdiagram.com/phannhatminh/hodion_drive
- Repository: https://github.com/phannhatminh/hodion_drive

## Overview

Hodion Drive is a cloud file-storage product with a native macOS client, stateless Workers, Postgres metadata, R2 file content, and per-drive authorization. The main client workflow is a user mounting a drive: the mount controller runs reconciliation, which compares local files with the remote tree, applies sync actions, and records an agreed baseline; file events and the doorbell wake later cycles. On the server, API and auth Workers route requests into domain services and authorization. The graph preserves documented Shared Drive, configurable authorization, and files-on-demand capabilities; unsampled internals are represented at their supported directory paths.

Main entry points: [`client/Sources/Core/Sync/SyncEngine.swift`](https://github.com/phannhatminh/hodion_drive/blob/main/client/Sources/Core/Sync/SyncEngine.swift) (Sync engine), [`client/Sources/App/MountController.swift`](https://github.com/phannhatminh/hodion_drive/blob/main/client/Sources/App/MountController.swift) (Mount controller), [`server/src/workers/api-worker/fs-routes.ts`](https://github.com/phannhatminh/hodion_drive/blob/main/server/src/workers/api-worker/fs-routes.ts) (Filesystem routes), [`client/Sources/Adapters/HTTPAPIClient.swift`](https://github.com/phannhatminh/hodion_drive/blob/main/client/Sources/Adapters/HTTPAPIClient.swift) (HTTP API client)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["macOS client"]
  node_app["Mac app"]
  node_mount["Mount controller"]
  node_sync["Sync engine<br/>[SyncEngine.swift]"]
  node_reconcile["Reconciler<br/>[Reconciler.swift]"]
  node_planner["Action planner<br/>[Planner.swift]"]
  node_applier["Action applier<br/>[Applier.swift]"]
  node_local["Local files"]
  node_clientapi["HTTP API client"]
  node_session["Auth session<br/>[AuthSession.swift]"]
  node_blob["R2 transfer"]
  node_state[("Sync state")]
  node_fileprovider["File Provider"]
end

subgraph group_serving["Worker APIs"]
  node_apiworker["Drive API worker<br/>[app.ts]"]
  node_fsroutes["Filesystem routes<br/>[fs-routes.ts]"]
  node_authworker["Auth worker<br/>[app.ts]"]
  node_pipeline["Middleware pipeline<br/>[pipeline.ts]"]
end

subgraph group_domain["Drive domain"]
  node_nodeservice["Node service<br/>[NodeService.ts]"]
  node_driveservice["Drive service<br/>[DriveService.ts]"]
  node_authzservice["Authorization service<br/>[AuthzService.ts]"]
  node_engineauth["Authorization engine"]
  node_decision["Policy evaluation<br/>[decide.ts]"]
  node_model["Access model<br/>[AccessModel.ts]"]
end

subgraph group_data["Storage and integrations"]
  node_pgstores[("Postgres engine stores<br/>[PgEngineStores.ts]")]
  node_r2server["R2 capabilities"]
  node_doorbell["Drive doorbell"]
end

node_person(("Drive user"))
node_postgres[("Postgres")]
node_r2[("Cloudflare R2")]

node_person -->|"uses"| node_app
node_person -->|"browses files"| node_fileprovider
node_app -.->|"starts mounts"| node_mount
node_mount -->|"runs cycles"| node_sync
node_mount -->|"watches changes"| node_local
node_sync -->|"compares trees"| node_reconcile
node_sync -->|"orders actions"| node_planner
node_sync -.->|"applies plan"| node_applier
node_sync -->|"scans files"| node_local
node_sync -->|"fetches metadata"| node_clientapi
node_sync -->|"loads and saves"| node_state
node_mount -->|"configures"| node_clientapi
node_mount -->|"configures"| node_blob
node_clientapi -->|"renews tokens"| node_session
node_clientapi -.->|"sends requests"| node_apiworker
node_fileprovider -.->|"requests metadata"| node_clientapi
node_fileprovider -.->|"transfers content"| node_blob
node_blob -.->|"transfers blobs"| node_r2
node_apiworker -->|"routes requests"| node_fsroutes
node_apiworker -->|"composes middleware"| node_pipeline
node_authworker -->|"composes middleware"| node_pipeline
node_fsroutes -->|"manages nodes"| node_nodeservice
node_fsroutes -->|"lists drives"| node_driveservice
node_fsroutes -->|"changes access"| node_authzservice
node_engineauth -->|"evaluates policy"| node_decision
node_engineauth -->|"filters trash"| node_nodeservice
node_authzservice -->|"resolves configuration"| node_model
node_pgstores -->|"reads and writes"| node_postgres
node_r2server -.->|"enables transfers"| node_r2
node_fsroutes -.->|"notifies changes"| node_doorbell

click node_app "https://github.com/phannhatminh/hodion_drive/blob/main/client/Sources/App/HodionDriveApp.swift"
click node_mount "https://github.com/phannhatminh/hodion_drive/blob/main/client/Sources/App/MountController.swift"
click node_sync "https://github.com/phannhatminh/hodion_drive/blob/main/client/Sources/Core/Sync/SyncEngine.swift"
click node_reconcile "https://github.com/phannhatminh/hodion_drive/blob/main/client/Sources/Core/Sync/Reconciler.swift"
click node_planner "https://github.com/phannhatminh/hodion_drive/blob/main/client/Sources/Core/Sync/Planner.swift"
click node_applier "https://github.com/phannhatminh/hodion_drive/blob/main/client/Sources/Core/Sync/Applier.swift"
click node_local "https://github.com/phannhatminh/hodion_drive/blob/main/client/Sources/Adapters/RealLocalFiles.swift"
click node_clientapi "https://github.com/phannhatminh/hodion_drive/blob/main/client/Sources/Adapters/HTTPAPIClient.swift"
click node_session "https://github.com/phannhatminh/hodion_drive/blob/main/client/Sources/Adapters/AuthSession.swift"
click node_blob "https://github.com/phannhatminh/hodion_drive/blob/main/client/Sources/Adapters/R2BlobTransfer.swift"
click node_state "https://github.com/phannhatminh/hodion_drive/blob/main/client/Sources/Adapters/JSONStateStore.swift"
click node_fileprovider "https://github.com/phannhatminh/hodion_drive/blob/main/client/Sources/FileProviderExt/HodionFileProviderExtension.swift"
click node_apiworker "https://github.com/phannhatminh/hodion_drive/blob/main/server/src/workers/api-worker/app.ts"
click node_fsroutes "https://github.com/phannhatminh/hodion_drive/blob/main/server/src/workers/api-worker/fs-routes.ts"
click node_authworker "https://github.com/phannhatminh/hodion_drive/blob/main/server/src/workers/auth-worker/app.ts"
click node_pipeline "https://github.com/phannhatminh/hodion_drive/blob/main/server/src/middleware/pipeline.ts"
click node_nodeservice "https://github.com/phannhatminh/hodion_drive/blob/main/server/src/domain/services/NodeService.ts"
click node_driveservice "https://github.com/phannhatminh/hodion_drive/blob/main/server/src/domain/services/DriveService.ts"
click node_authzservice "https://github.com/phannhatminh/hodion_drive/blob/main/server/src/domain/services/AuthzService.ts"
click node_engineauth "https://github.com/phannhatminh/hodion_drive/blob/main/server/src/domain/engine/EngineAuthorizer.ts"
click node_decision "https://github.com/phannhatminh/hodion_drive/blob/main/server/src/domain/engine/decide.ts"
click node_model "https://github.com/phannhatminh/hodion_drive/blob/main/server/src/domain/model/AccessModel.ts"
click node_pgstores "https://github.com/phannhatminh/hodion_drive/blob/main/server/src/adapters/postgres/PgEngineStores.ts"
click node_r2server "https://github.com/phannhatminh/hodion_drive/blob/main/server/src/adapters/r2/R2TransferCapabilities.ts"
click node_doorbell "https://github.com/phannhatminh/hodion_drive/blob/main/server/src/adapters/do/DoorbellNotifier.ts"

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_app,node_mount,node_sync,node_reconcile,node_planner,node_applier,node_local,node_clientapi,node_session,node_blob,node_state,node_fileprovider,node_person toneBlue
class node_apiworker,node_fsroutes,node_authworker,node_pipeline,node_postgres,node_r2 toneAmber
class node_nodeservice,node_driveservice,node_authzservice,node_engineauth,node_decision,node_model toneMint
class node_pgstores,node_r2server,node_doorbell toneRose
```

## Components

### macOS client

- [Mac app](https://github.com/phannhatminh/hodion_drive/blob/main/client/Sources/App/HodionDriveApp.swift): `client/Sources/App/HodionDriveApp.swift`
- [Mount controller](https://github.com/phannhatminh/hodion_drive/blob/main/client/Sources/App/MountController.swift): `client/Sources/App/MountController.swift`
- [Sync engine](https://github.com/phannhatminh/hodion_drive/blob/main/client/Sources/Core/Sync/SyncEngine.swift): `client/Sources/Core/Sync/SyncEngine.swift`
- [Reconciler](https://github.com/phannhatminh/hodion_drive/blob/main/client/Sources/Core/Sync/Reconciler.swift): `client/Sources/Core/Sync/Reconciler.swift`
- [Action planner](https://github.com/phannhatminh/hodion_drive/blob/main/client/Sources/Core/Sync/Planner.swift): `client/Sources/Core/Sync/Planner.swift`
- [Action applier](https://github.com/phannhatminh/hodion_drive/blob/main/client/Sources/Core/Sync/Applier.swift): `client/Sources/Core/Sync/Applier.swift`
- [Local files](https://github.com/phannhatminh/hodion_drive/blob/main/client/Sources/Adapters/RealLocalFiles.swift): `client/Sources/Adapters/RealLocalFiles.swift`
- [HTTP API client](https://github.com/phannhatminh/hodion_drive/blob/main/client/Sources/Adapters/HTTPAPIClient.swift): `client/Sources/Adapters/HTTPAPIClient.swift`
- [Auth session](https://github.com/phannhatminh/hodion_drive/blob/main/client/Sources/Adapters/AuthSession.swift): `client/Sources/Adapters/AuthSession.swift`
- [R2 transfer](https://github.com/phannhatminh/hodion_drive/blob/main/client/Sources/Adapters/R2BlobTransfer.swift): `client/Sources/Adapters/R2BlobTransfer.swift`
- [Sync state](https://github.com/phannhatminh/hodion_drive/blob/main/client/Sources/Adapters/JSONStateStore.swift): `client/Sources/Adapters/JSONStateStore.swift`
- [File Provider](https://github.com/phannhatminh/hodion_drive/blob/main/client/Sources/FileProviderExt/HodionFileProviderExtension.swift): `client/Sources/FileProviderExt/HodionFileProviderExtension.swift`

### Worker APIs

- [Drive API worker](https://github.com/phannhatminh/hodion_drive/blob/main/server/src/workers/api-worker/app.ts): `server/src/workers/api-worker/app.ts`
- [Filesystem routes](https://github.com/phannhatminh/hodion_drive/blob/main/server/src/workers/api-worker/fs-routes.ts): `server/src/workers/api-worker/fs-routes.ts`
- [Auth worker](https://github.com/phannhatminh/hodion_drive/blob/main/server/src/workers/auth-worker/app.ts): `server/src/workers/auth-worker/app.ts`
- [Middleware pipeline](https://github.com/phannhatminh/hodion_drive/blob/main/server/src/middleware/pipeline.ts): `server/src/middleware/pipeline.ts`

### Drive domain

- [Node service](https://github.com/phannhatminh/hodion_drive/blob/main/server/src/domain/services/NodeService.ts): `server/src/domain/services/NodeService.ts`
- [Drive service](https://github.com/phannhatminh/hodion_drive/blob/main/server/src/domain/services/DriveService.ts): `server/src/domain/services/DriveService.ts`
- [Authorization service](https://github.com/phannhatminh/hodion_drive/blob/main/server/src/domain/services/AuthzService.ts): `server/src/domain/services/AuthzService.ts`
- [Authorization engine](https://github.com/phannhatminh/hodion_drive/blob/main/server/src/domain/engine/EngineAuthorizer.ts): `server/src/domain/engine/EngineAuthorizer.ts`
- [Policy evaluation](https://github.com/phannhatminh/hodion_drive/blob/main/server/src/domain/engine/decide.ts): `server/src/domain/engine/decide.ts`
- [Access model](https://github.com/phannhatminh/hodion_drive/blob/main/server/src/domain/model/AccessModel.ts): `server/src/domain/model/AccessModel.ts`

### Storage and integrations

- [Postgres engine stores](https://github.com/phannhatminh/hodion_drive/blob/main/server/src/adapters/postgres/PgEngineStores.ts): `server/src/adapters/postgres/PgEngineStores.ts`
- [R2 capabilities](https://github.com/phannhatminh/hodion_drive/blob/main/server/src/adapters/r2/R2TransferCapabilities.ts): `server/src/adapters/r2/R2TransferCapabilities.ts`
- [Drive doorbell](https://github.com/phannhatminh/hodion_drive/blob/main/server/src/adapters/do/DoorbellNotifier.ts): `server/src/adapters/do/DoorbellNotifier.ts`

### Other components

- **Drive user**
- **Postgres**
- **Cloudflare R2**

## Connections

- Drive user → Mac app: uses (evidence: `README.md`)
- Drive user → File Provider: browses files (evidence: `README.md`)
- Mac app → Mount controller: starts mounts
- Mount controller → Sync engine: runs cycles (evidence: `client/Sources/App/MountController.swift`)
- Mount controller → Local files: watches changes (evidence: `client/Sources/App/MountController.swift`)
- Sync engine → Reconciler: compares trees (evidence: `client/Sources/Core/Sync/SyncEngine.swift`)
- Sync engine → Action planner: orders actions (evidence: `client/Sources/Core/Sync/SyncEngine.swift`)
- Sync engine → Action applier: applies plan (evidence: `client/Sources/Core/Sync/SyncEngine.swift`)
- Sync engine → Local files: scans files (evidence: `client/Sources/Core/Sync/SyncEngine.swift`)
- Sync engine → HTTP API client: fetches metadata (evidence: `client/Sources/Core/Sync/SyncEngine.swift`)
- Sync engine → Sync state: loads and saves (evidence: `client/Sources/Core/Sync/SyncEngine.swift`)
- Mount controller → HTTP API client: configures (evidence: `client/Sources/App/MountController.swift`)
- Mount controller → R2 transfer: configures (evidence: `client/Sources/App/MountController.swift`)
- HTTP API client → Auth session: renews tokens (evidence: `client/Sources/Adapters/HTTPAPIClient.swift`)
- HTTP API client → Drive API worker: sends requests (evidence: `README.md`)
- File Provider → HTTP API client: requests metadata (evidence: `client/Sources/FileProviderExt/HodionFileProviderExtension.swift`)
- File Provider → R2 transfer: transfers content (evidence: `client/Sources/FileProviderExt/HodionFileProviderExtension.swift`)
- R2 transfer → Cloudflare R2: transfers blobs (evidence: `README.md`)
- Drive API worker → Filesystem routes: routes requests (evidence: `server/src/workers/api-worker/app.ts`)
- Drive API worker → Middleware pipeline: composes middleware (evidence: `server/src/workers/api-worker/app.ts`)
- Auth worker → Middleware pipeline: composes middleware (evidence: `server/src/workers/auth-worker/app.ts`)
- Filesystem routes → Node service: manages nodes (evidence: `server/src/workers/api-worker/fs-routes.ts`)
- Filesystem routes → Drive service: lists drives (evidence: `server/src/workers/api-worker/fs-routes.ts`)
- Filesystem routes → Authorization service: changes access (evidence: `server/src/workers/api-worker/fs-routes.ts`)
- Authorization engine → Policy evaluation: evaluates policy (evidence: `server/src/domain/engine/EngineAuthorizer.ts`)
- Authorization engine → Node service: filters trash (evidence: `server/src/domain/engine/EngineAuthorizer.ts`)
- Authorization service → Access model: resolves configuration (evidence: `server/src/domain/services/AuthzService.ts`)
- Postgres engine stores → Postgres: reads and writes (evidence: `server/src/adapters/postgres/PgEngineStores.ts`)
- R2 capabilities → Cloudflare R2: enables transfers (evidence: `README.md`)
- Filesystem routes → Drive doorbell: notifies changes (evidence: `server/src/workers/api-worker/fs-routes.ts`)
