# shyam7291/document-monitor architecture

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

- Interactive diagram: https://gitdiagram.com/shyam7291/document-monitor
- Repository: https://github.com/shyam7291/document-monitor

## Overview

#### Purpose and Entry Points
`document-monitor` is a file-backed document/URL monitoring pipeline. It scrapes source links, normalizes document records, compares them with known prior records, captures issues, and emits CSV reports. Primary executable entry points are `scrape.py` and the development variant `scrape_dev.py`.

#### Pipeline Orchestration
GitHub Actions divides execution into staged runs: initial processing, subsequent phases, and a parallel final phase. Workflows in `.github/workflows/run_p1.yml`, `.github/workflows/run_p2_p3.yml`, and `.github/workflows/run_p4_p5_parallel.yml` define the production control plane; `.github/workflows/run_test_dev.yml` supports development/testing runs.

#### Scraping and Link Acquisition
The scraper ingests and produces URL/link datasets. `scrape.py` is the main acquisition/processing boundary, with CSV inputs/outputs such as `raw_links.csv`, `raw_links_p2_p3_latest.csv`, and `test_urls.csv`. This is the likely external-network boundary: URL availability and document retrieval depend on remote sites.

#### Document Record Stages
Document data is partitioned by processing phase rather than held in a database. Early/intermediate outputs include `documents.csv`, `documents_p1.csv`, `documents_p2.csv`, and `documents_p3.csv`. Final parallel-phase shards are stored in `p4_p5/documents_p4_p5_01.csv` through `p4_p5/documents_p4_p5_06.csv`, enabling distributed or batched processing.

#### Identity, Change Detection, and State
Known-document datasets provide the comparison baseline for determining additions, changes, or removals: `known_documents.csv` and `p4_p5/known_documents_p4_p5.csv`. Canonical identity is explicitly materialized in `p4_p5/document_canonical_keys_p4_p5.csv`. Change/difference outputs are persisted in `diff.csv`, `diff_p4_p5.csv`, and `diffbackup.csv`; these CSVs are the pipeline’s durable state and handoff boundary between runs.

#### Validation and Issue Capture
Failures and anomalous records are captured separately from normal document outputs. Key artifacts are `capture_issues.csv`, `capture_issues_p2_p3_latest.csv`, and `p4_p5/capture_issues_p4_p5.csv`. URL-level outcomes are retained in `p4_p5/url_status_p4_p5.csv`, separating fetch/status diagnostics from document comparison results.

#### Reporting and Final Outputs
The pipeline produces consolidated outputs for consumers and run-level oversight. Main deliverables include `output.csv`, `output_test.csv`, and `p4_p5/output_p4_p5.csv`. Summary/reporting artifacts—`run_summary_master.csv`, `run_summary_v2.csv`, and `report_keywords.csv`—support aggregation, run tracking, and keyword-oriented reporting.

Main entry points: [`scrape.py`](https://github.com/shyam7291/document-monitor/blob/main/scrape.py) (Main scraper), [`run_summary_master.csv`](https://github.com/shyam7291/document-monitor/blob/main/run_summary_master.csv) (Run reporting), [`scrape_dev.py`](https://github.com/shyam7291/document-monitor/blob/main/scrape_dev.py) (Development scraper), [`raw_links.csv`](https://github.com/shyam7291/document-monitor/blob/main/raw_links.csv) (Link datasets)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_control["Workflow Control Plane"]
  node_workflow_p1["Phase 1 workflow<br/>GitHub Actions workflow<br/>[run_p1.yml]"]
  node_workflow_p2p3["Phases 2–3 workflow<br/>GitHub Actions workflow<br/>[run_p2_p3.yml]"]
  node_workflow_p4p5["Parallel phases 4–5<br/>GitHub Actions workflow"]
  node_workflow_dev["Development workflow<br/>GitHub Actions workflow<br/>[run_test_dev.yml]"]
end

subgraph group_processing["Processing Pipeline"]
  node_scraper["Main scraper<br/>Python entry point<br/>[scrape.py]"]
  node_dev_scraper["Development scraper<br/>Python entry point<br/>[scrape_dev.py]"]
  node_comparison["Change detection<br/>processing stage"]
end

subgraph group_state["CSV State and Outputs"]
  node_link_inputs["Link datasets<br/>CSV input/output<br/>[raw_links.csv]"]
  node_document_stages["Early document stages<br/>CSV stage outputs<br/>[documents_p1.csv]"]
  node_final_shards["Final document shards<br/>parallel CSV shards"]
  node_known_documents[("Known-document baseline<br/>CSV state")]
  node_canonical_keys["Canonical identities<br/>CSV identity index"]
  node_diff_state[("Difference state<br/>CSV state<br/>[diff.csv]")]
  node_issue_capture["Issue capture<br/>CSV diagnostics<br/>[capture_issues.csv]"]
  node_url_status["URL status diagnostics<br/>CSV diagnostics"]
  node_consumer_output["Consumer output<br/>CSV deliverable<br/>[output.csv]"]
  node_parallel_output["Final parallel output<br/>CSV deliverable<br/>[output_p4_p5.csv]"]
  node_reporting["Run reporting<br/>CSV reports"]
end

node_workflow_p1 -->|"runs"| node_scraper
node_workflow_p2p3 -->|"runs"| node_scraper
node_workflow_p4p5 -->|"runs in parallel"| node_scraper
node_workflow_dev -->|"runs"| node_dev_scraper
node_link_inputs -->|"URLs and links"| node_scraper
node_scraper -->|"normalizes"| node_document_stages
node_scraper -->|"writes phase 4–5 batches"| node_final_shards
node_scraper -->|"captures failures"| node_issue_capture
node_scraper -->|"records fetch status"| node_url_status
node_dev_scraper -.->|"uses test URLs"| node_link_inputs
node_document_stages -->|"candidate records"| node_comparison
node_final_shards -->|"parallel candidates"| node_comparison
node_known_documents -->|"prior baseline"| node_comparison
node_canonical_keys -->|"canonical identity"| node_comparison
node_comparison -->|"persists differences"| node_diff_state
node_comparison -->|"emits results"| node_consumer_output
node_comparison -->|"emits final results"| node_parallel_output
node_diff_state -.->|"informs next-run state"| node_known_documents
node_consumer_output -->|"summarizes"| node_reporting
node_parallel_output -->|"summarizes"| node_reporting
node_issue_capture -->|"tracks issues"| node_reporting
node_url_status -->|"tracks URL outcomes"| node_reporting

click node_workflow_p1 "https://github.com/shyam7291/document-monitor/blob/main/.github/workflows/run_p1.yml"
click node_workflow_p2p3 "https://github.com/shyam7291/document-monitor/blob/main/.github/workflows/run_p2_p3.yml"
click node_workflow_p4p5 "https://github.com/shyam7291/document-monitor/blob/main/.github/workflows/run_p4_p5_parallel.yml"
click node_workflow_dev "https://github.com/shyam7291/document-monitor/blob/main/.github/workflows/run_test_dev.yml"
click node_scraper "https://github.com/shyam7291/document-monitor/blob/main/scrape.py"
click node_dev_scraper "https://github.com/shyam7291/document-monitor/blob/main/scrape_dev.py"
click node_link_inputs "https://github.com/shyam7291/document-monitor/blob/main/raw_links.csv"
click node_document_stages "https://github.com/shyam7291/document-monitor/blob/main/documents_p1.csv"
click node_final_shards "https://github.com/shyam7291/document-monitor/blob/main/p4_p5/documents_p4_p5_01.csv"
click node_known_documents "https://github.com/shyam7291/document-monitor/blob/main/known_documents.csv"
click node_canonical_keys "https://github.com/shyam7291/document-monitor/blob/main/p4_p5/document_canonical_keys_p4_p5.csv"
click node_diff_state "https://github.com/shyam7291/document-monitor/blob/main/diff.csv"
click node_issue_capture "https://github.com/shyam7291/document-monitor/blob/main/capture_issues.csv"
click node_url_status "https://github.com/shyam7291/document-monitor/blob/main/p4_p5/url_status_p4_p5.csv"
click node_consumer_output "https://github.com/shyam7291/document-monitor/blob/main/output.csv"
click node_parallel_output "https://github.com/shyam7291/document-monitor/blob/main/p4_p5/output_p4_p5.csv"
click node_reporting "https://github.com/shyam7291/document-monitor/blob/main/run_summary_master.csv"

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_workflow_p1,node_workflow_p2p3,node_workflow_p4p5,node_workflow_dev toneBlue
class node_scraper,node_dev_scraper,node_comparison toneAmber
class node_link_inputs,node_document_stages,node_final_shards,node_known_documents,node_canonical_keys,node_diff_state,node_issue_capture,node_url_status,node_consumer_output,node_parallel_output,node_reporting toneMint
```

## Components

### Workflow Control Plane

GitHub Actions stages production and development runs.

- [Phase 1 workflow](https://github.com/shyam7291/document-monitor/blob/main/.github/workflows/run_p1.yml): GitHub Actions workflow · `.github/workflows/run_p1.yml`
- [Phases 2–3 workflow](https://github.com/shyam7291/document-monitor/blob/main/.github/workflows/run_p2_p3.yml): GitHub Actions workflow · `.github/workflows/run_p2_p3.yml`
- [Parallel phases 4–5](https://github.com/shyam7291/document-monitor/blob/main/.github/workflows/run_p4_p5_parallel.yml): GitHub Actions workflow · Runs final work in parallel shards. · `.github/workflows/run_p4_p5_parallel.yml`
- [Development workflow](https://github.com/shyam7291/document-monitor/blob/main/.github/workflows/run_test_dev.yml): GitHub Actions workflow · `.github/workflows/run_test_dev.yml`

### Processing Pipeline

Scraping, normalization, comparison, and issue capture.

- [Main scraper](https://github.com/shyam7291/document-monitor/blob/main/scrape.py): Python entry point · Acquires links and processes document records. · `scrape.py`
- [Development scraper](https://github.com/shyam7291/document-monitor/blob/main/scrape_dev.py): Python entry point · `scrape_dev.py`
- **Change detection**: processing stage · Classifies additions, changes, and removals against known records.

### CSV State and Outputs

File-backed handoffs, baselines, and reports.

- [Link datasets](https://github.com/shyam7291/document-monitor/blob/main/raw_links.csv): CSV input/output · Raw and test URLs feed acquisition. · `raw_links.csv`
- [Early document stages](https://github.com/shyam7291/document-monitor/blob/main/documents_p1.csv): CSV stage outputs · Phase-partitioned normalized document records. · `documents_p1.csv`
- [Final document shards](https://github.com/shyam7291/document-monitor/blob/main/p4_p5/documents_p4_p5_01.csv): parallel CSV shards · Six phase 4–5 batches enable parallel processing. · `p4_p5/documents_p4_p5_01.csv`
- [Known-document baseline](https://github.com/shyam7291/document-monitor/blob/main/known_documents.csv): CSV state · Prior records used for change detection. · `known_documents.csv`
- [Canonical identities](https://github.com/shyam7291/document-monitor/blob/main/p4_p5/document_canonical_keys_p4_p5.csv): CSV identity index · `p4_p5/document_canonical_keys_p4_p5.csv`
- [Difference state](https://github.com/shyam7291/document-monitor/blob/main/diff.csv): CSV state · Durable comparison handoff between runs. · `diff.csv`
- [Issue capture](https://github.com/shyam7291/document-monitor/blob/main/capture_issues.csv): CSV diagnostics · Separates anomalous or failed records from normal output. · `capture_issues.csv`
- [URL status diagnostics](https://github.com/shyam7291/document-monitor/blob/main/p4_p5/url_status_p4_p5.csv): CSV diagnostics · Retains fetch and availability outcomes. · `p4_p5/url_status_p4_p5.csv`
- [Consumer output](https://github.com/shyam7291/document-monitor/blob/main/output.csv): CSV deliverable · `output.csv`
- [Final parallel output](https://github.com/shyam7291/document-monitor/blob/main/p4_p5/output_p4_p5.csv): CSV deliverable · `p4_p5/output_p4_p5.csv`
- [Run reporting](https://github.com/shyam7291/document-monitor/blob/main/run_summary_master.csv): CSV reports · Run summaries and keyword-oriented reporting. · `run_summary_master.csv`

## Connections

- Phase 1 workflow → Main scraper: runs
- Phases 2–3 workflow → Main scraper: runs
- Parallel phases 4–5 → Main scraper: runs in parallel
- Development workflow → Development scraper: runs
- Link datasets → Main scraper: URLs and links
- Main scraper → Early document stages: normalizes
- Main scraper → Final document shards: writes phase 4–5 batches
- Main scraper → Issue capture: captures failures
- Main scraper → URL status diagnostics: records fetch status
- Development scraper → Link datasets: uses test URLs
- Early document stages → Change detection: candidate records
- Final document shards → Change detection: parallel candidates
- Known-document baseline → Change detection: prior baseline
- Canonical identities → Change detection: canonical identity
- Change detection → Difference state: persists differences
- Change detection → Consumer output: emits results
- Change detection → Final parallel output: emits final results
- Difference state → Known-document baseline: informs next-run state
- Consumer output → Run reporting: summarizes
- Final parallel output → Run reporting: summarizes
- Issue capture → Run reporting: tracks issues
- URL status diagnostics → Run reporting: tracks URL outcomes
