# minji827/day68 architecture

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

- Interactive diagram: https://gitdiagram.com/minji827/day68
- Repository: https://github.com/minji827/day68

## Overview

DeltaWatch detects changes in corporate disclosures, financials, and interest-rate context, then presents review priorities and evidence-backed explanations. The main user workflow is entering a stock code in the local web app, which collects and loads data, runs change rules, optionally generates validated AI explanations, and refreshes the dashboard. The graph includes the documented Power BI and n8n capabilities and the separate pure-function rule engines. Edges rely on README statements or SOURCE INDEX references; unsampled implementation details are not inferred.

Main entry points: [`scripts/webapp.py`](https://github.com/minji827/day68/blob/main/scripts/webapp.py) (Live web app), [`scripts/collect.py`](https://github.com/minji827/day68/blob/main/scripts/collect.py) (Company collector), [`scripts/run_rules.py`](https://github.com/minji827/day68/blob/main/scripts/run_rules.py) (SQL rule runner), [`scripts/explain.py`](https://github.com/minji827/day68/blob/main/scripts/explain.py) (AI explanations)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_ingest["Data collection"]
  node_opendart["OpenDART client<br/>[opendart_client.py]"]
  node_ecos["ECOS client<br/>[ecos_client.py]"]
  node_collector["Company collector<br/>[collect.py]"]
end

subgraph group_data["Data platform"]
  node_raw[("RAW tables<br/>[002_raw.sql]")]
  node_rawloader["RAW loader<br/>[load_raw.py]"]
  node_core[("CORE tables<br/>[003_core.sql]")]
  node_coreloader["CORE transformer<br/>[load_core.py]"]
  node_mart[("MART tables<br/>[004_mart.sql]")]
  node_db["Database connections<br/>[db.py]"]
end

subgraph group_analysis["Change analysis"]
  node_rulesql["SQL rule runner<br/>[run_rules.py]"]
  node_rulev33["Rule engine v3.3<br/>[rule_engine_v33.py]"]
  node_rulev40["Rule engine v4.0<br/>[rule_engine_v40.py]"]
  node_domainmap["Rule domains<br/>[domain_map.py]"]
  node_sections["Disclosure sections<br/>[sections.py]"]
  node_xmlparser["DART XML parser<br/>[dart_xml.py]"]
  node_compare["Disclosure diff"]
  node_explainer["AI explanations<br/>[explain.py]"]
  node_quarterly["Quarterly analysis<br/>[quarterly.py]"]
end

subgraph group_experience["Review experience"]
  node_webapp["Live web app<br/>[webapp.py]"]
  node_frontend["Dashboard UI<br/>[index.html]"]
  node_export["Dashboard data export<br/>[data_export.py]"]
end

subgraph group_delivery["Reporting and alerts"]
  node_powerbi["Power BI sync<br/>[export_powerbi.py]"]
  node_powerbidb[("Power BI database<br/>[001_schema.sql]")]
  node_n8n["Weekly email workflow"]
end

node_user(("Analyst"))
node_openaiext["OpenAI API"]
node_powerbiuser(("Power BI consumer"))
node_email(("Email recipient"))

node_user -->|"enters stock code"| node_frontend
node_frontend -->|"requests analysis"| node_webapp
node_webapp -->|"resolves company"| node_opendart
node_webapp -->|"starts collection"| node_collector
node_collector -->|"fetches disclosures"| node_opendart
node_collector -->|"fetches rates"| node_ecos
node_collector -->|"saves raw data"| node_raw
node_webapp -->|"loads raw data"| node_rawloader
node_rawloader -.->|"writes records"| node_raw
node_webapp -->|"transforms records"| node_coreloader
node_coreloader -->|"reads raw data"| node_raw
node_coreloader -->|"writes normalized data"| node_core
node_webapp -->|"runs rules"| node_rulesql
node_rulesql -->|"reads core data"| node_core
node_rulesql -->|"writes change results"| node_mart
node_rulesql -->|"uses database connection"| node_db
node_rulev33 -->|"uses rule metadata"| node_domainmap
node_rulev40 -->|"uses rule metadata"| node_domainmap
node_webapp -->|"runs optional explanations"| node_explainer
node_explainer -->|"gets disclosure text"| node_sections
node_explainer -->|"reads and stores results"| node_db
node_sections -->|"downloads originals"| node_opendart
node_sections -->|"parses document"| node_xmlparser
node_explainer -->|"requests explanations"| node_openaiext
node_webapp -->|"exports dashboard data"| node_export
node_export -.->|"reads dashboard metrics"| node_mart
node_webapp -->|"serves dashboard"| node_frontend
node_webapp -->|"triggers sync"| node_powerbi
node_powerbi -->|"writes reporting tables"| node_powerbidb
node_powerbiuser -->|"views reports"| node_powerbidb
node_n8n -->|"sends weekly alerts"| node_email
node_compare -->|"compares disclosure sections"| node_sections
node_quarterly -->|"uses database connection"| node_db

click node_webapp "https://github.com/minji827/day68/blob/main/scripts/webapp.py"
click node_frontend "https://github.com/minji827/day68/blob/main/scripts/webapp_static/index.html"
click node_opendart "https://github.com/minji827/day68/blob/main/scripts/opendart_client.py"
click node_ecos "https://github.com/minji827/day68/blob/main/scripts/ecos_client.py"
click node_collector "https://github.com/minji827/day68/blob/main/scripts/collect.py"
click node_raw "https://github.com/minji827/day68/blob/main/sql/002_raw.sql"
click node_rawloader "https://github.com/minji827/day68/blob/main/scripts/load_raw.py"
click node_core "https://github.com/minji827/day68/blob/main/sql/003_core.sql"
click node_coreloader "https://github.com/minji827/day68/blob/main/scripts/load_core.py"
click node_mart "https://github.com/minji827/day68/blob/main/sql/004_mart.sql"
click node_rulesql "https://github.com/minji827/day68/blob/main/scripts/run_rules.py"
click node_rulev33 "https://github.com/minji827/day68/blob/main/src/rules/rule_engine_v33.py"
click node_rulev40 "https://github.com/minji827/day68/blob/main/src/rules/rule_engine_v40.py"
click node_domainmap "https://github.com/minji827/day68/blob/main/src/rules/domain_map.py"
click node_sections "https://github.com/minji827/day68/blob/main/scripts/sections.py"
click node_xmlparser "https://github.com/minji827/day68/blob/main/scripts/dart_xml.py"
click node_compare "https://github.com/minji827/day68/blob/main/scripts/compare_disclosure.py"
click node_explainer "https://github.com/minji827/day68/blob/main/scripts/explain.py"
click node_export "https://github.com/minji827/day68/blob/main/scripts/data_export.py"
click node_quarterly "https://github.com/minji827/day68/blob/main/scripts/quarterly.py"
click node_db "https://github.com/minji827/day68/blob/main/scripts/db.py"
click node_powerbi "https://github.com/minji827/day68/blob/main/scripts/export_powerbi.py"
click node_powerbidb "https://github.com/minji827/day68/blob/main/sql/powerbi/001_schema.sql"
click node_n8n "https://github.com/minji827/day68/blob/main/n8n/deltawatch_weekly_alert.json"

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_opendart,node_ecos,node_collector toneBlue
class node_raw,node_rawloader,node_core,node_coreloader,node_mart,node_db toneAmber
class node_rulesql,node_rulev33,node_rulev40,node_domainmap,node_sections,node_xmlparser,node_compare,node_explainer,node_quarterly,node_openaiext toneMint
class node_webapp,node_frontend,node_export toneRose
class node_powerbi,node_powerbidb,node_n8n,node_user,node_powerbiuser,node_email toneIndigo
```

## Components

### Data collection

- [OpenDART client](https://github.com/minji827/day68/blob/main/scripts/opendart_client.py): `scripts/opendart_client.py`
- [ECOS client](https://github.com/minji827/day68/blob/main/scripts/ecos_client.py): `scripts/ecos_client.py`
- [Company collector](https://github.com/minji827/day68/blob/main/scripts/collect.py): `scripts/collect.py`

### Data platform

- [RAW tables](https://github.com/minji827/day68/blob/main/sql/002_raw.sql): `sql/002_raw.sql`
- [RAW loader](https://github.com/minji827/day68/blob/main/scripts/load_raw.py): `scripts/load_raw.py`
- [CORE tables](https://github.com/minji827/day68/blob/main/sql/003_core.sql): `sql/003_core.sql`
- [CORE transformer](https://github.com/minji827/day68/blob/main/scripts/load_core.py): `scripts/load_core.py`
- [MART tables](https://github.com/minji827/day68/blob/main/sql/004_mart.sql): `sql/004_mart.sql`
- [Database connections](https://github.com/minji827/day68/blob/main/scripts/db.py): `scripts/db.py`

### Change analysis

- [SQL rule runner](https://github.com/minji827/day68/blob/main/scripts/run_rules.py): `scripts/run_rules.py`
- [Rule engine v3.3](https://github.com/minji827/day68/blob/main/src/rules/rule_engine_v33.py): `src/rules/rule_engine_v33.py`
- [Rule engine v4.0](https://github.com/minji827/day68/blob/main/src/rules/rule_engine_v40.py): `src/rules/rule_engine_v40.py`
- [Rule domains](https://github.com/minji827/day68/blob/main/src/rules/domain_map.py): `src/rules/domain_map.py`
- [Disclosure sections](https://github.com/minji827/day68/blob/main/scripts/sections.py): `scripts/sections.py`
- [DART XML parser](https://github.com/minji827/day68/blob/main/scripts/dart_xml.py): `scripts/dart_xml.py`
- [Disclosure diff](https://github.com/minji827/day68/blob/main/scripts/compare_disclosure.py): `scripts/compare_disclosure.py`
- [AI explanations](https://github.com/minji827/day68/blob/main/scripts/explain.py): `scripts/explain.py`
- [Quarterly analysis](https://github.com/minji827/day68/blob/main/scripts/quarterly.py): `scripts/quarterly.py`

### Review experience

- [Live web app](https://github.com/minji827/day68/blob/main/scripts/webapp.py): `scripts/webapp.py`
- [Dashboard UI](https://github.com/minji827/day68/blob/main/scripts/webapp_static/index.html): `scripts/webapp_static/index.html`
- [Dashboard data export](https://github.com/minji827/day68/blob/main/scripts/data_export.py): `scripts/data_export.py`

### Reporting and alerts

- [Power BI sync](https://github.com/minji827/day68/blob/main/scripts/export_powerbi.py): `scripts/export_powerbi.py`
- [Power BI database](https://github.com/minji827/day68/blob/main/sql/powerbi/001_schema.sql): `sql/powerbi/001_schema.sql`
- [Weekly email workflow](https://github.com/minji827/day68/blob/main/n8n/deltawatch_weekly_alert.json): `n8n/deltawatch_weekly_alert.json`

### Other components

- **Analyst**
- **OpenAI API**
- **Power BI consumer**
- **Email recipient**

## Connections

- Analyst → Dashboard UI: enters stock code (evidence: `README.md`)
- Dashboard UI → Live web app: requests analysis (evidence: `README.md`)
- Live web app → OpenDART client: resolves company (evidence: `scripts/webapp.py`)
- Live web app → Company collector: starts collection (evidence: `README.md`)
- Company collector → OpenDART client: fetches disclosures (evidence: `scripts/collect.py`)
- Company collector → ECOS client: fetches rates (evidence: `scripts/collect.py`)
- Company collector → RAW tables: saves raw data (evidence: `README.md`)
- Live web app → RAW loader: loads raw data (evidence: `README.md`)
- RAW loader → RAW tables: writes records
- Live web app → CORE transformer: transforms records (evidence: `README.md`)
- CORE transformer → RAW tables: reads raw data (evidence: `README.md`)
- CORE transformer → CORE tables: writes normalized data (evidence: `README.md`)
- Live web app → SQL rule runner: runs rules (evidence: `README.md`)
- SQL rule runner → CORE tables: reads core data (evidence: `scripts/run_rules.py`)
- SQL rule runner → MART tables: writes change results (evidence: `README.md`)
- SQL rule runner → Database connections: uses database connection (evidence: `scripts/run_rules.py`)
- Rule engine v3.3 → Rule domains: uses rule metadata (evidence: `src/rules/rule_engine_v33.py`)
- Rule engine v4.0 → Rule domains: uses rule metadata (evidence: `src/rules/rule_engine_v40.py`)
- Live web app → AI explanations: runs optional explanations (evidence: `scripts/webapp.py`)
- AI explanations → Disclosure sections: gets disclosure text (evidence: `scripts/explain.py`)
- AI explanations → Database connections: reads and stores results (evidence: `scripts/explain.py`)
- Disclosure sections → OpenDART client: downloads originals (evidence: `scripts/sections.py`)
- Disclosure sections → DART XML parser: parses document (evidence: `scripts/sections.py`)
- AI explanations → OpenAI API: requests explanations (evidence: `scripts/explain.py`)
- Live web app → Dashboard data export: exports dashboard data (evidence: `scripts/webapp.py`)
- Dashboard data export → MART tables: reads dashboard metrics
- Live web app → Dashboard UI: serves dashboard (evidence: `README.md`)
- Live web app → Power BI sync: triggers sync (evidence: `scripts/webapp.py`)
- Power BI sync → Power BI database: writes reporting tables (evidence: `scripts/export_powerbi.py`)
- Power BI consumer → Power BI database: views reports (evidence: `README.md`)
- Weekly email workflow → Email recipient: sends weekly alerts (evidence: `README.md`)
- Disclosure diff → Disclosure sections: compares disclosure sections (evidence: `scripts/compare_disclosure.py`)
- Quarterly analysis → Database connections: uses database connection (evidence: `scripts/quarterly.py`)
