# avalon-initiative/pyn architecture

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

- Interactive diagram: https://gitdiagram.com/avalon-initiative/pyn
- Repository: https://github.com/avalon-initiative/pyn

## Overview

pyn is a Git-compatible version-control server and CLI that adds policy-controlled exclusive paths and leased locks for files that should not be concurrently edited. The main workflow is a user invoking CLI commands, the CLI contacting the server, and core services applying access, policy, merge, and storage rules to repository changes. The README documents additional account, collaboration, remote-transfer, and Git interoperability capabilities. Some connections below rely on those README-level descriptions; unsampled implementation details are not asserted.

Main entry points: [`crates/pyn-core/src/service.rs`](https://github.com/avalon-initiative/pyn/blob/main/crates/pyn-core/src/service.rs) (Repository services), [`crates/pyn-cli/src/main.rs`](https://github.com/avalon-initiative/pyn/blob/main/crates/pyn-cli/src/main.rs) (pyn CLI), [`crates/pyn-core/src/store.rs`](https://github.com/avalon-initiative/pyn/blob/main/crates/pyn-core/src/store.rs) (Store contracts), [`crates/pyn-cli/src/client.rs`](https://github.com/avalon-initiative/pyn/blob/main/crates/pyn-cli/src/client.rs) (API client)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["Client workflow"]
  node_cli["pyn CLI<br/>[main.rs]"]
  node_cli_client["API client<br/>[client.rs]"]
end

subgraph group_server["Server API"]
  node_server["HTTP server<br/>[main.rs]"]
  node_routes["API routing<br/>[routes.rs]"]
  node_api_handlers["API handlers"]
end

subgraph group_domain["Repository domain"]
  node_core_service["Repository services<br/>[service.rs]"]
  node_policy["Path policy<br/>[rules.rs]"]
  node_locks["Leased locks<br/>[store.rs]"]
  node_merge["Merge and commits<br/>[merge.rs]"]
  node_history["History and branches<br/>[repo.rs]"]
  node_git_engine["Git interoperability<br/>[ingest.rs]"]
end

subgraph group_storage["Persistence and objects"]
  node_object_space["Object space<br/>[object_space.rs]"]
  node_store["Store contracts<br/>[store.rs]"]
  node_memory_store[("Memory backend<br/>[memory.rs]")]
  node_postgres[("Postgres backend<br/>[lib.rs]")]
  node_s3["S3 object storage<br/>[client.rs]"]
end

subgraph group_collab["Identity and collaboration"]
  node_access["Access control<br/>[access.rs]"]
  node_accounts["Accounts and orgs<br/>[access_service.rs]"]
  node_audit["Audit log<br/>[audit.rs]"]
  node_webhooks["Webhooks<br/>[webhook.rs]"]
end

node_user(("Repository user"))
node_remote(("Remote server"))

node_user -->|"runs commands"| node_cli
node_cli -->|"uses API"| node_cli_client
node_cli_client -->|"sends requests"| node_server
node_server -->|"routes requests"| node_routes
node_routes -->|"dispatches to"| node_api_handlers
node_api_handlers -.->|"applies operations"| node_core_service
node_core_service -->|"checks modes"| node_policy
node_core_service -.->|"enforces leases"| node_locks
node_core_service -.->|"merges changes"| node_merge
node_core_service -.->|"tracks revisions"| node_history
node_core_service -->|"accesses objects"| node_object_space
node_core_service -->|"uses contracts"| node_store
node_store -.->|"implemented by"| node_memory_store
node_store -.->|"implemented by"| node_postgres
node_object_space -.->|"stores objects"| node_s3
node_core_service -->|"checks permissions"| node_access
node_access -->|"supports identity"| node_accounts
node_core_service -.->|"records actions"| node_audit
node_core_service -.->|"emits events"| node_webhooks
node_cli -.->|"imports and exports"| node_git_engine
node_cli -->|"pushes and fetches"| node_remote

click node_cli "https://github.com/avalon-initiative/pyn/blob/main/crates/pyn-cli/src/main.rs"
click node_cli_client "https://github.com/avalon-initiative/pyn/blob/main/crates/pyn-cli/src/client.rs"
click node_server "https://github.com/avalon-initiative/pyn/blob/main/crates/pyn-server/src/main.rs"
click node_routes "https://github.com/avalon-initiative/pyn/blob/main/crates/pyn-server/src/routes.rs"
click node_api_handlers "https://github.com/avalon-initiative/pyn/tree/main/crates/pyn-server/src"
click node_core_service "https://github.com/avalon-initiative/pyn/blob/main/crates/pyn-core/src/service.rs"
click node_policy "https://github.com/avalon-initiative/pyn/blob/main/crates/pyn-core/src/rules.rs"
click node_locks "https://github.com/avalon-initiative/pyn/blob/main/crates/pyn-core/src/store.rs"
click node_merge "https://github.com/avalon-initiative/pyn/blob/main/crates/pyn-core/src/merge.rs"
click node_history "https://github.com/avalon-initiative/pyn/blob/main/crates/pyn-core/src/repo.rs"
click node_git_engine "https://github.com/avalon-initiative/pyn/blob/main/crates/pyn-git/src/ingest.rs"
click node_object_space "https://github.com/avalon-initiative/pyn/blob/main/crates/pyn-core/src/object_space.rs"
click node_store "https://github.com/avalon-initiative/pyn/blob/main/crates/pyn-core/src/store.rs"
click node_memory_store "https://github.com/avalon-initiative/pyn/blob/main/crates/pyn-core/src/memory.rs"
click node_postgres "https://github.com/avalon-initiative/pyn/blob/main/crates/pyn-postgres/src/lib.rs"
click node_s3 "https://github.com/avalon-initiative/pyn/blob/main/crates/pyn-s3/src/client.rs"
click node_access "https://github.com/avalon-initiative/pyn/blob/main/crates/pyn-core/src/access.rs"
click node_accounts "https://github.com/avalon-initiative/pyn/blob/main/crates/pyn-core/src/access_service.rs"
click node_audit "https://github.com/avalon-initiative/pyn/blob/main/crates/pyn-core/src/audit.rs"
click node_webhooks "https://github.com/avalon-initiative/pyn/blob/main/crates/pyn-core/src/webhook.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_cli,node_cli_client,node_user toneBlue
class node_server,node_routes,node_api_handlers toneAmber
class node_core_service,node_policy,node_locks,node_merge,node_history,node_git_engine,node_remote toneMint
class node_object_space,node_store,node_memory_store,node_postgres,node_s3 toneRose
class node_access,node_accounts,node_audit,node_webhooks toneIndigo
```

## Components

### Client workflow

- [pyn CLI](https://github.com/avalon-initiative/pyn/blob/main/crates/pyn-cli/src/main.rs): `crates/pyn-cli/src/main.rs`
- [API client](https://github.com/avalon-initiative/pyn/blob/main/crates/pyn-cli/src/client.rs): `crates/pyn-cli/src/client.rs`

### Server API

- [HTTP server](https://github.com/avalon-initiative/pyn/blob/main/crates/pyn-server/src/main.rs): `crates/pyn-server/src/main.rs`
- [API routing](https://github.com/avalon-initiative/pyn/blob/main/crates/pyn-server/src/routes.rs): `crates/pyn-server/src/routes.rs`
- [API handlers](https://github.com/avalon-initiative/pyn/tree/main/crates/pyn-server/src): `crates/pyn-server/src`

### Repository domain

- [Repository services](https://github.com/avalon-initiative/pyn/blob/main/crates/pyn-core/src/service.rs): `crates/pyn-core/src/service.rs`
- [Path policy](https://github.com/avalon-initiative/pyn/blob/main/crates/pyn-core/src/rules.rs): `crates/pyn-core/src/rules.rs`
- [Leased locks](https://github.com/avalon-initiative/pyn/blob/main/crates/pyn-core/src/store.rs): `crates/pyn-core/src/store.rs`
- [Merge and commits](https://github.com/avalon-initiative/pyn/blob/main/crates/pyn-core/src/merge.rs): `crates/pyn-core/src/merge.rs`
- [History and branches](https://github.com/avalon-initiative/pyn/blob/main/crates/pyn-core/src/repo.rs): `crates/pyn-core/src/repo.rs`
- [Git interoperability](https://github.com/avalon-initiative/pyn/blob/main/crates/pyn-git/src/ingest.rs): `crates/pyn-git/src/ingest.rs`

### Persistence and objects

- [Object space](https://github.com/avalon-initiative/pyn/blob/main/crates/pyn-core/src/object_space.rs): `crates/pyn-core/src/object_space.rs`
- [Store contracts](https://github.com/avalon-initiative/pyn/blob/main/crates/pyn-core/src/store.rs): `crates/pyn-core/src/store.rs`
- [Memory backend](https://github.com/avalon-initiative/pyn/blob/main/crates/pyn-core/src/memory.rs): `crates/pyn-core/src/memory.rs`
- [Postgres backend](https://github.com/avalon-initiative/pyn/blob/main/crates/pyn-postgres/src/lib.rs): `crates/pyn-postgres/src/lib.rs`
- [S3 object storage](https://github.com/avalon-initiative/pyn/blob/main/crates/pyn-s3/src/client.rs): `crates/pyn-s3/src/client.rs`

### Identity and collaboration

- [Access control](https://github.com/avalon-initiative/pyn/blob/main/crates/pyn-core/src/access.rs): `crates/pyn-core/src/access.rs`
- [Accounts and orgs](https://github.com/avalon-initiative/pyn/blob/main/crates/pyn-core/src/access_service.rs): `crates/pyn-core/src/access_service.rs`
- [Audit log](https://github.com/avalon-initiative/pyn/blob/main/crates/pyn-core/src/audit.rs): `crates/pyn-core/src/audit.rs`
- [Webhooks](https://github.com/avalon-initiative/pyn/blob/main/crates/pyn-core/src/webhook.rs): `crates/pyn-core/src/webhook.rs`

### Other components

- **Repository user**
- **Remote server**

## Connections

- Repository user → pyn CLI: runs commands
- pyn CLI → API client: uses API (evidence: `crates/pyn-cli/src/main.rs`)
- API client → HTTP server: sends requests
- HTTP server → API routing: routes requests (evidence: `crates/pyn-server/src/routes.rs`)
- API routing → API handlers: dispatches to (evidence: `crates/pyn-server/src/routes.rs`)
- API handlers → Repository services: applies operations
- Repository services → Path policy: checks modes (evidence: `crates/pyn-core/src/service.rs`)
- Repository services → Leased locks: enforces leases (evidence: `crates/pyn-core/src/service.rs`)
- Repository services → Merge and commits: merges changes (evidence: `crates/pyn-core/src/service.rs`)
- Repository services → History and branches: tracks revisions (evidence: `crates/pyn-core/src/service.rs`)
- Repository services → Object space: accesses objects (evidence: `crates/pyn-core/src/service.rs`)
- Repository services → Store contracts: uses contracts (evidence: `crates/pyn-core/src/service.rs`)
- Store contracts → Memory backend: implemented by (evidence: `crates/pyn-core/src/memory.rs`)
- Store contracts → Postgres backend: implemented by
- Object space → S3 object storage: stores objects
- Repository services → Access control: checks permissions (evidence: `crates/pyn-core/src/service.rs`)
- Access control → Accounts and orgs: supports identity (evidence: `crates/pyn-core/src/access.rs`)
- Repository services → Audit log: records actions (evidence: `crates/pyn-core/src/service.rs`)
- Repository services → Webhooks: emits events
- pyn CLI → Git interoperability: imports and exports
- pyn CLI → Remote server: pushes and fetches
