# cslawyer1985/contract-review-pro architecture

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

- Interactive diagram: https://gitdiagram.com/cslawyer1985/contract-review-pro
- Repository: https://github.com/cslawyer1985/contract-review-pro

## Overview

1. **Project shape**
   - This is a **Python-based contract review engine**, not a web application.
   - The repo is organized around a **library-style review pipeline** plus a top-level entrypoint in `main.py`.
   - `skill.json` and `prompt.md` indicate it is also packaged as a **Claude Skill / prompt-driven assistant**.

2. **Primary entrypoints**
   - `main.py` is the main orchestration layer exposed to callers.
   - The repository keeps prior implementations in `main_v1.0_backup.py` and `main_v2.py`, showing the system evolved through versioned rewrites.
   - The public API in the README centers on `quick_review()` and `advanced_review()`.

3. **Review pipeline boundary**
   - The core flow is: **contract text + user context → analysis → risk scoring → generated outputs**.
   - Inputs include raw contract text, contract name, and reviewer context such as party position, deal history, and focus area.
   - Outputs are structured review results, a legal opinion document, and an annotated contract with inline risk marks.

4. **Analysis subsystem**
   - `scripts/contract_analyzer.py` appears to be the first semantic layer: it identifies contract type and extracts key structure from the text.
   - `scripts/clause_review.py` likely performs clause-level inspection against standards and checklist items.
   - `scripts/sanguan_analysis.py` implements the project’s method framework, the “三观四步法” analysis across macro / meso / micro levels.

5. **Risk subsystem**
   - `scripts/risk_assessment.py` handles risk detection and classification.
   - `scripts/intelligent_scoring.py` computes the weighted score described in the README: **business 30% + legal 40% + practical 30%**.
   - Risk results are organized into severity bands, which drive downstream reporting and visual emphasis.

6. **Knowledge and rules data layer**
   - The `data/` directory is a key architectural boundary: the system is **data-driven** rather than hardcoded.
   - `contract_types.csv` provides the supported contract taxonomy.
   - `risk_templates.csv` contains the risk-point library.
   - `review_checklists.csv` contains macro/meso/micro checklist items.
   - `clause_standards.csv` stores standard clause patterns used during comparison and recommendation.

7. **Configuration and mode control**
   - `scripts/review_config.py` centralizes operational settings.
   - The README’s three review depths — **quick / standard / deep** — are likely mapped here and used to control analysis breadth, scoring detail, and output verbosity.
   - This is the main place where environment-independent behavior is normalized across modules.

8. **Document generation layer**
   - `scripts/document_generator.py` turns analysis results into user-facing artifacts.
   - The presence of `document_generator_v2.py` and a v1 backup suggests the output format changed significantly in v2.
   - This layer likely creates the legal opinion document and the annotated version of the original contract, separating computation from presentation.

9. **Maintenance / data expansion tools**
   - `scripts/generate_new_risks.py` is a utility for expanding the risk template library.
   - The CSV backups in `data/` (`*_backup.csv`, `*_new.csv`) indicate controlled evolution of the knowledge base.
   - This is important architecturally: the system can be updated by **editing the rule/data corpus** without rewriting the whole engine.

10. **Feedback and iteration loop**
   - `data_collection/` contains feedback JSON and summary CSV files.
   - This suggests a closed loop for capturing review results or user feedback and using them to improve templates, scoring, or checklist coverage.
   - It is a lightweight learning/monitoring boundary, not a model-training subsystem.

11. **Methodology layer**
   - The repo’s distinctive feature is the explicit encoding of legal methodology: **three perspectives** and **four steps**.
   - That methodology is not just documentation; it is implemented through the analysis modules and reflected in the scoring/reporting structure.
   - The architecture therefore combines **rule-based legal knowledge**, **structured method analysis**, and **template-driven output generation**.

12. **Runtime and dependencies**
   - The system is Python-centric and depends on common data/document tooling such as `pandas`, `python-docx`, and `jieba`; `hanlp` is optional for deeper NLP support.
   - No external SaaS, database, or web runtime is indicated in the repository structure.
   - This means the system is best understood as an **offline/local analysis engine** with file-based knowledge assets and generated document outputs.

13. **Versioning and operational maturity**
   - The presence of `V1.1_UPGRADE_SUMMARY.md`, `V1.2_UPGRADE_SUMMARY.md`, and `V2.0_UPGRADE_GUIDE.md` shows deliberate architectural evolution and backward compatibility concerns.
   - The backups in both code and data suggest changes are managed by versioned replacement rather than migrations.
   - For diagramming, it is useful to show a stable core pipeline with versioned implementations around it.

14. **Best architectural diagram focus**
   - The clearest system boundary is: **Caller / Skill prompt → `main.py` orchestrator → analysis and scoring modules → document generation → output artifacts**.
   - Beneath that, a second boundary is the **CSV knowledge base**, which supplies contract types, risk templates, clause standards, and checklists.
   - A third boundary is the **feedback/update loop** in `data_collection/`, which feeds future rule and template refinement.

Main entry points: [`main.py`](https://github.com/cslawyer1985/contract-review-pro/blob/main/main.py) (Main app), [`scripts/clause_review.py`](https://github.com/cslawyer1985/contract-review-pro/blob/main/scripts/clause_review.py) (Clause review), [`scripts/risk_assessment.py`](https://github.com/cslawyer1985/contract-review-pro/blob/main/scripts/risk_assessment.py) (Risk assess), [`scripts/document_generator.py`](https://github.com/cslawyer1985/contract-review-pro/blob/main/scripts/document_generator.py) (Doc generator)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["Entry & Prompting"]
  node_skill["Skill spec<br/>skill-config<br/>[skill.json]"]
  node_prompt["Prompt<br/>[prompt.md]"]
end

subgraph group_engine["Review Engine"]
  node_main["Main app<br/>orchestrator<br/>[main.py]"]
  node_analyzer["Analyzer<br/>nlp-extractor"]
  node_sanguan["三观分析<br/>method-framework"]
  node_clause["Clause review<br/>clause-checker<br/>[clause_review.py]"]
  node_risk["Risk assess<br/>risk-engine<br/>[risk_assessment.py]"]
  node_scoring["Scoring<br/>weighted-ranker"]
  node_config["Review config<br/>mode-config<br/>[review_config.py]"]
  node_docgen["Doc generator<br/>report-builder"]
  node_docgen2["Doc gen v2<br/>report-builder"]
end

subgraph group_knowledge["Knowledge Base"]
  node_contract_types["Contract types<br/>taxonomy-data<br/>[contract_types.csv]"]
  node_risk_templates["Risk templates<br/>rules-data<br/>[risk_templates.csv]"]
  node_checklists["Checklists<br/>criteria-data"]
  node_standards["Clause standards<br/>standards-data"]
end

subgraph group_ops["Feedback & Expansion"]
  node_feedback["Feedback log<br/>review-feedback"]
  node_risk_expander["Risk expand<br/>maintenance-tool"]
end

node_skill -->|"invoke"| node_main
node_prompt -->|"instruct"| node_main
node_main -->|"mode"| node_config
node_main -->|"parse"| node_analyzer
node_main -->|"method"| node_sanguan
node_main -->|"inspect"| node_clause
node_main -->|"assess"| node_risk
node_risk -->|"score"| node_scoring
node_analyzer -->|"lookup"| node_contract_types
node_clause -->|"compare"| node_standards
node_clause -->|"check"| node_checklists
node_risk -->|"match"| node_risk_templates
node_scoring -->|"rank"| node_docgen
node_main -->|"render"| node_docgen2
node_docgen -.->|"evolve"| node_docgen2
node_docgen2 -->|"emit"| node_feedback
node_feedback -.->|"refine"| node_risk_templates
node_risk_expander -->|"update"| node_risk_templates
node_main -->|"output"| node_docgen

click node_skill "https://github.com/cslawyer1985/contract-review-pro/blob/main/skill.json"
click node_prompt "https://github.com/cslawyer1985/contract-review-pro/blob/main/prompt.md"
click node_main "https://github.com/cslawyer1985/contract-review-pro/blob/main/main.py"
click node_analyzer "https://github.com/cslawyer1985/contract-review-pro/blob/main/scripts/contract_analyzer.py"
click node_sanguan "https://github.com/cslawyer1985/contract-review-pro/blob/main/scripts/sanguan_analysis.py"
click node_clause "https://github.com/cslawyer1985/contract-review-pro/blob/main/scripts/clause_review.py"
click node_risk "https://github.com/cslawyer1985/contract-review-pro/blob/main/scripts/risk_assessment.py"
click node_scoring "https://github.com/cslawyer1985/contract-review-pro/blob/main/scripts/intelligent_scoring.py"
click node_config "https://github.com/cslawyer1985/contract-review-pro/blob/main/scripts/review_config.py"
click node_docgen "https://github.com/cslawyer1985/contract-review-pro/blob/main/scripts/document_generator.py"
click node_docgen2 "https://github.com/cslawyer1985/contract-review-pro/blob/main/scripts/document_generator_v2.py"
click node_contract_types "https://github.com/cslawyer1985/contract-review-pro/blob/main/data/contract_types.csv"
click node_risk_templates "https://github.com/cslawyer1985/contract-review-pro/blob/main/data/risk_templates.csv"
click node_checklists "https://github.com/cslawyer1985/contract-review-pro/blob/main/data/review_checklists.csv"
click node_standards "https://github.com/cslawyer1985/contract-review-pro/blob/main/data/clause_standards.csv"
click node_feedback "https://github.com/cslawyer1985/contract-review-pro/blob/main/data_collection/feedback_summary.csv"
click node_risk_expander "https://github.com/cslawyer1985/contract-review-pro/blob/main/scripts/generate_new_risks.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_skill,node_prompt toneBlue
class node_main,node_analyzer,node_sanguan,node_clause,node_risk,node_scoring,node_config,node_docgen,node_docgen2 toneAmber
class node_contract_types,node_risk_templates,node_checklists,node_standards toneMint
class node_feedback,node_risk_expander toneRose
```

## Components

### Entry & Prompting

Top-level caller entrypoints and skill-facing prompt assets

- [Skill spec](https://github.com/cslawyer1985/contract-review-pro/blob/main/skill.json): skill-config · Claude Skill packaging and invocation metadata · `skill.json`
- [Prompt](https://github.com/cslawyer1985/contract-review-pro/blob/main/prompt.md): prompt-spec · Instruction prompt for the review assistant · `prompt.md`

### Review Engine

Core analysis, scoring, and document generation pipeline

- [Main app](https://github.com/cslawyer1985/contract-review-pro/blob/main/main.py): orchestrator · Primary entrypoint and review workflow coordinator · `main.py`
- [Analyzer](https://github.com/cslawyer1985/contract-review-pro/blob/main/scripts/contract_analyzer.py): nlp-extractor · Identifies contract type and extracts structure from text · `scripts/contract_analyzer.py`
- [三观分析](https://github.com/cslawyer1985/contract-review-pro/blob/main/scripts/sanguan_analysis.py): method-framework · Macro, meso, and micro legal analysis method implementation · `scripts/sanguan_analysis.py`
- [Clause review](https://github.com/cslawyer1985/contract-review-pro/blob/main/scripts/clause_review.py): clause-checker · Clause-level inspection against standards and checklist items · `scripts/clause_review.py`
- [Risk assess](https://github.com/cslawyer1985/contract-review-pro/blob/main/scripts/risk_assessment.py): risk-engine · Detects, classifies, and structures contractual risks · `scripts/risk_assessment.py`
- [Scoring](https://github.com/cslawyer1985/contract-review-pro/blob/main/scripts/intelligent_scoring.py): weighted-ranker · Computes weighted business, legal, and practical scores · `scripts/intelligent_scoring.py`
- [Review config](https://github.com/cslawyer1985/contract-review-pro/blob/main/scripts/review_config.py): mode-config · Centralizes quick, standard, and deep review behavior · `scripts/review_config.py`
- [Doc generator](https://github.com/cslawyer1985/contract-review-pro/blob/main/scripts/document_generator.py): report-builder · Produces legal opinion and annotated contract outputs · `scripts/document_generator.py`
- [Doc gen v2](https://github.com/cslawyer1985/contract-review-pro/blob/main/scripts/document_generator_v2.py): report-builder · Updated document generation implementation · `scripts/document_generator_v2.py`

### Knowledge Base

Data-driven contract taxonomy, templates, standards, and checklists

- [Contract types](https://github.com/cslawyer1985/contract-review-pro/blob/main/data/contract_types.csv): taxonomy-data · Supported contract classification library · `data/contract_types.csv`
- [Risk templates](https://github.com/cslawyer1985/contract-review-pro/blob/main/data/risk_templates.csv): rules-data · Library of risk points and reusable findings · `data/risk_templates.csv`
- [Checklists](https://github.com/cslawyer1985/contract-review-pro/blob/main/data/review_checklists.csv): criteria-data · Macro, meso, and micro review checklist items · `data/review_checklists.csv`
- [Clause standards](https://github.com/cslawyer1985/contract-review-pro/blob/main/data/clause_standards.csv): standards-data · Reference clause patterns for comparison and recommendations · `data/clause_standards.csv`

### Feedback & Expansion

Captured feedback and utilities for evolving the rule corpus

- [Feedback log](https://github.com/cslawyer1985/contract-review-pro/blob/main/data_collection/feedback_summary.csv): review-feedback · Captured review feedback and summary records · `data_collection/feedback_summary.csv`
- [Risk expand](https://github.com/cslawyer1985/contract-review-pro/blob/main/scripts/generate_new_risks.py): maintenance-tool · Utility for generating or extending risk templates · `scripts/generate_new_risks.py`

## Connections

- Skill spec → Main app: invoke · Skill packaging routes requests into the main orchestrator
- Prompt → Main app: instruct · Prompt provides operating instructions and review framing
- Main app → Review config: mode · Main workflow selects quick, standard, or deep review settings
- Main app → Analyzer: parse · Initial text analysis extracts contract structure and type
- Main app → 三观分析: method · Applies the three-perspective legal method framework
- Main app → Clause review: inspect · Runs clause-level comparison and checklist evaluation
- Main app → Risk assess: assess · Consolidates findings into risks and severity bands
- Risk assess → Scoring: score · Risk findings feed weighted scoring and ranking
- Analyzer → Contract types: lookup · Contract classification relies on taxonomy data
- Clause review → Clause standards: compare · Clause review uses standard patterns as reference
- Clause review → Checklists: check · Checklist items guide clause coverage and review depth
- Risk assess → Risk templates: match · Risk detection is driven by the risk-point library
- Scoring → Doc generator: rank · Scores and severities are formatted into final outputs
- Main app → Doc gen v2: render · Newer output generation path for artifacts
- Doc generator → Doc gen v2: evolve · Versioned document generation replacement path
- Doc gen v2 → Feedback log: emit · Generated reviews and outcomes are captured for iteration
- Feedback log → Risk templates: refine · Feedback supports template expansion and tuning
- Risk expand → Risk templates: update · Utility expands or regenerates risk library entries
- Main app → Doc generator: output · Produces legal opinion documents and annotated contracts
