How cslawyer1985/contract-review-pro works
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 Main app · clause_review.py Clause review · risk_assessment.py Risk assess · document_generator.py Doc generator
Components 17
Entry & Prompting
Top-level caller entrypoints and skill-facing prompt assets
- Skill spec · Claude Skill packaging and invocation metadata
skill.json - Prompt · Instruction prompt for the review assistant
prompt.md
Review Engine
Core analysis, scoring, and document generation pipeline
- Main app · Primary entrypoint and review workflow coordinator
main.py - Analyzer · Identifies contract type and extracts structure from text
scripts/contract_analyzer.py - 三观分析 · Macro, meso, and micro legal analysis method implementation
scripts/sanguan_analysis.py - Clause review · Clause-level inspection against standards and checklist items
scripts/clause_review.py - Risk assess · Detects, classifies, and structures contractual risks
scripts/risk_assessment.py - Scoring · Computes weighted business, legal, and practical scores
scripts/intelligent_scoring.py - Review config · Centralizes quick, standard, and deep review behavior
scripts/review_config.py - Doc generator · Produces legal opinion and annotated contract outputs
scripts/document_generator.py - Doc gen v2 · Updated document generation implementation
scripts/document_generator_v2.py
Knowledge Base
Data-driven contract taxonomy, templates, standards, and checklists
- Contract types · Supported contract classification library
data/contract_types.csv - Risk templates · Library of risk points and reusable findings
data/risk_templates.csv - Checklists · Macro, meso, and micro review checklist items
data/review_checklists.csv - Clause standards · Reference clause patterns for comparison and recommendations
data/clause_standards.csv
Feedback & Expansion
Captured feedback and utilities for evolving the rule corpus
- Feedback log · Captured review feedback and summary records
data_collection/feedback_summary.csv - Risk expand · Utility for generating or extending risk templates
scripts/generate_new_risks.py
Connections 19
- 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