# reeperetter/legislation-monitor architecture

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

- Interactive diagram: https://gitdiagram.com/reeperetter/legislation-monitor
- Repository: https://github.com/reeperetter/legislation-monitor

## Overview

#### Purpose and Entry Points
This is a Python service for monitoring external government/news sources, parsing published items, storing normalized documents, and exposing operational/API and dashboard views. The runtime entry point is `app/main.py`; route modules are `app/api/document_router.py`, `app/api/source_router.py`, `app/api/parser_router.py`, and `app/api/monitor_router.py`.

#### HTTP Application and Presentation Boundary
`app/main.py` assembles the application and connects API routes, templates, and static assets. The API layer accepts document/source/parser/monitoring requests and delegates rather than directly handling persistence or scraping. Server-rendered dashboard pages live in `app/templates/dashboard.html`, `app/templates/documents.html`, and `app/templates/sources.html`; assets are under `app/static/css/style.css`.

#### Monitoring Orchestration
Monitoring is the control-plane workflow: it initiates source checks, coordinates parsers, and reports parser/monitor state. Its main components are `app/monitoring/monitor.py`, `app/monitoring/parser_manager.py`, and `app/services/monitoring_service.py`. The monitor-to-parser-manager boundary isolates scheduling/execution coordination from HTTP endpoints.

#### Source Acquisition and Parser Pipeline
Each supported publisher has source-specific acquisition and parsing implementations: `app/parsers/sources/diam.py`, `app/parsers/sources/kmu.py`, `app/parsers/sources/rada.py`, alongside matching parser modules such as `app/parsers/diam.py`, `app/parsers/kmu.py`, and `app/parsers/rada.py`. `app/parsers/base.py` establishes the parser abstraction. Provider modules (`app/providers/diam.py`, `app/providers/kmu.py`, `app/providers/rada.py`) form a further source-integration boundary, likely separating source/provider behavior from parse logic.

The README explicitly says to remove the `parsers` folder; this is a material planned architectural change because monitoring currently depends on `app/parsers/`.

#### Document and Source Domain
Persisted business entities include documents, sources, categories, keywords, users, and roles. Core models are `app/models/document.py`, `app/models/source.py`, `app/models/category.py`, with shared model behavior in `app/models/base_model.py`. DTO boundary definitions include `app/schemas/document_dto.py`.

#### Service and Repository Layers
Application services own domain workflows: `app/services/document_service.py`, `app/services/source_service.py`, and `app/services/rss_service.py`. Repositories isolate database reads/writes: `app/repositories/document_repository.py`, `app/repositories/source_repository.py`, and `app/repositories/base.py`. Expected primary flow is source configuration → acquisition/parser/provider processing → document normalization/service handling → repository persistence → document API/dashboard retrieval.

#### Persistence, Configuration, and External I/O
Database setup is centralized in `app/db/session.py`, `app/db/base.py`, and `app/db/init_db.py`; Alembic manages schema history through `alembic/env.py` and `alembic/versions/`. Schema migrations establish documents and source/keyword/category relations. Runtime configuration and outbound HTTP behavior are isolated in `app/core/config.py` and `app/core/http_client.py`; external dependencies are the monitored remote sources accessed over HTTP and the configured relational database.

Main entry points: [`app/repositories/document_repository.py`](https://github.com/reeperetter/legislation-monitor/blob/main/app/repositories/document_repository.py) (Document & Source Repositories), [`app/services/document_service.py`](https://github.com/reeperetter/legislation-monitor/blob/main/app/services/document_service.py) (Document Service), [`app/parsers/diam.py`](https://github.com/reeperetter/legislation-monitor/blob/main/app/parsers/diam.py) (Publisher Parsers), [`app/parsers/base.py`](https://github.com/reeperetter/legislation-monitor/blob/main/app/parsers/base.py) (Parser Abstraction)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_http["HTTP &amp; Dashboard"]
  node_app["Application Assembly<br/>FastAPI entrypoint<br/>[main.py]"]
  node_api["API Routes<br/>route modules"]
  node_dashboard["Dashboard Views<br/>server-rendered templates"]
end

subgraph group_monitoring["Monitoring"]
  node_monitor_service["Monitoring Service<br/>application service"]
  node_monitor["Monitor<br/>control-plane workflow<br/>[monitor.py]"]
  node_parser_manager["Parser Manager<br/>execution coordinator<br/>[parser_manager.py]"]
end

subgraph group_pipeline["Acquisition &amp; Parsing"]
  node_parser_base{{"Parser Abstraction<br/>parser interface<br/>[base.py]"}}
  node_source_adapters["Publisher Source Adapters<br/>source acquisition<br/>[diam.py]"]
  node_publisher_parsers["Publisher Parsers<br/>normalization pipeline<br/>[diam.py]"]
  node_providers["Provider Integrations<br/>source integration<br/>[diam.py]"]
  node_external_sources(("Government &amp; News Sources<br/>external HTTP systems"))
  node_http_client["HTTP Client<br/>outbound I/O<br/>[http_client.py]"]
  node_parser_removal["Planned Parser Removal<br/>planned change<br/>[README.md]"]
end

subgraph group_domain["Domain &amp; Persistence"]
  node_document_service["Document Service<br/>application service"]
  node_source_service["Source Service<br/>application service<br/>[source_service.py]"]
  node_repositories["Document &amp; Source Repositories<br/>data access layer"]
  node_models["Domain Models<br/>ORM entities<br/>[document.py]"]
  node_database[("Relational Database<br/>persistence")]
  node_db_setup["Database Setup &amp; Migrations<br/>schema management<br/>[session.py]"]
end

node_app -->|"registers"| node_api
node_app -->|"serves"| node_dashboard
node_api -->|"monitor requests"| node_monitor_service
node_api -->|"document requests"| node_document_service
node_api -->|"source requests"| node_source_service
node_monitor_service -->|"runs"| node_monitor
node_monitor -->|"coordinates"| node_parser_manager
node_parser_manager -->|"executes"| node_parser_base
node_parser_base -->|"implemented by"| node_publisher_parsers
node_publisher_parsers -->|"acquires through"| node_source_adapters
node_source_adapters -->|"integrates via"| node_providers
node_providers -->|"uses"| node_http_client
node_http_client -->|"HTTP access"| node_external_sources
node_publisher_parsers -->|"normalized documents"| node_document_service
node_source_service -->|"persists sources"| node_repositories
node_document_service -->|"persists and retrieves"| node_repositories
node_repositories -->|"maps"| node_models
node_repositories -->|"reads and writes"| node_database
node_db_setup -->|"initializes and migrates"| node_database
node_dashboard -->|"document views"| node_document_service
node_dashboard -->|"source views"| node_source_service
node_parser_removal -.->|"planned removal affects"| node_parser_base

click node_app "https://github.com/reeperetter/legislation-monitor/blob/main/app/main.py"
click node_monitor_service "https://github.com/reeperetter/legislation-monitor/blob/main/app/services/monitoring_service.py"
click node_monitor "https://github.com/reeperetter/legislation-monitor/blob/main/app/monitoring/monitor.py"
click node_parser_manager "https://github.com/reeperetter/legislation-monitor/blob/main/app/monitoring/parser_manager.py"
click node_parser_base "https://github.com/reeperetter/legislation-monitor/blob/main/app/parsers/base.py"
click node_source_adapters "https://github.com/reeperetter/legislation-monitor/blob/main/app/parsers/sources/diam.py"
click node_publisher_parsers "https://github.com/reeperetter/legislation-monitor/blob/main/app/parsers/diam.py"
click node_providers "https://github.com/reeperetter/legislation-monitor/blob/main/app/providers/diam.py"
click node_http_client "https://github.com/reeperetter/legislation-monitor/blob/main/app/core/http_client.py"
click node_document_service "https://github.com/reeperetter/legislation-monitor/blob/main/app/services/document_service.py"
click node_source_service "https://github.com/reeperetter/legislation-monitor/blob/main/app/services/source_service.py"
click node_repositories "https://github.com/reeperetter/legislation-monitor/blob/main/app/repositories/document_repository.py"
click node_models "https://github.com/reeperetter/legislation-monitor/blob/main/app/models/document.py"
click node_db_setup "https://github.com/reeperetter/legislation-monitor/blob/main/app/db/session.py"
click node_parser_removal "https://github.com/reeperetter/legislation-monitor/blob/main/README.md"

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_app,node_api,node_dashboard toneBlue
class node_monitor_service,node_monitor,node_parser_manager toneAmber
class node_parser_base,node_source_adapters,node_publisher_parsers,node_providers,node_external_sources,node_http_client,node_parser_removal toneMint
class node_document_service,node_source_service,node_repositories,node_models,node_database,node_db_setup toneRose
```

## Components

### HTTP & Dashboard

- [Application Assembly](https://github.com/reeperetter/legislation-monitor/blob/main/app/main.py): FastAPI entrypoint · Registers routes, templates, and static assets. · `app/main.py`
- **API Routes**: route modules · Document, source, parser, and monitor endpoints delegate to services.
- **Dashboard Views**: server-rendered templates · Operational pages for dashboard, documents, and sources.

### Monitoring

- [Monitoring Service](https://github.com/reeperetter/legislation-monitor/blob/main/app/services/monitoring_service.py): application service · Runs monitoring workflows requested through the API. · `app/services/monitoring_service.py`
- [Monitor](https://github.com/reeperetter/legislation-monitor/blob/main/app/monitoring/monitor.py): control-plane workflow · Initiates source checks and reports monitor state. · `app/monitoring/monitor.py`
- [Parser Manager](https://github.com/reeperetter/legislation-monitor/blob/main/app/monitoring/parser_manager.py): execution coordinator · Separates parser scheduling and execution from HTTP handling. · `app/monitoring/parser_manager.py`

### Acquisition & Parsing

- [Parser Abstraction](https://github.com/reeperetter/legislation-monitor/blob/main/app/parsers/base.py): parser interface · `app/parsers/base.py`
- [Publisher Source Adapters](https://github.com/reeperetter/legislation-monitor/blob/main/app/parsers/sources/diam.py): source acquisition · Publisher-specific acquisition for DIAM, KMU, and Rada. · `app/parsers/sources/diam.py`
- [Publisher Parsers](https://github.com/reeperetter/legislation-monitor/blob/main/app/parsers/diam.py): normalization pipeline · DIAM, KMU, and Rada parsers convert acquired items to normalized documents. · `app/parsers/diam.py`
- [Provider Integrations](https://github.com/reeperetter/legislation-monitor/blob/main/app/providers/diam.py): source integration · Source/provider boundary for DIAM, KMU, and Rada behavior. · `app/providers/diam.py`
- **Government & News Sources**: external HTTP systems
- [HTTP Client](https://github.com/reeperetter/legislation-monitor/blob/main/app/core/http_client.py): outbound I/O · Centralizes outbound HTTP behavior. · `app/core/http_client.py`
- [Planned Parser Removal](https://github.com/reeperetter/legislation-monitor/blob/main/README.md): planned change · README calls for removing parsers despite current monitoring dependency. · `README.md`

### Domain & Persistence

- [Document Service](https://github.com/reeperetter/legislation-monitor/blob/main/app/services/document_service.py): application service · Owns document normalization and retrieval workflows. · `app/services/document_service.py`
- [Source Service](https://github.com/reeperetter/legislation-monitor/blob/main/app/services/source_service.py): application service · Owns source configuration workflows. · `app/services/source_service.py`
- [Document & Source Repositories](https://github.com/reeperetter/legislation-monitor/blob/main/app/repositories/document_repository.py): data access layer · Isolates database reads and writes. · `app/repositories/document_repository.py`
- [Domain Models](https://github.com/reeperetter/legislation-monitor/blob/main/app/models/document.py): ORM entities · Documents, sources, categories, keywords, users, and roles. · `app/models/document.py`
- **Relational Database**: persistence · Configured database holding normalized domain records.
- [Database Setup & Migrations](https://github.com/reeperetter/legislation-monitor/blob/main/app/db/session.py): schema management · Session/base initialization and Alembic schema history. · `app/db/session.py`

## Connections

- Application Assembly → API Routes: registers
- Application Assembly → Dashboard Views: serves
- API Routes → Monitoring Service: monitor requests
- API Routes → Document Service: document requests
- API Routes → Source Service: source requests
- Monitoring Service → Monitor: runs
- Monitor → Parser Manager: coordinates
- Parser Manager → Parser Abstraction: executes
- Parser Abstraction → Publisher Parsers: implemented by
- Publisher Parsers → Publisher Source Adapters: acquires through
- Publisher Source Adapters → Provider Integrations: integrates via
- Provider Integrations → HTTP Client: uses
- HTTP Client → Government & News Sources: HTTP access
- Publisher Parsers → Document Service: normalized documents
- Source Service → Document & Source Repositories: persists sources
- Document Service → Document & Source Repositories: persists and retrieves
- Document & Source Repositories → Domain Models: maps
- Document & Source Repositories → Relational Database: reads and writes
- Database Setup & Migrations → Relational Database: initializes and migrates
- Dashboard Views → Document Service: document views
- Dashboard Views → Source Service: source views
- Planned Parser Removal → Parser Abstraction: planned removal affects
