# dev-strzx9/sop-template architecture

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

- Interactive diagram: https://gitdiagram.com/dev-strzx9/sop-template
- Repository: https://github.com/dev-strzx9/sop-template

## Overview

SOP Studio is a browser-based SOP editor backed by a FastAPI service and external PostgreSQL. Users open the editor, browse or search documents, open and edit a SOP, then save a new version; the server validates and derives searchable fields, resolves cross-SOP references, and persists document/version data. Separate capabilities include version history and diffs, edit locks, reference browsing, and the flowchart editor. The graph reflects the README and sampled source; unsampled implementation details are omitted where relationships are not evidenced.

Main entry points: [`app/main.py`](https://github.com/dev-strzx9/sop-template/blob/main/app/main.py) (FastAPI app), [`app/sop/sops.py`](https://github.com/dev-strzx9/sop-template/blob/main/app/sop/sops.py) (Document API), [`app/core/db.py`](https://github.com/dev-strzx9/sop-template/blob/main/app/core/db.py) (DB connection pool), [`app/sop/versions.py`](https://github.com/dev-strzx9/sop-template/blob/main/app/sop/versions.py) (Version history)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_presentation["Editor"]
  node_editor["SOP Studio editor<br/>[sopstudio.html]"]
  node_flowchart_editor["Flowchart editor<br/>[flowchart.html]"]
end

subgraph group_service["API service"]
  node_app_entry["Server startup<br/>[app.py]"]
  node_app["FastAPI app<br/>[main.py]"]
  node_identity["User header<br/>[deps.py]"]
  node_error_handling["Error responses<br/>[errors.py]"]
  node_config["Runtime settings<br/>[config.py]"]
  node_core_schemas["Health schemas<br/>[schemas.py]"]
end

subgraph group_domain["SOP domain"]
  node_sop_api["Document API<br/>[sops.py]"]
  node_validation["Document validation<br/>[derive.py]"]
  node_reference_logic["SOP references<br/>[refs.py]"]
  node_shared_logic["Shared SOP helpers<br/>[common.py]"]
  node_version_api["Version history<br/>[versions.py]"]
  node_lock_api["Edit locks<br/>[locks.py]"]
  node_sop_schemas["SOP API schemas<br/>[schemas.py]"]
end

subgraph group_persistence["Persistence"]
  node_db_access["DB connection pool<br/>[db.py]"]
  node_schema_setup["Schema setup<br/>[apply_schema.py]"]
  node_postgres[("PostgreSQL")]
  node_db_design["SOP tables<br/>[schema.sql]"]
  node_db_migrations["Schema migrations"]
end

node_user(("SOP editor user"))

node_user -->|"opens"| node_editor
node_editor -->|"uses API"| node_app
node_user -.->|"edits flows"| node_flowchart_editor
node_app_entry -.->|"starts"| node_app
node_app -->|"loads settings"| node_config
node_app -->|"opens pool"| node_db_access
node_app -->|"guards APIs"| node_identity
node_app -->|"installs handlers"| node_error_handling
node_app -->|"returns health"| node_core_schemas
node_app -->|"mounts router"| node_sop_api
node_app -->|"serves page"| node_editor
node_app -->|"pings"| node_db_access
node_db_access -->|"uses settings"| node_config
node_db_access -->|"connects"| node_postgres
node_schema_setup -->|"reads connection"| node_config
node_schema_setup -->|"applies schema"| node_postgres
node_schema_setup -.->|"loads design"| node_db_design
node_schema_setup -.->|"applies changes"| node_db_migrations
node_sop_api -->|"queries"| node_db_access
node_sop_api -->|"validates"| node_validation
node_sop_api -->|"resolves references"| node_reference_logic
node_sop_api -->|"uses helpers"| node_shared_logic
node_sop_api -->|"uses models"| node_sop_schemas
node_version_api -->|"queries"| node_db_access
node_version_api -->|"loads references"| node_reference_logic
node_version_api -->|"uses helpers"| node_shared_logic
node_version_api -->|"uses models"| node_sop_schemas
node_lock_api -->|"queries"| node_db_access
node_lock_api -->|"gets user"| node_identity
node_lock_api -->|"uses helpers"| node_shared_logic
node_lock_api -->|"uses models"| node_sop_schemas
node_shared_logic -->|"returns lock model"| node_sop_schemas
node_sop_api -.->|"raises API errors"| node_error_handling
node_validation -->|"raises validation errors"| node_error_handling

click node_editor "https://github.com/dev-strzx9/sop-template/blob/main/static/sop/sopstudio.html"
click node_flowchart_editor "https://github.com/dev-strzx9/sop-template/blob/main/static/sop/flowchart.html"
click node_app_entry "https://github.com/dev-strzx9/sop-template/blob/main/app.py"
click node_app "https://github.com/dev-strzx9/sop-template/blob/main/app/main.py"
click node_identity "https://github.com/dev-strzx9/sop-template/blob/main/app/core/deps.py"
click node_error_handling "https://github.com/dev-strzx9/sop-template/blob/main/app/core/errors.py"
click node_config "https://github.com/dev-strzx9/sop-template/blob/main/app/core/config.py"
click node_db_access "https://github.com/dev-strzx9/sop-template/blob/main/app/core/db.py"
click node_schema_setup "https://github.com/dev-strzx9/sop-template/blob/main/app/core/apply_schema.py"
click node_db_design "https://github.com/dev-strzx9/sop-template/blob/main/sql/sop/schema.sql"
click node_db_migrations "https://github.com/dev-strzx9/sop-template/tree/main/sql/sop/migrations"
click node_sop_api "https://github.com/dev-strzx9/sop-template/blob/main/app/sop/sops.py"
click node_validation "https://github.com/dev-strzx9/sop-template/blob/main/app/sop/derive.py"
click node_reference_logic "https://github.com/dev-strzx9/sop-template/blob/main/app/sop/refs.py"
click node_shared_logic "https://github.com/dev-strzx9/sop-template/blob/main/app/sop/common.py"
click node_version_api "https://github.com/dev-strzx9/sop-template/blob/main/app/sop/versions.py"
click node_lock_api "https://github.com/dev-strzx9/sop-template/blob/main/app/sop/locks.py"
click node_sop_schemas "https://github.com/dev-strzx9/sop-template/blob/main/app/sop/schemas.py"
click node_core_schemas "https://github.com/dev-strzx9/sop-template/blob/main/app/core/schemas.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_editor,node_flowchart_editor,node_user toneBlue
class node_app_entry,node_app,node_identity,node_error_handling,node_config,node_core_schemas toneAmber
class node_sop_api,node_validation,node_reference_logic,node_shared_logic,node_version_api,node_lock_api,node_sop_schemas toneMint
class node_db_access,node_schema_setup,node_postgres,node_db_design,node_db_migrations toneRose
```

## Components

### Editor

- [SOP Studio editor](https://github.com/dev-strzx9/sop-template/blob/main/static/sop/sopstudio.html): `static/sop/sopstudio.html`
- [Flowchart editor](https://github.com/dev-strzx9/sop-template/blob/main/static/sop/flowchart.html): `static/sop/flowchart.html`

### API service

- [Server startup](https://github.com/dev-strzx9/sop-template/blob/main/app.py): `app.py`
- [FastAPI app](https://github.com/dev-strzx9/sop-template/blob/main/app/main.py): `app/main.py`
- [User header](https://github.com/dev-strzx9/sop-template/blob/main/app/core/deps.py): `app/core/deps.py`
- [Error responses](https://github.com/dev-strzx9/sop-template/blob/main/app/core/errors.py): `app/core/errors.py`
- [Runtime settings](https://github.com/dev-strzx9/sop-template/blob/main/app/core/config.py): `app/core/config.py`
- [Health schemas](https://github.com/dev-strzx9/sop-template/blob/main/app/core/schemas.py): `app/core/schemas.py`

### SOP domain

- [Document API](https://github.com/dev-strzx9/sop-template/blob/main/app/sop/sops.py): `app/sop/sops.py`
- [Document validation](https://github.com/dev-strzx9/sop-template/blob/main/app/sop/derive.py): `app/sop/derive.py`
- [SOP references](https://github.com/dev-strzx9/sop-template/blob/main/app/sop/refs.py): `app/sop/refs.py`
- [Shared SOP helpers](https://github.com/dev-strzx9/sop-template/blob/main/app/sop/common.py): `app/sop/common.py`
- [Version history](https://github.com/dev-strzx9/sop-template/blob/main/app/sop/versions.py): `app/sop/versions.py`
- [Edit locks](https://github.com/dev-strzx9/sop-template/blob/main/app/sop/locks.py): `app/sop/locks.py`
- [SOP API schemas](https://github.com/dev-strzx9/sop-template/blob/main/app/sop/schemas.py): `app/sop/schemas.py`

### Persistence

- [DB connection pool](https://github.com/dev-strzx9/sop-template/blob/main/app/core/db.py): `app/core/db.py`
- [Schema setup](https://github.com/dev-strzx9/sop-template/blob/main/app/core/apply_schema.py): `app/core/apply_schema.py`
- **PostgreSQL**
- [SOP tables](https://github.com/dev-strzx9/sop-template/blob/main/sql/sop/schema.sql): `sql/sop/schema.sql`
- [Schema migrations](https://github.com/dev-strzx9/sop-template/tree/main/sql/sop/migrations): `sql/sop/migrations`

### Other components

- **SOP editor user**

## Connections

- SOP editor user → SOP Studio editor: opens (evidence: `README.md`)
- SOP Studio editor → FastAPI app: uses API (evidence: `README.md`)
- SOP editor user → Flowchart editor: edits flows
- Server startup → FastAPI app: starts
- FastAPI app → Runtime settings: loads settings (evidence: `app/main.py`)
- FastAPI app → DB connection pool: opens pool (evidence: `app/main.py`)
- FastAPI app → User header: guards APIs (evidence: `app/main.py`)
- FastAPI app → Error responses: installs handlers (evidence: `app/main.py`)
- FastAPI app → Health schemas: returns health (evidence: `app/main.py`)
- FastAPI app → Document API: mounts router (evidence: `app/main.py`)
- FastAPI app → SOP Studio editor: serves page (evidence: `README.md`)
- FastAPI app → DB connection pool: pings (evidence: `app/main.py`)
- DB connection pool → Runtime settings: uses settings (evidence: `app/core/db.py`)
- DB connection pool → PostgreSQL: connects (evidence: `README.md`)
- Schema setup → Runtime settings: reads connection (evidence: `app/core/apply_schema.py`)
- Schema setup → PostgreSQL: applies schema (evidence: `README.md`)
- Schema setup → SOP tables: loads design
- Schema setup → Schema migrations: applies changes
- Document API → DB connection pool: queries (evidence: `app/sop/sops.py`)
- Document API → Document validation: validates (evidence: `app/sop/sops.py`)
- Document API → SOP references: resolves references (evidence: `app/sop/sops.py`)
- Document API → Shared SOP helpers: uses helpers (evidence: `app/sop/sops.py`)
- Document API → SOP API schemas: uses models (evidence: `app/sop/sops.py`)
- Version history → DB connection pool: queries (evidence: `app/sop/versions.py`)
- Version history → SOP references: loads references (evidence: `app/sop/versions.py`)
- Version history → Shared SOP helpers: uses helpers (evidence: `app/sop/versions.py`)
- Version history → SOP API schemas: uses models (evidence: `app/sop/versions.py`)
- Edit locks → DB connection pool: queries (evidence: `app/sop/locks.py`)
- Edit locks → User header: gets user (evidence: `app/sop/locks.py`)
- Edit locks → Shared SOP helpers: uses helpers (evidence: `app/sop/locks.py`)
- Edit locks → SOP API schemas: uses models (evidence: `app/sop/locks.py`)
- Shared SOP helpers → SOP API schemas: returns lock model (evidence: `app/sop/common.py`)
- Document API → Error responses: raises API errors (evidence: `app/sop/sops.py`)
- Document validation → Error responses: raises validation errors (evidence: `app/sop/derive.py`)
