# thuenen-forest-ecosystems/tfm-server architecture

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

- Interactive diagram: https://gitdiagram.com/thuenen-forest-ecosystems/tfm-server
- Repository: https://github.com/thuenen-forest-ecosystems/tfm-server

## Overview

TFM Server is a self-hosted Supabase/Postgres backend with PowerSync for local development and data synchronization. The main documented workflow is deploying the services, applying database migrations, and exposing the resulting schema through the REST API. The tree indicates distinct records, inventory, derived-data, and workflow domains, plus authentication and sync configuration. The excerpts do not show most service wiring or SQL behavior, so those relationships are omitted or marked unverified; the migration-classification tool is included as a substantial indexed module, not as runtime application flow.

Main entry points: [`volumes/db`](https://github.com/thuenen-forest-ecosystems/tfm-server/tree/main/volumes/db) (Postgres database), [`supabase/config.toml`](https://github.com/thuenen-forest-ecosystems/tfm-server/blob/main/supabase/config.toml) (Supabase services), [`supabase/migrations`](https://github.com/thuenen-forest-ecosystems/tfm-server/tree/main/supabase/migrations) (Database migrations), [`Dockerfile.auth`](https://github.com/thuenen-forest-ecosystems/tfm-server/blob/main/Dockerfile.auth) (Authentication)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_platform["Backend platform"]
  node_supabase["Supabase services<br/>[config.toml]"]
  node_postgres[("Postgres database")]
  node_auth["Authentication<br/>[Dockerfile.auth]"]
  node_rest["REST API"]
end

subgraph group_domain["Data domains"]
  node_records["Records"]
  node_inventory["Inventory archive"]
  node_derived["Derived calculations"]
  node_workflow["Record workflow"]
  node_plausibility["Plausibility validation"]
end

subgraph group_sync["Sync and access"]
  node_powersync["PowerSync<br/>[powersync.yaml]"]
  node_sync_rules["Sync rules<br/>[sync_rules.yaml]"]
  node_webhook["Auth hook<br/>[pull.js]"]
  node_pooler["Connection pooler<br/>[pooler.exs]"]
end

subgraph group_operations["Schema operations"]
  node_migrations["Database migrations"]
  node_classifier["Migration classifier"]
end

node_developer(("Developer"))

node_developer -->|"starts locally"| node_supabase
node_developer -->|"applies migrations"| node_migrations
node_migrations -->|"changes schema"| node_postgres
node_postgres -->|"serves schema"| node_rest
node_supabase -->|"starts alongside"| node_powersync
node_classifier -.->|"classifies files"| node_migrations
node_records -.->|"defines data"| node_postgres
node_inventory -.->|"defines data"| node_postgres
node_derived -.->|"defines calculations"| node_postgres
node_workflow -.->|"defines workflow"| node_postgres
node_sync_rules -.->|"configures sync"| node_powersync
node_auth -.->|"integrates with"| node_supabase
node_webhook -.->|"supports auth"| node_auth
node_pooler -.->|"pools connections"| node_postgres

click node_supabase "https://github.com/thuenen-forest-ecosystems/tfm-server/blob/main/supabase/config.toml"
click node_postgres "https://github.com/thuenen-forest-ecosystems/tfm-server/tree/main/volumes/db"
click node_auth "https://github.com/thuenen-forest-ecosystems/tfm-server/blob/main/Dockerfile.auth"
click node_rest "https://github.com/thuenen-forest-ecosystems/tfm-server/tree/main/volumes/api"
click node_records "https://github.com/thuenen-forest-ecosystems/tfm-server/blob/main/supabase/migrations/20260206000000_records_messages.sql"
click node_inventory "https://github.com/thuenen-forest-ecosystems/tfm-server/blob/main/supabase/migrations/20250115140817_inventory_archive.sql"
click node_derived "https://github.com/thuenen-forest-ecosystems/tfm-server/blob/main/supabase/migrations/20260401000000_derived_calculations.sql"
click node_workflow "https://github.com/thuenen-forest-ecosystems/tfm-server/blob/main/supabase/migrations/20260825000000_workflow_code.sql"
click node_plausibility "https://github.com/thuenen-forest-ecosystems/tfm-server/blob/main/supabase/TFM/ci2027_plausability_0.0.1.js"
click node_powersync "https://github.com/thuenen-forest-ecosystems/tfm-server/blob/main/config/powersync.yaml"
click node_sync_rules "https://github.com/thuenen-forest-ecosystems/tfm-server/blob/main/config/sync_rules.yaml"
click node_webhook "https://github.com/thuenen-forest-ecosystems/tfm-server/blob/main/hook/pull.js"
click node_pooler "https://github.com/thuenen-forest-ecosystems/tfm-server/blob/main/volumes/pooler/pooler.exs"
click node_migrations "https://github.com/thuenen-forest-ecosystems/tfm-server/tree/main/supabase/migrations"
click node_classifier "https://github.com/thuenen-forest-ecosystems/tfm-server/blob/main/scripts/classify-migrations.py"

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_supabase,node_postgres,node_auth,node_rest toneBlue
class node_records,node_inventory,node_derived,node_workflow,node_plausibility toneAmber
class node_powersync,node_sync_rules,node_webhook,node_pooler toneMint
class node_migrations,node_classifier toneRose
class node_developer toneIndigo
```

## Components

### Backend platform

- [Supabase services](https://github.com/thuenen-forest-ecosystems/tfm-server/blob/main/supabase/config.toml): `supabase/config.toml`
- [Postgres database](https://github.com/thuenen-forest-ecosystems/tfm-server/tree/main/volumes/db): `volumes/db`
- [Authentication](https://github.com/thuenen-forest-ecosystems/tfm-server/blob/main/Dockerfile.auth): `Dockerfile.auth`
- [REST API](https://github.com/thuenen-forest-ecosystems/tfm-server/tree/main/volumes/api): `volumes/api`

### Data domains

- [Records](https://github.com/thuenen-forest-ecosystems/tfm-server/blob/main/supabase/migrations/20260206000000_records_messages.sql): `supabase/migrations/20260206000000_records_messages.sql`
- [Inventory archive](https://github.com/thuenen-forest-ecosystems/tfm-server/blob/main/supabase/migrations/20250115140817_inventory_archive.sql): `supabase/migrations/20250115140817_inventory_archive.sql`
- [Derived calculations](https://github.com/thuenen-forest-ecosystems/tfm-server/blob/main/supabase/migrations/20260401000000_derived_calculations.sql): `supabase/migrations/20260401000000_derived_calculations.sql`
- [Record workflow](https://github.com/thuenen-forest-ecosystems/tfm-server/blob/main/supabase/migrations/20260825000000_workflow_code.sql): `supabase/migrations/20260825000000_workflow_code.sql`
- [Plausibility validation](https://github.com/thuenen-forest-ecosystems/tfm-server/blob/main/supabase/TFM/ci2027_plausability_0.0.1.js): `supabase/TFM/ci2027_plausability_0.0.1.js`

### Sync and access

- [PowerSync](https://github.com/thuenen-forest-ecosystems/tfm-server/blob/main/config/powersync.yaml): `config/powersync.yaml`
- [Sync rules](https://github.com/thuenen-forest-ecosystems/tfm-server/blob/main/config/sync_rules.yaml): `config/sync_rules.yaml`
- [Auth hook](https://github.com/thuenen-forest-ecosystems/tfm-server/blob/main/hook/pull.js): `hook/pull.js`
- [Connection pooler](https://github.com/thuenen-forest-ecosystems/tfm-server/blob/main/volumes/pooler/pooler.exs): `volumes/pooler/pooler.exs`

### Schema operations

- [Database migrations](https://github.com/thuenen-forest-ecosystems/tfm-server/tree/main/supabase/migrations): `supabase/migrations`
- [Migration classifier](https://github.com/thuenen-forest-ecosystems/tfm-server/blob/main/scripts/classify-migrations.py): `scripts/classify-migrations.py`

### Other components

- **Developer**

## Connections

- Developer → Supabase services: starts locally (evidence: `README.md`)
- Developer → Database migrations: applies migrations (evidence: `README.md`)
- Database migrations → Postgres database: changes schema (evidence: `README.md`)
- Postgres database → REST API: serves schema (evidence: `README.md`)
- Supabase services → PowerSync: starts alongside (evidence: `README.md`)
- Migration classifier → Database migrations: classifies files
- Records → Postgres database: defines data
- Inventory archive → Postgres database: defines data
- Derived calculations → Postgres database: defines calculations
- Record workflow → Postgres database: defines workflow
- Sync rules → PowerSync: configures sync
- Authentication → Supabase services: integrates with
- Auth hook → Authentication: supports auth
- Connection pooler → Postgres database: pools connections
