# prozorroukr/prozorro-risks architecture

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

- Interactive diagram: https://gitdiagram.com/prozorroukr/prozorro-risks
- Repository: https://github.com/prozorroukr/prozorro-risks
- Video tour (about a minute): https://gitdiagram.com/prozorroukr/prozorro-risks/video

## Overview

Prozorro Risks detects procurement risks in tender and contract records, stores assessment history, and exposes results through an API and browser report. The main workflow is a crawler fetching records from the public procurement API, dispatching eligible records to matching risk rules, then persisting assessments. Rules can also consult stored historical tenders. The README describes rule metadata and result states; sampled code supports the tender and contract crawler flows and the report endpoints. Other crawler details and API routing are inferred only from the tree, so uncertain wiring is omitted.

Main entry points: [`src/prozorro/risks/crawlers/tenders_crawler.py`](https://github.com/prozorroukr/prozorro-risks/blob/master/src/prozorro/risks/crawlers/tenders_crawler.py) (Tender crawler), [`src/prozorro/risks/crawlers/contracts_crawler.py`](https://github.com/prozorroukr/prozorro-risks/blob/master/src/prozorro/risks/crawlers/contracts_crawler.py) (Contract crawler), [`src/prozorro/risks/rules`](https://github.com/prozorroukr/prozorro-risks/tree/master/src/prozorro/risks/rules) (Risk rules), [`src/prozorro/risks/handlers.py`](https://github.com/prozorroukr/prozorro-risks/blob/master/src/prozorro/risks/handlers.py) (API handlers)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_ingestion["Crawling"]
  node_tender_crawler["Tender crawler<br/>[tenders_crawler.py]"]
  node_contract_crawler["Contract crawler"]
  node_delay_crawler["Delay crawler<br/>[delay_crawler.py]"]
  node_requests["Object requests<br/>[requests.py]"]
end

subgraph group_assessment["Risk assessment"]
  node_dispatcher["Crawler dispatcher<br/>[base.py]"]
  node_risk_rules["Risk rules"]
  node_rule_base["Rule foundations<br/>[base.py]"]
  node_historical["Historical queries<br/>[historical_data.py]"]
  node_risk_utils["Risk utilities<br/>[utils.py]"]
end

subgraph group_storage["Persistence"]
  node_database[("MongoDB records<br/>[db.py]")]
end

subgraph group_access["Reporting"]
  node_api["API application<br/>[api.py]"]
  node_handlers["API handlers<br/>[handlers.py]"]
  node_frontend["Risk report UI<br/>[main.js]"]
end

node_procurement_source(("Procurement API"))
node_browser(("Report user"))

node_procurement_source -->|"supplies feed items"| node_tender_crawler
node_procurement_source -->|"supplies feed items"| node_contract_crawler
node_tender_crawler -->|"fetches tenders"| node_requests
node_contract_crawler -->|"fetches contracts"| node_requests
node_requests -->|"requests records"| node_procurement_source
node_tender_crawler -->|"dispatches tender"| node_dispatcher
node_contract_crawler -->|"dispatches contract"| node_dispatcher
node_dispatcher -->|"invokes rules"| node_risk_rules
node_risk_rules -->|"inherits behavior"| node_rule_base
node_risk_rules -->|"queries history"| node_historical
node_historical -->|"aggregates tenders"| node_database
node_tender_crawler -->|"uses helpers"| node_risk_utils
node_contract_crawler -->|"loads parent tender"| node_risk_utils
node_tender_crawler -->|"saves assessment"| node_database
node_contract_crawler -->|"saves assessment"| node_database
node_api -->|"routes requests"| node_handlers
node_handlers -->|"reads reports"| node_database
node_handlers -->|"lists rule metadata"| node_risk_rules
node_browser -->|"uses report"| node_frontend
node_frontend -->|"fetches report data"| node_handlers

click node_tender_crawler "https://github.com/prozorroukr/prozorro-risks/blob/master/src/prozorro/risks/crawlers/tenders_crawler.py"
click node_contract_crawler "https://github.com/prozorroukr/prozorro-risks/blob/master/src/prozorro/risks/crawlers/contracts_crawler.py"
click node_delay_crawler "https://github.com/prozorroukr/prozorro-risks/blob/master/src/prozorro/risks/crawlers/delay_crawler.py"
click node_requests "https://github.com/prozorroukr/prozorro-risks/blob/master/src/prozorro/risks/requests.py"
click node_dispatcher "https://github.com/prozorroukr/prozorro-risks/blob/master/src/prozorro/risks/crawlers/base.py"
click node_risk_rules "https://github.com/prozorroukr/prozorro-risks/tree/master/src/prozorro/risks/rules"
click node_rule_base "https://github.com/prozorroukr/prozorro-risks/blob/master/src/prozorro/risks/rules/base.py"
click node_historical "https://github.com/prozorroukr/prozorro-risks/blob/master/src/prozorro/risks/historical_data.py"
click node_risk_utils "https://github.com/prozorroukr/prozorro-risks/blob/master/src/prozorro/risks/utils.py"
click node_database "https://github.com/prozorroukr/prozorro-risks/blob/master/src/prozorro/risks/db.py"
click node_api "https://github.com/prozorroukr/prozorro-risks/blob/master/src/prozorro/risks/api.py"
click node_handlers "https://github.com/prozorroukr/prozorro-risks/blob/master/src/prozorro/risks/handlers.py"
click node_frontend "https://github.com/prozorroukr/prozorro-risks/blob/master/frontend/src/js/main.js"

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_tender_crawler,node_contract_crawler,node_delay_crawler,node_requests,node_browser toneBlue
class node_dispatcher,node_risk_rules,node_rule_base,node_historical,node_risk_utils toneAmber
class node_database,node_procurement_source toneMint
class node_api,node_handlers,node_frontend toneRose
```

## Components

### Crawling

- [Tender crawler](https://github.com/prozorroukr/prozorro-risks/blob/master/src/prozorro/risks/crawlers/tenders_crawler.py): `src/prozorro/risks/crawlers/tenders_crawler.py`
- [Contract crawler](https://github.com/prozorroukr/prozorro-risks/blob/master/src/prozorro/risks/crawlers/contracts_crawler.py): `src/prozorro/risks/crawlers/contracts_crawler.py`
- [Delay crawler](https://github.com/prozorroukr/prozorro-risks/blob/master/src/prozorro/risks/crawlers/delay_crawler.py): `src/prozorro/risks/crawlers/delay_crawler.py`
- [Object requests](https://github.com/prozorroukr/prozorro-risks/blob/master/src/prozorro/risks/requests.py): `src/prozorro/risks/requests.py`

### Risk assessment

- [Crawler dispatcher](https://github.com/prozorroukr/prozorro-risks/blob/master/src/prozorro/risks/crawlers/base.py): `src/prozorro/risks/crawlers/base.py`
- [Risk rules](https://github.com/prozorroukr/prozorro-risks/tree/master/src/prozorro/risks/rules): `src/prozorro/risks/rules`
- [Rule foundations](https://github.com/prozorroukr/prozorro-risks/blob/master/src/prozorro/risks/rules/base.py): `src/prozorro/risks/rules/base.py`
- [Historical queries](https://github.com/prozorroukr/prozorro-risks/blob/master/src/prozorro/risks/historical_data.py): `src/prozorro/risks/historical_data.py`
- [Risk utilities](https://github.com/prozorroukr/prozorro-risks/blob/master/src/prozorro/risks/utils.py): `src/prozorro/risks/utils.py`

### Persistence

- [MongoDB records](https://github.com/prozorroukr/prozorro-risks/blob/master/src/prozorro/risks/db.py): `src/prozorro/risks/db.py`

### Reporting

- [API application](https://github.com/prozorroukr/prozorro-risks/blob/master/src/prozorro/risks/api.py): `src/prozorro/risks/api.py`
- [API handlers](https://github.com/prozorroukr/prozorro-risks/blob/master/src/prozorro/risks/handlers.py): `src/prozorro/risks/handlers.py`
- [Risk report UI](https://github.com/prozorroukr/prozorro-risks/blob/master/frontend/src/js/main.js): `frontend/src/js/main.js`

### Other components

- **Procurement API**
- **Report user**

## Connections

- Procurement API → Tender crawler: supplies feed items
- Procurement API → Contract crawler: supplies feed items
- Tender crawler → Object requests: fetches tenders
- Contract crawler → Object requests: fetches contracts
- Object requests → Procurement API: requests records
- Tender crawler → Crawler dispatcher: dispatches tender
- Contract crawler → Crawler dispatcher: dispatches contract
- Crawler dispatcher → Risk rules: invokes rules
- Risk rules → Rule foundations: inherits behavior
- Risk rules → Historical queries: queries history
- Historical queries → MongoDB records: aggregates tenders
- Tender crawler → Risk utilities: uses helpers
- Contract crawler → Risk utilities: loads parent tender
- Tender crawler → MongoDB records: saves assessment
- Contract crawler → MongoDB records: saves assessment
- API application → API handlers: routes requests
- API handlers → MongoDB records: reads reports
- API handlers → Risk rules: lists rule metadata
- Report user → Risk report UI: uses report
- Risk report UI → API handlers: fetches report data
