How reeperetter/legislation-monitor works
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: document_repository.py Document & Source Repositories · document_service.py Document Service · diam.py Publisher Parsers · base.py Parser Abstraction
Components 19
HTTP & Dashboard
- Application Assembly · Registers routes, templates, and static assets.
app/main.py - API Routes · Document, source, parser, and monitor endpoints delegate to services.
- Dashboard Views · Operational pages for dashboard, documents, and sources.
Monitoring
- Monitoring Service · Runs monitoring workflows requested through the API.
app/services/monitoring_service.py - Monitor · Initiates source checks and reports monitor state.
app/monitoring/monitor.py - Parser Manager · Separates parser scheduling and execution from HTTP handling.
app/monitoring/parser_manager.py
Acquisition & Parsing
- Parser Abstraction
app/parsers/base.py - Publisher Source Adapters · Publisher-specific acquisition for DIAM, KMU, and Rada.
app/parsers/sources/diam.py - Publisher Parsers · DIAM, KMU, and Rada parsers convert acquired items to normalized documents.
app/parsers/diam.py - Provider Integrations · Source/provider boundary for DIAM, KMU, and Rada behavior.
app/providers/diam.py - Government & News Sources
- HTTP Client · Centralizes outbound HTTP behavior.
app/core/http_client.py - Planned Parser Removal · README calls for removing parsers despite current monitoring dependency.
README.md
Domain & Persistence
- Document Service · Owns document normalization and retrieval workflows.
app/services/document_service.py - Source Service · Owns source configuration workflows.
app/services/source_service.py - Document & Source Repositories · Isolates database reads and writes.
app/repositories/document_repository.py - Domain Models · Documents, sources, categories, keywords, users, and roles.
app/models/document.py - Relational Database · Configured database holding normalized domain records.
- Database Setup & Migrations · Session/base initialization and Alembic schema history.
app/db/session.py
Connections 22
- 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