# chenwenyu1014/csr architecture

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

- Interactive diagram: https://gitdiagram.com/chenwenyu1014/csr
- Repository: https://github.com/chenwenyu1014/csr

## Overview

CSR Document Generation System turns project source files and data requirements into generated CSR narratives and completed Word documents. Its main workflow spans source validation and allocation, cross-platform file preprocessing, evidence extraction, LLM paragraph generation, and template insertion; separate API capabilities also support standalone preprocessing, insertion, allocation, validation, and document cleanup. Linux owns orchestration and model-facing work, while the Windows bridge handles Office-document operations. The README documents the overall service boundary; sampled source excerpts provide implementation detail for selected generation, model, and preprocessing components only.

Main entry points: [`api/linux/main.py`](https://github.com/chenwenyu1014/csr/blob/main/api/linux/main.py) (Linux API Routes), [`service/linux/bridge/windows_bridge_client.py`](https://github.com/chenwenyu1014/csr/blob/main/service/linux/bridge/windows_bridge_client.py) (Windows Bridge Client), [`api/linux/compose.py`](https://github.com/chenwenyu1014/csr/blob/main/api/linux/compose.py) (Compose Endpoint), [`service/linux/generation/pipeline.py`](https://github.com/chenwenyu1014/csr/blob/main/service/linux/generation/pipeline.py) (Generation Pipeline)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_linux_api["Linux API"]
  node_linux_routes["Linux API Routes<br/>[main.py]"]
  node_validation_api["Validation Endpoint<br/>[validation.py]"]
  node_allocation_api["Allocation Endpoint<br/>[allocation.py]"]
  node_preprocessing_api["Preprocessing Endpoint<br/>[preprocessing.py]"]
  node_generation_api["Generation Endpoint<br/>[generation.py]"]
  node_compose_api["Compose Endpoint<br/>[compose.py]"]
  node_insertion_api["Insertion Endpoint<br/>[insertion.py]"]
  node_postprocess_api["Cleanup Endpoint<br/>[postprocessing.py]"]
end

subgraph group_linux_workflows["CSR Workflows"]
  node_validation_service["Source Validation"]
  node_allocation_service["Data Allocation"]
  node_preprocessing_service["Preprocessing Tasks"]
  node_generation_flow["Generation Flow Controller<br/>[flow_controller.py]"]
  node_generation_pipeline["Generation Pipeline<br/>[pipeline.py]"]
  node_data_extractor["Data Extraction<br/>[data_extractor.py]"]
  node_paragraph_generation["Paragraph Generation"]
  node_template_service["Template Handling"]
  node_bridge_client["Windows Bridge Client"]
end

subgraph group_windows_processing["Windows Processing"]
  node_windows_bridge["Windows Bridge API<br/>[app.py]"]
  node_windows_preprocessing["Office File Processing<br/>[service.py]"]
  node_file_processor["Format Pipelines"]
  node_word_insertion["Word Insertion"]
end

subgraph group_model_layer["Models and Prompts"]
  node_llm_layer["LLM Model Services<br/>[model_service.py]"]
  node_prompt_manager["Prompt Management"]
end

node_user(("CSR User"))
node_office_com["Microsoft Office COM"]
node_ragflow["RAGFlow Retrieval<br/>[ragflow_client.py]"]

node_user -->|"calls API"| node_linux_routes
node_linux_routes -->|"dispatches"| node_validation_api
node_linux_routes -->|"dispatches"| node_allocation_api
node_linux_routes -->|"dispatches"| node_preprocessing_api
node_linux_routes -->|"dispatches"| node_generation_api
node_linux_routes -->|"dispatches"| node_compose_api
node_linux_routes -->|"dispatches"| node_insertion_api
node_linux_routes -->|"dispatches"| node_postprocess_api
node_validation_api -->|"validates source"| node_validation_service
node_allocation_api -->|"allocates data"| node_allocation_service
node_preprocessing_api -->|"starts tasks"| node_preprocessing_service
node_generation_api -->|"starts generation"| node_generation_flow
node_compose_api -->|"generates content"| node_generation_flow
node_compose_api -->|"requests insertion"| node_insertion_api
node_insertion_api -->|"requests insertion"| node_bridge_client
node_postprocess_api -->|"requests cleanup"| node_bridge_client
node_generation_flow -->|"runs pipeline"| node_generation_pipeline
node_generation_pipeline -->|"extracts evidence"| node_data_extractor
node_generation_pipeline -->|"generates paragraphs"| node_paragraph_generation
node_preprocessing_service -->|"forwards processing"| node_bridge_client
node_bridge_client -->|"sends HTTP"| node_windows_bridge
node_windows_bridge -->|"dispatches processing"| node_windows_preprocessing
node_windows_preprocessing -->|"processes formats"| node_file_processor
node_windows_bridge -->|"dispatches documents"| node_word_insertion
node_word_insertion -->|"controls Word"| node_office_com
node_paragraph_generation -->|"builds prompts"| node_prompt_manager
node_paragraph_generation -->|"requests generation"| node_llm_layer
node_validation_service -->|"requests validation"| node_llm_layer
node_llm_layer -.->|"retrieves context"| node_ragflow

click node_linux_routes "https://github.com/chenwenyu1014/csr/blob/main/api/linux/main.py"
click node_validation_api "https://github.com/chenwenyu1014/csr/blob/main/api/linux/validation.py"
click node_allocation_api "https://github.com/chenwenyu1014/csr/blob/main/api/linux/allocation.py"
click node_preprocessing_api "https://github.com/chenwenyu1014/csr/blob/main/api/linux/preprocessing.py"
click node_generation_api "https://github.com/chenwenyu1014/csr/blob/main/api/linux/generation.py"
click node_compose_api "https://github.com/chenwenyu1014/csr/blob/main/api/linux/compose.py"
click node_insertion_api "https://github.com/chenwenyu1014/csr/blob/main/api/linux/insertion.py"
click node_postprocess_api "https://github.com/chenwenyu1014/csr/blob/main/api/linux/postprocessing.py"
click node_validation_service "https://github.com/chenwenyu1014/csr/blob/main/service/linux/validation/validation_service.py"
click node_allocation_service "https://github.com/chenwenyu1014/csr/blob/main/service/linux/allocation/allocation_service.py"
click node_preprocessing_service "https://github.com/chenwenyu1014/csr/blob/main/service/linux/preprocessing/preprocessing_task_service.py"
click node_generation_flow "https://github.com/chenwenyu1014/csr/blob/main/service/linux/generation/flow_controller.py"
click node_generation_pipeline "https://github.com/chenwenyu1014/csr/blob/main/service/linux/generation/pipeline.py"
click node_data_extractor "https://github.com/chenwenyu1014/csr/blob/main/service/linux/generation/data_extractor.py"
click node_paragraph_generation "https://github.com/chenwenyu1014/csr/blob/main/service/linux/generation/paragraph_generation_service.py"
click node_template_service "https://github.com/chenwenyu1014/csr/blob/main/service/linux/template/template_service.py"
click node_bridge_client "https://github.com/chenwenyu1014/csr/blob/main/service/linux/bridge/windows_bridge_client.py"
click node_windows_bridge "https://github.com/chenwenyu1014/csr/blob/main/api/windows/app.py"
click node_windows_preprocessing "https://github.com/chenwenyu1014/csr/blob/main/service/windows/preprocessing/service.py"
click node_file_processor "https://github.com/chenwenyu1014/csr/tree/main/service/windows/preprocessing/preprocessing_function"
click node_word_insertion "https://github.com/chenwenyu1014/csr/blob/main/service/windows/insertion/word_document_service.py"
click node_llm_layer "https://github.com/chenwenyu1014/csr/blob/main/service/models/model_service.py"
click node_prompt_manager "https://github.com/chenwenyu1014/csr/blob/main/service/prompts/system_prompt_manager.py"
click node_ragflow "https://github.com/chenwenyu1014/csr/blob/main/utils/ragflow_client.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_linux_routes,node_validation_api,node_allocation_api,node_preprocessing_api,node_generation_api,node_compose_api,node_insertion_api,node_postprocess_api,node_user toneBlue
class node_validation_service,node_allocation_service,node_preprocessing_service,node_generation_flow,node_generation_pipeline,node_data_extractor,node_paragraph_generation,node_template_service,node_bridge_client toneAmber
class node_windows_bridge,node_windows_preprocessing,node_file_processor,node_word_insertion toneMint
class node_llm_layer,node_prompt_manager toneRose
class node_office_com toneIndigo
class node_ragflow toneTeal
```

## Components

### Linux API

- [Linux API Routes](https://github.com/chenwenyu1014/csr/blob/main/api/linux/main.py): `api/linux/main.py`
- [Validation Endpoint](https://github.com/chenwenyu1014/csr/blob/main/api/linux/validation.py): `api/linux/validation.py`
- [Allocation Endpoint](https://github.com/chenwenyu1014/csr/blob/main/api/linux/allocation.py): `api/linux/allocation.py`
- [Preprocessing Endpoint](https://github.com/chenwenyu1014/csr/blob/main/api/linux/preprocessing.py): `api/linux/preprocessing.py`
- [Generation Endpoint](https://github.com/chenwenyu1014/csr/blob/main/api/linux/generation.py): `api/linux/generation.py`
- [Compose Endpoint](https://github.com/chenwenyu1014/csr/blob/main/api/linux/compose.py): `api/linux/compose.py`
- [Insertion Endpoint](https://github.com/chenwenyu1014/csr/blob/main/api/linux/insertion.py): `api/linux/insertion.py`
- [Cleanup Endpoint](https://github.com/chenwenyu1014/csr/blob/main/api/linux/postprocessing.py): `api/linux/postprocessing.py`

### CSR Workflows

- [Source Validation](https://github.com/chenwenyu1014/csr/blob/main/service/linux/validation/validation_service.py): `service/linux/validation/validation_service.py`
- [Data Allocation](https://github.com/chenwenyu1014/csr/blob/main/service/linux/allocation/allocation_service.py): `service/linux/allocation/allocation_service.py`
- [Preprocessing Tasks](https://github.com/chenwenyu1014/csr/blob/main/service/linux/preprocessing/preprocessing_task_service.py): `service/linux/preprocessing/preprocessing_task_service.py`
- [Generation Flow Controller](https://github.com/chenwenyu1014/csr/blob/main/service/linux/generation/flow_controller.py): `service/linux/generation/flow_controller.py`
- [Generation Pipeline](https://github.com/chenwenyu1014/csr/blob/main/service/linux/generation/pipeline.py): `service/linux/generation/pipeline.py`
- [Data Extraction](https://github.com/chenwenyu1014/csr/blob/main/service/linux/generation/data_extractor.py): `service/linux/generation/data_extractor.py`
- [Paragraph Generation](https://github.com/chenwenyu1014/csr/blob/main/service/linux/generation/paragraph_generation_service.py): `service/linux/generation/paragraph_generation_service.py`
- [Template Handling](https://github.com/chenwenyu1014/csr/blob/main/service/linux/template/template_service.py): `service/linux/template/template_service.py`
- [Windows Bridge Client](https://github.com/chenwenyu1014/csr/blob/main/service/linux/bridge/windows_bridge_client.py): `service/linux/bridge/windows_bridge_client.py`

### Windows Processing

- [Windows Bridge API](https://github.com/chenwenyu1014/csr/blob/main/api/windows/app.py): `api/windows/app.py`
- [Office File Processing](https://github.com/chenwenyu1014/csr/blob/main/service/windows/preprocessing/service.py): `service/windows/preprocessing/service.py`
- [Format Pipelines](https://github.com/chenwenyu1014/csr/tree/main/service/windows/preprocessing/preprocessing_function): `service/windows/preprocessing/preprocessing_function`
- [Word Insertion](https://github.com/chenwenyu1014/csr/blob/main/service/windows/insertion/word_document_service.py): `service/windows/insertion/word_document_service.py`

### Models and Prompts

- [LLM Model Services](https://github.com/chenwenyu1014/csr/blob/main/service/models/model_service.py): `service/models/model_service.py`
- [Prompt Management](https://github.com/chenwenyu1014/csr/blob/main/service/prompts/system_prompt_manager.py): `service/prompts/system_prompt_manager.py`

### Other components

- **CSR User**
- **Microsoft Office COM**
- [RAGFlow Retrieval](https://github.com/chenwenyu1014/csr/blob/main/utils/ragflow_client.py): `utils/ragflow_client.py`

## Connections

- CSR User → Linux API Routes: calls API
- Linux API Routes → Validation Endpoint: dispatches
- Linux API Routes → Allocation Endpoint: dispatches
- Linux API Routes → Preprocessing Endpoint: dispatches
- Linux API Routes → Generation Endpoint: dispatches
- Linux API Routes → Compose Endpoint: dispatches
- Linux API Routes → Insertion Endpoint: dispatches
- Linux API Routes → Cleanup Endpoint: dispatches
- Validation Endpoint → Source Validation: validates source
- Allocation Endpoint → Data Allocation: allocates data
- Preprocessing Endpoint → Preprocessing Tasks: starts tasks
- Generation Endpoint → Generation Flow Controller: starts generation
- Compose Endpoint → Generation Flow Controller: generates content
- Compose Endpoint → Insertion Endpoint: requests insertion
- Insertion Endpoint → Windows Bridge Client: requests insertion
- Cleanup Endpoint → Windows Bridge Client: requests cleanup
- Generation Flow Controller → Generation Pipeline: runs pipeline
- Generation Pipeline → Data Extraction: extracts evidence
- Generation Pipeline → Paragraph Generation: generates paragraphs
- Preprocessing Tasks → Windows Bridge Client: forwards processing
- Windows Bridge Client → Windows Bridge API: sends HTTP
- Windows Bridge API → Office File Processing: dispatches processing
- Office File Processing → Format Pipelines: processes formats
- Windows Bridge API → Word Insertion: dispatches documents
- Word Insertion → Microsoft Office COM: controls Word
- Paragraph Generation → Prompt Management: builds prompts
- Paragraph Generation → LLM Model Services: requests generation
- Source Validation → LLM Model Services: requests validation
- LLM Model Services → RAGFlow Retrieval: retrieves context
