# syschat0/docugen architecture

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

- Interactive diagram: https://gitdiagram.com/syschat0/docugen
- Repository: https://github.com/syschat0/docugen

## Overview

LLM Document Agent is a FastAPI document-writing product with a static web UI and SQLite persistence. The main workflow creates a project, gathers and saves intake answers when needed, then runs staged research and writing; users can review progress and retrieve the resulting draft and artifacts. The README also documents document-type profiles, source and citation quality checks, project settings, and optional illustration generation. The large repository module owns much of the workflow orchestration. Some subsystem links below are documented capabilities; unsampled implementation details are not asserted.

Main entry points: [`app/db/repositories.py`](https://github.com/syschat0/docugen/blob/main/app/db/repositories.py) (Workflow orchestration), [`app/services/search.py`](https://github.com/syschat0/docugen/blob/main/app/services/search.py) (Research search), [`app/main.py`](https://github.com/syschat0/docugen/blob/main/app/main.py) (FastAPI app), [`app/services/llm.py`](https://github.com/syschat0/docugen/blob/main/app/services/llm.py) (LLM writing)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_app["Application and API"]
  node_ui["Web UI<br/>[app.js]"]
  node_main["FastAPI app<br/>[main.py]"]
  node_projects_api["Projects API<br/>[projects.py]"]
  node_workflow_api["Workflow API<br/>[workflow.py]"]
  node_questions_api["Questions API<br/>[questions.py]"]
  node_artifacts_api["Artifacts API<br/>[artifacts.py]"]
  node_settings_api["Settings API<br/>[settings.py]"]
end

subgraph group_workflow["Writing workflow"]
  node_pipeline["Workflow orchestration<br/>[repositories.py]"]
  node_llm["LLM writing<br/>[llm.py]"]
  node_doc_types["Document profiles<br/>[doc_types.py]"]
  node_citations["Citation handling<br/>[citations.py]"]
  node_image_gen["Illustration generation<br/>[image_gen.py]"]
end

subgraph group_research["Research and quality"]
  node_search["Research search<br/>[search.py]"]
  node_browser_search["Browser search<br/>[browser_search.py]"]
  node_google_pse["Google PSE<br/>[google_pse.py]"]
  node_quality["Quality checks<br/>[quality.py]"]
  node_evidence["Evidence validation<br/>[evidence.py]"]
end

subgraph group_storage["Persistence and settings"]
  node_database[("SQLite database<br/>[session.py]")]
  node_llm_settings["LLM settings<br/>[llm_settings.py]"]
  node_image_settings["Image settings<br/>[image_settings.py]"]
  node_search_options["Search options<br/>[search_options.py]"]
  node_config["Runtime configuration<br/>[config.py]"]
end

node_user(("Writer"))

node_user -.->|"uses"| node_ui
node_ui -.->|"starts writing"| node_workflow_api
node_main -->|"mounts"| node_projects_api
node_main -->|"mounts"| node_workflow_api
node_main -->|"mounts"| node_questions_api
node_main -->|"mounts"| node_artifacts_api
node_main -->|"mounts"| node_settings_api
node_projects_api -->|"calls"| node_pipeline
node_projects_api -->|"reads profiles"| node_doc_types
node_projects_api -->|"reads defaults"| node_search_options
node_workflow_api -->|"calls"| node_pipeline
node_workflow_api -->|"uses run control"| node_database
node_questions_api -->|"calls"| node_pipeline
node_artifacts_api -->|"calls"| node_pipeline
node_settings_api -->|"configures"| node_llm_settings
node_settings_api -->|"configures"| node_image_settings
node_pipeline -->|"reads and writes"| node_database
node_pipeline -->|"runs stages"| node_llm
node_pipeline -->|"requests research"| node_search
node_pipeline -->|"uses"| node_citations
node_pipeline -->|"checks drafts"| node_quality
node_pipeline -.->|"validates evidence"| node_evidence
node_pipeline -->|"generates images"| node_image_gen
node_search -->|"searches pages"| node_browser_search
node_search -->|"uses engine"| node_google_pse
node_search -->|"ranks sources"| node_quality
node_browser_search -->|"uses engine"| node_google_pse
node_llm -->|"uses"| node_citations
node_llm -->|"uses profiles"| node_doc_types
node_quality -->|"uses validation"| node_evidence
node_llm_settings -->|"stores settings"| node_database
node_image_settings -->|"stores settings"| node_database
node_llm -->|"resolves provider"| node_llm_settings
node_search -->|"reads options"| node_search_options
node_llm -->|"reads options"| node_search_options
node_llm_settings -->|"uses defaults"| node_config
node_search -->|"uses defaults"| node_config

click node_ui "https://github.com/syschat0/docugen/blob/main/app/static/app.js"
click node_main "https://github.com/syschat0/docugen/blob/main/app/main.py"
click node_projects_api "https://github.com/syschat0/docugen/blob/main/app/api/projects.py"
click node_workflow_api "https://github.com/syschat0/docugen/blob/main/app/api/workflow.py"
click node_questions_api "https://github.com/syschat0/docugen/blob/main/app/api/questions.py"
click node_artifacts_api "https://github.com/syschat0/docugen/blob/main/app/api/artifacts.py"
click node_settings_api "https://github.com/syschat0/docugen/blob/main/app/api/settings.py"
click node_pipeline "https://github.com/syschat0/docugen/blob/main/app/db/repositories.py"
click node_llm "https://github.com/syschat0/docugen/blob/main/app/services/llm.py"
click node_doc_types "https://github.com/syschat0/docugen/blob/main/app/services/doc_types.py"
click node_citations "https://github.com/syschat0/docugen/blob/main/app/services/citations.py"
click node_search "https://github.com/syschat0/docugen/blob/main/app/services/search.py"
click node_browser_search "https://github.com/syschat0/docugen/blob/main/app/services/browser_search.py"
click node_google_pse "https://github.com/syschat0/docugen/blob/main/app/services/google_pse.py"
click node_quality "https://github.com/syschat0/docugen/blob/main/app/services/quality.py"
click node_evidence "https://github.com/syschat0/docugen/blob/main/app/services/evidence.py"
click node_image_gen "https://github.com/syschat0/docugen/blob/main/app/services/image_gen.py"
click node_database "https://github.com/syschat0/docugen/blob/main/app/db/session.py"
click node_llm_settings "https://github.com/syschat0/docugen/blob/main/app/services/llm_settings.py"
click node_image_settings "https://github.com/syschat0/docugen/blob/main/app/services/image_settings.py"
click node_search_options "https://github.com/syschat0/docugen/blob/main/app/services/search_options.py"
click node_config "https://github.com/syschat0/docugen/blob/main/app/core/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_ui,node_main,node_projects_api,node_workflow_api,node_questions_api,node_artifacts_api,node_settings_api toneBlue
class node_pipeline,node_llm,node_doc_types,node_citations,node_image_gen toneAmber
class node_search,node_browser_search,node_google_pse,node_quality,node_evidence toneMint
class node_database,node_llm_settings,node_image_settings,node_search_options,node_config toneRose
class node_user toneIndigo
```

## Components

### Application and API

- [Web UI](https://github.com/syschat0/docugen/blob/main/app/static/app.js): `app/static/app.js`
- [FastAPI app](https://github.com/syschat0/docugen/blob/main/app/main.py): `app/main.py`
- [Projects API](https://github.com/syschat0/docugen/blob/main/app/api/projects.py): `app/api/projects.py`
- [Workflow API](https://github.com/syschat0/docugen/blob/main/app/api/workflow.py): `app/api/workflow.py`
- [Questions API](https://github.com/syschat0/docugen/blob/main/app/api/questions.py): `app/api/questions.py`
- [Artifacts API](https://github.com/syschat0/docugen/blob/main/app/api/artifacts.py): `app/api/artifacts.py`
- [Settings API](https://github.com/syschat0/docugen/blob/main/app/api/settings.py): `app/api/settings.py`

### Writing workflow

- [Workflow orchestration](https://github.com/syschat0/docugen/blob/main/app/db/repositories.py): `app/db/repositories.py`
- [LLM writing](https://github.com/syschat0/docugen/blob/main/app/services/llm.py): `app/services/llm.py`
- [Document profiles](https://github.com/syschat0/docugen/blob/main/app/services/doc_types.py): `app/services/doc_types.py`
- [Citation handling](https://github.com/syschat0/docugen/blob/main/app/services/citations.py): `app/services/citations.py`
- [Illustration generation](https://github.com/syschat0/docugen/blob/main/app/services/image_gen.py): `app/services/image_gen.py`

### Research and quality

- [Research search](https://github.com/syschat0/docugen/blob/main/app/services/search.py): `app/services/search.py`
- [Browser search](https://github.com/syschat0/docugen/blob/main/app/services/browser_search.py): `app/services/browser_search.py`
- [Google PSE](https://github.com/syschat0/docugen/blob/main/app/services/google_pse.py): `app/services/google_pse.py`
- [Quality checks](https://github.com/syschat0/docugen/blob/main/app/services/quality.py): `app/services/quality.py`
- [Evidence validation](https://github.com/syschat0/docugen/blob/main/app/services/evidence.py): `app/services/evidence.py`

### Persistence and settings

- [SQLite database](https://github.com/syschat0/docugen/blob/main/app/db/session.py): `app/db/session.py`
- [LLM settings](https://github.com/syschat0/docugen/blob/main/app/services/llm_settings.py): `app/services/llm_settings.py`
- [Image settings](https://github.com/syschat0/docugen/blob/main/app/services/image_settings.py): `app/services/image_settings.py`
- [Search options](https://github.com/syschat0/docugen/blob/main/app/services/search_options.py): `app/services/search_options.py`
- [Runtime configuration](https://github.com/syschat0/docugen/blob/main/app/core/config.py): `app/core/config.py`

### Other components

- **Writer**

## Connections

- Writer → Web UI: uses (evidence: `README.md`)
- Web UI → Workflow API: starts writing (evidence: `README.md`)
- FastAPI app → Projects API: mounts (evidence: `app/main.py`)
- FastAPI app → Workflow API: mounts (evidence: `app/main.py`)
- FastAPI app → Questions API: mounts (evidence: `app/main.py`)
- FastAPI app → Artifacts API: mounts (evidence: `app/main.py`)
- FastAPI app → Settings API: mounts (evidence: `app/main.py`)
- Projects API → Workflow orchestration: calls (evidence: `app/api/projects.py`)
- Projects API → Document profiles: reads profiles (evidence: `app/api/projects.py`)
- Projects API → Search options: reads defaults (evidence: `app/api/projects.py`)
- Workflow API → Workflow orchestration: calls (evidence: `app/api/workflow.py`)
- Workflow API → SQLite database: uses run control (evidence: `app/api/workflow.py`)
- Questions API → Workflow orchestration: calls (evidence: `app/api/questions.py`)
- Artifacts API → Workflow orchestration: calls (evidence: `app/api/artifacts.py`)
- Settings API → LLM settings: configures (evidence: `app/api/settings.py`)
- Settings API → Image settings: configures (evidence: `app/api/settings.py`)
- Workflow orchestration → SQLite database: reads and writes (evidence: `app/db/repositories.py`)
- Workflow orchestration → LLM writing: runs stages (evidence: `app/db/repositories.py`)
- Workflow orchestration → Research search: requests research (evidence: `app/db/repositories.py`)
- Workflow orchestration → Citation handling: uses (evidence: `app/db/repositories.py`)
- Workflow orchestration → Quality checks: checks drafts (evidence: `app/db/repositories.py`)
- Workflow orchestration → Evidence validation: validates evidence
- Workflow orchestration → Illustration generation: generates images (evidence: `app/db/repositories.py`)
- Research search → Browser search: searches pages (evidence: `app/services/search.py`)
- Research search → Google PSE: uses engine (evidence: `app/services/search.py`)
- Research search → Quality checks: ranks sources (evidence: `app/services/search.py`)
- Browser search → Google PSE: uses engine (evidence: `app/services/browser_search.py`)
- LLM writing → Citation handling: uses (evidence: `app/services/llm.py`)
- LLM writing → Document profiles: uses profiles (evidence: `app/services/llm.py`)
- Quality checks → Evidence validation: uses validation (evidence: `app/services/quality.py`)
- LLM settings → SQLite database: stores settings (evidence: `app/services/llm_settings.py`)
- Image settings → SQLite database: stores settings (evidence: `app/services/image_settings.py`)
- LLM writing → LLM settings: resolves provider (evidence: `app/services/llm.py`)
- Research search → Search options: reads options (evidence: `app/services/search.py`)
- LLM writing → Search options: reads options (evidence: `app/services/llm.py`)
- LLM settings → Runtime configuration: uses defaults (evidence: `app/services/llm_settings.py`)
- Research search → Runtime configuration: uses defaults (evidence: `app/services/search.py`)
