# 4bits-capstone/konverter_full_pipeline architecture

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

- Interactive diagram: https://gitdiagram.com/4bits-capstone/konverter_full_pipeline
- Repository: https://github.com/4bits-capstone/konverter_full_pipeline

## Overview

#### Purpose and entry points
Konverter is a document-conversion and review system for turning uploaded PDFs into structured, publishable outputs with confidence/audit visibility. The FastAPI backend starts at `backend/app/main.py`; the Vite/React client starts at `src/main.tsx` and composes the application in `src/App.tsx` / `src/ConverterApp.tsx`.

#### Frontend workflow shell
The UI models a multi-stage document workflow, with route/workflow definitions in `src/config/workflow.ts` and route helpers in `src/lib/converterRoutes.ts`. `src/components/AppShell.tsx` provides shared layout, while `src/components/StageRail.tsx` exposes pipeline progress. Document-centric pages cover upload, review, metadata, preview, history, and administrative operations under `src/pages/`.

#### Client state, API boundary, and contracts
`src/state/KonverterContext.tsx` is the central client-side document/workflow state boundary. API calls flow through `src/services/httpClient.ts` and `src/services/fastApi.ts`, against typed service contracts in `src/services/contracts.ts`. Domain types reside in `src/types/konverter.ts`; this keeps page/components decoupled from FastAPI transport details.

#### Backend API and service orchestration
`backend/app/main.py` defines the FastAPI application and HTTP entry boundary. `backend/app/service.py` coordinates document operations and persistence-facing behavior, with request/domain models in `backend/app/models.py`. Runtime options, page limits, confidence thresholds, OCR/table/device settings, and URL/publication defaults are centralized in `backend/app/config.py`.

#### Conversion and structure pipeline
`backend/app/pipeline.py` is the core PDF/Docling conversion stage, configurable for CPU, CUDA, or auto device selection and optional OCR/table structure extraction. Derived content is then interpreted through `backend/app/visual_structure.py`, `backend/app/toc_hierarchy.py`, and `backend/app/metadata_rules.py` to establish visual/document hierarchy and publication metadata. This is the key boundary between raw converter output and reviewable structured content.

#### Publication, media, and storage outputs
`backend/app/exporter.py` creates downstream publication/export representations, including HTML assembled by `backend/app/preview_html.py`. `backend/app/media.py` manages document media assets; `backend/app/storage.py` provides the persistence/storage boundary for uploaded and generated artifacts. Public URL construction can use configured site, page-template, and API-origin values.

#### Security, audit, and infrastructure
Authentication/authorization is split between frontend Supabase integration (`src/lib/supabaseClient.ts`, `src/lib/useIsAdmin.ts`) and backend verification/privileged access in `backend/app/auth.py`. Admin-gated UI uses `src/components/AuthGate.tsx` and `src/components/RequireAdmin.tsx`. `backend/app/audit.py` records material actions, surfaced by `src/pages/AuditLogPage.tsx`; backend logging is managed in `backend/app/logging_utils.py`. Material runtimes are Node 20+ for React/Vite and Python 3.11/3.12 for FastAPI/Docling, with Supabase as the external identity service and optional CUDA-enabled PyTorch acceleration.

Main entry points: [`backend/app/service.py`](https://github.com/4bits-capstone/konverter_full_pipeline/blob/main/backend/app/service.py) (Document service), [`src/ConverterApp.tsx`](https://github.com/4bits-capstone/konverter_full_pipeline/blob/main/src/ConverterApp.tsx) (Converter application), [`backend/app/main.py`](https://github.com/4bits-capstone/konverter_full_pipeline/blob/main/backend/app/main.py) (FastAPI application), [`src/components/AppShell.tsx`](https://github.com/4bits-capstone/konverter_full_pipeline/blob/main/src/components/AppShell.tsx) (Workflow UI shell)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["React client"]
  node_client_entry["Vite entry<br/>React bootstrap<br/>[main.tsx]"]
  node_app["Converter application<br/>workflow composition<br/>[ConverterApp.tsx]"]
  node_workflow["Workflow routing<br/>stage definitions<br/>[workflow.ts]"]
  node_ui_shell["Workflow UI shell<br/>layout and stage rail<br/>[AppShell.tsx]"]
  node_client_state["Document state<br/>client workflow state"]
  node_api_client["Typed API client<br/>transport and contracts<br/>[fastApi.ts]"]
  node_client_auth["Client auth gates<br/>Supabase and admin access<br/>[supabaseClient.ts]"]
end

subgraph group_backend["FastAPI backend"]
  node_api["FastAPI application<br/>HTTP entry point<br/>[main.py]"]
  node_service["Document service<br/>operation orchestration<br/>[service.py]"]
  node_backend_auth["Backend authorization<br/>token verification<br/>[auth.py]"]
  node_storage[("Artifact storage<br/>persistence boundary<br/>[storage.py]")]
  node_audit[("Audit trail<br/>material action logging<br/>[audit.py]")]
  node_runtime_config["Runtime configuration<br/>conversion and publication settings<br/>[config.py]"]
end

subgraph group_pipeline["Conversion pipeline"]
  node_conversion["PDF conversion<br/>Docling pipeline<br/>[pipeline.py]"]
  node_structure["Document structure<br/>hierarchy interpretation"]
  node_export["Publication export<br/>output generation<br/>[exporter.py]"]
  node_media["Media assets<br/>asset management<br/>[media.py]"]
end

subgraph group_external["External services"]
  node_supabase[("Supabase<br/>external identity service")]
end

node_client_entry -->|"mounts"| node_app
node_app -->|"uses stages"| node_workflow
node_app -->|"renders"| node_ui_shell
node_ui_shell -->|"reads and updates"| node_client_state
node_client_state -->|"invokes"| node_api_client
node_client_auth -->|"authenticates with"| node_supabase
node_client_auth -->|"gates admin UI"| node_ui_shell
node_api_client -->|"HTTP requests"| node_api
node_api -->|"authorizes"| node_backend_auth
node_backend_auth -->|"verifies identity"| node_supabase
node_api -->|"dispatches operations"| node_service
node_service -->|"converts uploads"| node_conversion
node_conversion -->|"produces raw content"| node_structure
node_structure -->|"supplies structured content"| node_export
node_service -->|"manages assets"| node_media
node_service -->|"persists artifacts"| node_storage
node_export -->|"stores outputs"| node_storage
node_service -->|"records actions"| node_audit
node_runtime_config -.->|"configures"| node_conversion
node_runtime_config -.->|"sets publication defaults"| node_export

click node_client_entry "https://github.com/4bits-capstone/konverter_full_pipeline/blob/main/src/main.tsx"
click node_app "https://github.com/4bits-capstone/konverter_full_pipeline/blob/main/src/ConverterApp.tsx"
click node_workflow "https://github.com/4bits-capstone/konverter_full_pipeline/blob/main/src/config/workflow.ts"
click node_ui_shell "https://github.com/4bits-capstone/konverter_full_pipeline/blob/main/src/components/AppShell.tsx"
click node_client_state "https://github.com/4bits-capstone/konverter_full_pipeline/blob/main/src/state/KonverterContext.tsx"
click node_api_client "https://github.com/4bits-capstone/konverter_full_pipeline/blob/main/src/services/fastApi.ts"
click node_client_auth "https://github.com/4bits-capstone/konverter_full_pipeline/blob/main/src/lib/supabaseClient.ts"
click node_api "https://github.com/4bits-capstone/konverter_full_pipeline/blob/main/backend/app/main.py"
click node_service "https://github.com/4bits-capstone/konverter_full_pipeline/blob/main/backend/app/service.py"
click node_backend_auth "https://github.com/4bits-capstone/konverter_full_pipeline/blob/main/backend/app/auth.py"
click node_storage "https://github.com/4bits-capstone/konverter_full_pipeline/blob/main/backend/app/storage.py"
click node_audit "https://github.com/4bits-capstone/konverter_full_pipeline/blob/main/backend/app/audit.py"
click node_conversion "https://github.com/4bits-capstone/konverter_full_pipeline/blob/main/backend/app/pipeline.py"
click node_structure "https://github.com/4bits-capstone/konverter_full_pipeline/blob/main/backend/app/visual_structure.py"
click node_export "https://github.com/4bits-capstone/konverter_full_pipeline/blob/main/backend/app/exporter.py"
click node_media "https://github.com/4bits-capstone/konverter_full_pipeline/blob/main/backend/app/media.py"
click node_runtime_config "https://github.com/4bits-capstone/konverter_full_pipeline/blob/main/backend/app/config.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_client_entry,node_app,node_workflow,node_ui_shell,node_client_state,node_api_client,node_client_auth toneBlue
class node_api,node_service,node_backend_auth,node_storage,node_audit,node_runtime_config toneAmber
class node_conversion,node_structure,node_export,node_media toneMint
class node_supabase toneRose
```

## Components

### React client

- [Vite entry](https://github.com/4bits-capstone/konverter_full_pipeline/blob/main/src/main.tsx): React bootstrap · `src/main.tsx`
- [Converter application](https://github.com/4bits-capstone/konverter_full_pipeline/blob/main/src/ConverterApp.tsx): workflow composition · `src/ConverterApp.tsx`
- [Workflow routing](https://github.com/4bits-capstone/konverter_full_pipeline/blob/main/src/config/workflow.ts): stage definitions · `src/config/workflow.ts`
- [Workflow UI shell](https://github.com/4bits-capstone/konverter_full_pipeline/blob/main/src/components/AppShell.tsx): layout and stage rail · Shared document pages expose progress, review, metadata, preview, history, and admin operations. · `src/components/AppShell.tsx`
- [Document state](https://github.com/4bits-capstone/konverter_full_pipeline/blob/main/src/state/KonverterContext.tsx): client workflow state · `src/state/KonverterContext.tsx`
- [Typed API client](https://github.com/4bits-capstone/konverter_full_pipeline/blob/main/src/services/fastApi.ts): transport and contracts · `src/services/fastApi.ts`
- [Client auth gates](https://github.com/4bits-capstone/konverter_full_pipeline/blob/main/src/lib/supabaseClient.ts): Supabase and admin access · `src/lib/supabaseClient.ts`

### FastAPI backend

- [FastAPI application](https://github.com/4bits-capstone/konverter_full_pipeline/blob/main/backend/app/main.py): HTTP entry point · `backend/app/main.py`
- [Document service](https://github.com/4bits-capstone/konverter_full_pipeline/blob/main/backend/app/service.py): operation orchestration · `backend/app/service.py`
- [Backend authorization](https://github.com/4bits-capstone/konverter_full_pipeline/blob/main/backend/app/auth.py): token verification · `backend/app/auth.py`
- [Artifact storage](https://github.com/4bits-capstone/konverter_full_pipeline/blob/main/backend/app/storage.py): persistence boundary · Stores uploaded and generated document artifacts. · `backend/app/storage.py`
- [Audit trail](https://github.com/4bits-capstone/konverter_full_pipeline/blob/main/backend/app/audit.py): material action logging · `backend/app/audit.py`
- [Runtime configuration](https://github.com/4bits-capstone/konverter_full_pipeline/blob/main/backend/app/config.py): conversion and publication settings · Centralizes limits, confidence thresholds, device, OCR, table, and URL defaults. · `backend/app/config.py`

### Conversion pipeline

- [PDF conversion](https://github.com/4bits-capstone/konverter_full_pipeline/blob/main/backend/app/pipeline.py): Docling pipeline · Runs CPU, CUDA, or automatic conversion with optional OCR and table extraction. · `backend/app/pipeline.py`
- [Document structure](https://github.com/4bits-capstone/konverter_full_pipeline/blob/main/backend/app/visual_structure.py): hierarchy interpretation · Transforms converter output into visual hierarchy, TOC structure, and publication metadata. · `backend/app/visual_structure.py`
- [Publication export](https://github.com/4bits-capstone/konverter_full_pipeline/blob/main/backend/app/exporter.py): output generation · Builds export representations and HTML previews. · `backend/app/exporter.py`
- [Media assets](https://github.com/4bits-capstone/konverter_full_pipeline/blob/main/backend/app/media.py): asset management · `backend/app/media.py`

### External services

- **Supabase**: external identity service

## Connections

- Vite entry → Converter application: mounts
- Converter application → Workflow routing: uses stages
- Converter application → Workflow UI shell: renders
- Workflow UI shell → Document state: reads and updates
- Document state → Typed API client: invokes
- Client auth gates → Supabase: authenticates with
- Client auth gates → Workflow UI shell: gates admin UI
- Typed API client → FastAPI application: HTTP requests
- FastAPI application → Backend authorization: authorizes
- Backend authorization → Supabase: verifies identity
- FastAPI application → Document service: dispatches operations
- Document service → PDF conversion: converts uploads
- PDF conversion → Document structure: produces raw content
- Document structure → Publication export: supplies structured content
- Document service → Media assets: manages assets
- Document service → Artifact storage: persists artifacts
- Publication export → Artifact storage: stores outputs
- Document service → Audit trail: records actions
- Runtime configuration → PDF conversion: configures
- Runtime configuration → Publication export: sets publication defaults
