# ronan-r-r/group2-public-tender-irregularity-detector architecture

> Architecture diagram of the GitHub repository ronan-r-r/group2-public-tender-irregularity-detector, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-27). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/ronan-r-r/group2-public-tender-irregularity-detector
- Repository: https://github.com/ronan-r-r/group2-public-tender-irregularity-detector

## Overview

This is a civic-tech tender-risk monitor: award data is ingested, enriched with company/director information, evaluated by red-flag rules and pricing anomaly analysis, then published as transparent scores and rule evidence for a static dashboard. The README and build script establish the batch pipeline; sampled frontend code shows routing, data loading and presentation. The API and database internals were not sampled, so their documented roles are shown without inferred implementation details.

Main entry points: [`scripts/build_dashboard_data.py`](https://github.com/ronan-r-r/group2-public-tender-irregularity-detector/blob/main/scripts/build_dashboard_data.py) (Scoring job), [`src/frontend/src/App.tsx`](https://github.com/ronan-r-r/group2-public-tender-irregularity-detector/blob/main/src/frontend/src/App.tsx) (Dashboard routes), [`src/frontend/src/pages/TenderDetail.tsx`](https://github.com/ronan-r-r/group2-public-tender-irregularity-detector/blob/main/src/frontend/src/pages/TenderDetail.tsx) (Tender assessment), [`src/frontend/src/data/useIndex.ts`](https://github.com/ronan-r-r/group2-public-tender-irregularity-detector/blob/main/src/frontend/src/data/useIndex.ts) (Index loading)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_ingest["Data ingestion"]
  node_ocds["OCDS ingestion<br/>[ocds.py]"]
  node_registry["Registry loading"]
  node_registry_sample["Sample registry<br/>[sample_registry.py]"]
  node_company_match["Supplier matching"]
  node_name_match["Name matching<br/>[name_match.py]"]
  node_enrichment["Enrichment context"]
end

subgraph group_analysis["Risk analysis"]
  node_models["Domain records<br/>[models.py]"]
  node_context["Award history<br/>[context.py]"]
  node_rules["Twelve red flags"]
  node_engine["Rule evaluation<br/>[engine.py]"]
  node_scorer["Composite score<br/>[scorer.py]"]
  node_anomaly["Price anomaly<br/>[anomaly.py]"]
end

subgraph group_publish["Publishing and storage"]
  node_batch["Scoring job"]
  node_export["Public data export<br/>[export.py]"]
  node_database[("PostgreSQL storage")]
  node_static_json["Published JSON"]
  node_api["Local demo API"]
end

subgraph group_dashboard["Public dashboard"]
  node_app["Dashboard routes<br/>[App.tsx]"]
  node_router["Route handling<br/>[router.tsx]"]
  node_index_hook["Index loading<br/>[useIndex.ts]"]
  node_data_loader["JSON data access<br/>[load.ts]"]
  node_overview["Overview and lists<br/>[Overview.tsx]"]
  node_tender_detail["Tender assessment<br/>[TenderDetail.tsx]"]
  node_buyer_page["Buyer page<br/>[Buyer.tsx]"]
  node_tender_list["Tender list<br/>[Tenders.tsx]"]
  node_aggregate["Dashboard aggregates<br/>[aggregate.ts]"]
  node_explain["Rule explanations<br/>[explain.ts]"]
  node_price_chart["Price comparison<br/>[PriceChart.tsx]"]
  node_anomaly_panel["Anomaly details<br/>[AnomalyPanel.tsx]"]
  node_score_ring["Score display<br/>[ScoreRing.tsx]"]
  node_legal["Legal information<br/>[Legal.tsx]"]
end

node_treasury(("eTenders awards"))
node_cipc[("CIPC registry")]
node_dashboard_user(("Auditor or public"))

node_treasury -->|"supplies awards"| node_ocds
node_cipc -->|"supplies records"| node_registry
node_ocds -->|"provides tender data"| node_batch
node_registry_sample -->|"provides registry data"| node_batch
node_company_match -->|"uses matching"| node_name_match
node_batch -->|"resolves suppliers"| node_company_match
node_batch -->|"builds records"| node_models
node_batch -->|"loads award history"| node_context
node_batch -->|"evaluates awards"| node_engine
node_engine -->|"dispatches rules"| node_rules
node_rules -.->|"queries history"| node_context
node_engine -->|"scores results"| node_scorer
node_batch -->|"computes pricing signal"| node_anomaly
node_batch -->|"exports results"| node_export
node_batch -->|"writes scores"| node_database
node_export -->|"publishes JSON"| node_static_json
node_dashboard_user -->|"opens dashboard"| node_app
node_app -->|"reads route"| node_router
node_app -->|"renders overview"| node_overview
node_app -->|"renders list"| node_tender_list
node_app -->|"renders assessment"| node_tender_detail
node_app -->|"renders buyer"| node_buyer_page
node_app -->|"renders legal pages"| node_legal
node_index_hook -->|"loads index"| node_data_loader
node_overview -->|"reads index"| node_index_hook
node_tender_list -->|"reads index"| node_index_hook
node_buyer_page -->|"reads index"| node_index_hook
node_overview -->|"summarizes awards"| node_aggregate
node_tender_list -->|"filters awards"| node_aggregate
node_buyer_page -->|"summarizes buyer"| node_aggregate
node_tender_detail -->|"loads detail"| node_data_loader
node_tender_detail -->|"explains rules"| node_explain
node_tender_detail -->|"displays score"| node_score_ring
node_tender_detail -->|"shows comparison"| node_price_chart
node_tender_detail -->|"shows anomaly"| node_anomaly_panel
node_static_json -->|"serves dashboard data"| node_data_loader

click node_ocds "https://github.com/ronan-r-r/group2-public-tender-irregularity-detector/blob/main/src/ingestion/ocds.py"
click node_registry "https://github.com/ronan-r-r/group2-public-tender-irregularity-detector/blob/main/src/ingestion/cipc_registry_loader.py"
click node_registry_sample "https://github.com/ronan-r-r/group2-public-tender-irregularity-detector/blob/main/src/ingestion/sample_registry.py"
click node_company_match "https://github.com/ronan-r-r/group2-public-tender-irregularity-detector/blob/main/src/ingestion/supplier_company_matcher.py"
click node_name_match "https://github.com/ronan-r-r/group2-public-tender-irregularity-detector/blob/main/src/ingestion/name_match.py"
click node_enrichment "https://github.com/ronan-r-r/group2-public-tender-irregularity-detector/blob/main/src/ingestion/enrichment_context.py"
click node_batch "https://github.com/ronan-r-r/group2-public-tender-irregularity-detector/blob/main/scripts/build_dashboard_data.py"
click node_models "https://github.com/ronan-r-r/group2-public-tender-irregularity-detector/blob/main/src/detection/models.py"
click node_context "https://github.com/ronan-r-r/group2-public-tender-irregularity-detector/blob/main/src/detection/context.py"
click node_rules "https://github.com/ronan-r-r/group2-public-tender-irregularity-detector/tree/main/src/detection/rules"
click node_engine "https://github.com/ronan-r-r/group2-public-tender-irregularity-detector/blob/main/src/detection/engine.py"
click node_scorer "https://github.com/ronan-r-r/group2-public-tender-irregularity-detector/blob/main/src/detection/scorer.py"
click node_anomaly "https://github.com/ronan-r-r/group2-public-tender-irregularity-detector/blob/main/src/detection/anomaly.py"
click node_export "https://github.com/ronan-r-r/group2-public-tender-irregularity-detector/blob/main/src/detection/export.py"
click node_database "https://github.com/ronan-r-r/group2-public-tender-irregularity-detector/tree/main/src/db"
click node_app "https://github.com/ronan-r-r/group2-public-tender-irregularity-detector/blob/main/src/frontend/src/App.tsx"
click node_router "https://github.com/ronan-r-r/group2-public-tender-irregularity-detector/blob/main/src/frontend/src/router.tsx"
click node_index_hook "https://github.com/ronan-r-r/group2-public-tender-irregularity-detector/blob/main/src/frontend/src/data/useIndex.ts"
click node_data_loader "https://github.com/ronan-r-r/group2-public-tender-irregularity-detector/blob/main/src/frontend/src/data/load.ts"
click node_overview "https://github.com/ronan-r-r/group2-public-tender-irregularity-detector/blob/main/src/frontend/src/pages/Overview.tsx"
click node_tender_detail "https://github.com/ronan-r-r/group2-public-tender-irregularity-detector/blob/main/src/frontend/src/pages/TenderDetail.tsx"
click node_buyer_page "https://github.com/ronan-r-r/group2-public-tender-irregularity-detector/blob/main/src/frontend/src/pages/Buyer.tsx"
click node_tender_list "https://github.com/ronan-r-r/group2-public-tender-irregularity-detector/blob/main/src/frontend/src/pages/Tenders.tsx"
click node_aggregate "https://github.com/ronan-r-r/group2-public-tender-irregularity-detector/blob/main/src/frontend/src/lib/aggregate.ts"
click node_explain "https://github.com/ronan-r-r/group2-public-tender-irregularity-detector/blob/main/src/frontend/src/lib/explain.ts"
click node_price_chart "https://github.com/ronan-r-r/group2-public-tender-irregularity-detector/blob/main/src/frontend/src/components/PriceChart.tsx"
click node_anomaly_panel "https://github.com/ronan-r-r/group2-public-tender-irregularity-detector/blob/main/src/frontend/src/components/AnomalyPanel.tsx"
click node_score_ring "https://github.com/ronan-r-r/group2-public-tender-irregularity-detector/blob/main/src/frontend/src/components/ScoreRing.tsx"
click node_legal "https://github.com/ronan-r-r/group2-public-tender-irregularity-detector/blob/main/src/frontend/src/pages/Legal.tsx"
click node_api "https://github.com/ronan-r-r/group2-public-tender-irregularity-detector/tree/main/src/api"

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_ocds,node_registry,node_registry_sample,node_company_match,node_name_match,node_enrichment toneBlue
class node_models,node_context,node_rules,node_engine,node_scorer,node_anomaly,node_cipc toneAmber
class node_batch,node_export,node_database,node_static_json,node_api toneMint
class node_app,node_router,node_index_hook,node_data_loader,node_overview,node_tender_detail,node_buyer_page,node_tender_list,node_aggregate,node_explain,node_price_chart,node_anomaly_panel,node_score_ring,node_legal toneRose
class node_treasury,node_dashboard_user toneIndigo
```

## Components

### Data ingestion

- [OCDS ingestion](https://github.com/ronan-r-r/group2-public-tender-irregularity-detector/blob/main/src/ingestion/ocds.py): `src/ingestion/ocds.py`
- [Registry loading](https://github.com/ronan-r-r/group2-public-tender-irregularity-detector/blob/main/src/ingestion/cipc_registry_loader.py): `src/ingestion/cipc_registry_loader.py`
- [Sample registry](https://github.com/ronan-r-r/group2-public-tender-irregularity-detector/blob/main/src/ingestion/sample_registry.py): `src/ingestion/sample_registry.py`
- [Supplier matching](https://github.com/ronan-r-r/group2-public-tender-irregularity-detector/blob/main/src/ingestion/supplier_company_matcher.py): `src/ingestion/supplier_company_matcher.py`
- [Name matching](https://github.com/ronan-r-r/group2-public-tender-irregularity-detector/blob/main/src/ingestion/name_match.py): `src/ingestion/name_match.py`
- [Enrichment context](https://github.com/ronan-r-r/group2-public-tender-irregularity-detector/blob/main/src/ingestion/enrichment_context.py): `src/ingestion/enrichment_context.py`

### Risk analysis

- [Domain records](https://github.com/ronan-r-r/group2-public-tender-irregularity-detector/blob/main/src/detection/models.py): `src/detection/models.py`
- [Award history](https://github.com/ronan-r-r/group2-public-tender-irregularity-detector/blob/main/src/detection/context.py): `src/detection/context.py`
- [Twelve red flags](https://github.com/ronan-r-r/group2-public-tender-irregularity-detector/tree/main/src/detection/rules): `src/detection/rules`
- [Rule evaluation](https://github.com/ronan-r-r/group2-public-tender-irregularity-detector/blob/main/src/detection/engine.py): `src/detection/engine.py`
- [Composite score](https://github.com/ronan-r-r/group2-public-tender-irregularity-detector/blob/main/src/detection/scorer.py): `src/detection/scorer.py`
- [Price anomaly](https://github.com/ronan-r-r/group2-public-tender-irregularity-detector/blob/main/src/detection/anomaly.py): `src/detection/anomaly.py`

### Publishing and storage

- [Scoring job](https://github.com/ronan-r-r/group2-public-tender-irregularity-detector/blob/main/scripts/build_dashboard_data.py): `scripts/build_dashboard_data.py`
- [Public data export](https://github.com/ronan-r-r/group2-public-tender-irregularity-detector/blob/main/src/detection/export.py): `src/detection/export.py`
- [PostgreSQL storage](https://github.com/ronan-r-r/group2-public-tender-irregularity-detector/tree/main/src/db): `src/db`
- **Published JSON**
- [Local demo API](https://github.com/ronan-r-r/group2-public-tender-irregularity-detector/tree/main/src/api): `src/api`

### Public dashboard

- [Dashboard routes](https://github.com/ronan-r-r/group2-public-tender-irregularity-detector/blob/main/src/frontend/src/App.tsx): `src/frontend/src/App.tsx`
- [Route handling](https://github.com/ronan-r-r/group2-public-tender-irregularity-detector/blob/main/src/frontend/src/router.tsx): `src/frontend/src/router.tsx`
- [Index loading](https://github.com/ronan-r-r/group2-public-tender-irregularity-detector/blob/main/src/frontend/src/data/useIndex.ts): `src/frontend/src/data/useIndex.ts`
- [JSON data access](https://github.com/ronan-r-r/group2-public-tender-irregularity-detector/blob/main/src/frontend/src/data/load.ts): `src/frontend/src/data/load.ts`
- [Overview and lists](https://github.com/ronan-r-r/group2-public-tender-irregularity-detector/blob/main/src/frontend/src/pages/Overview.tsx): `src/frontend/src/pages/Overview.tsx`
- [Tender assessment](https://github.com/ronan-r-r/group2-public-tender-irregularity-detector/blob/main/src/frontend/src/pages/TenderDetail.tsx): `src/frontend/src/pages/TenderDetail.tsx`
- [Buyer page](https://github.com/ronan-r-r/group2-public-tender-irregularity-detector/blob/main/src/frontend/src/pages/Buyer.tsx): `src/frontend/src/pages/Buyer.tsx`
- [Tender list](https://github.com/ronan-r-r/group2-public-tender-irregularity-detector/blob/main/src/frontend/src/pages/Tenders.tsx): `src/frontend/src/pages/Tenders.tsx`
- [Dashboard aggregates](https://github.com/ronan-r-r/group2-public-tender-irregularity-detector/blob/main/src/frontend/src/lib/aggregate.ts): `src/frontend/src/lib/aggregate.ts`
- [Rule explanations](https://github.com/ronan-r-r/group2-public-tender-irregularity-detector/blob/main/src/frontend/src/lib/explain.ts): `src/frontend/src/lib/explain.ts`
- [Price comparison](https://github.com/ronan-r-r/group2-public-tender-irregularity-detector/blob/main/src/frontend/src/components/PriceChart.tsx): `src/frontend/src/components/PriceChart.tsx`
- [Anomaly details](https://github.com/ronan-r-r/group2-public-tender-irregularity-detector/blob/main/src/frontend/src/components/AnomalyPanel.tsx): `src/frontend/src/components/AnomalyPanel.tsx`
- [Score display](https://github.com/ronan-r-r/group2-public-tender-irregularity-detector/blob/main/src/frontend/src/components/ScoreRing.tsx): `src/frontend/src/components/ScoreRing.tsx`
- [Legal information](https://github.com/ronan-r-r/group2-public-tender-irregularity-detector/blob/main/src/frontend/src/pages/Legal.tsx): `src/frontend/src/pages/Legal.tsx`

### Other components

- **eTenders awards**
- **CIPC registry**
- **Auditor or public**

## Connections

- eTenders awards → OCDS ingestion: supplies awards (evidence: `README.md`)
- CIPC registry → Registry loading: supplies records (evidence: `README.md`)
- OCDS ingestion → Scoring job: provides tender data (evidence: `scripts/build_dashboard_data.py`)
- Sample registry → Scoring job: provides registry data (evidence: `scripts/build_dashboard_data.py`)
- Supplier matching → Name matching: uses matching (evidence: `src/ingestion/supplier_company_matcher.py`)
- Scoring job → Supplier matching: resolves suppliers (evidence: `scripts/build_dashboard_data.py`)
- Scoring job → Domain records: builds records (evidence: `scripts/build_dashboard_data.py`)
- Scoring job → Award history: loads award history (evidence: `scripts/build_dashboard_data.py`)
- Scoring job → Rule evaluation: evaluates awards (evidence: `scripts/build_dashboard_data.py`)
- Rule evaluation → Twelve red flags: dispatches rules (evidence: `src/detection/engine.py`)
- Twelve red flags → Award history: queries history (evidence: `src/detection/rules/r04_director_concentration.py`)
- Rule evaluation → Composite score: scores results (evidence: `src/detection/engine.py`)
- Scoring job → Price anomaly: computes pricing signal (evidence: `scripts/build_dashboard_data.py`)
- Scoring job → Public data export: exports results (evidence: `scripts/build_dashboard_data.py`)
- Scoring job → PostgreSQL storage: writes scores (evidence: `README.md`)
- Public data export → Published JSON: publishes JSON (evidence: `README.md`)
- Auditor or public → Dashboard routes: opens dashboard (evidence: `README.md`)
- Dashboard routes → Route handling: reads route (evidence: `src/frontend/src/App.tsx`)
- Dashboard routes → Overview and lists: renders overview (evidence: `src/frontend/src/App.tsx`)
- Dashboard routes → Tender list: renders list (evidence: `src/frontend/src/App.tsx`)
- Dashboard routes → Tender assessment: renders assessment (evidence: `src/frontend/src/App.tsx`)
- Dashboard routes → Buyer page: renders buyer (evidence: `src/frontend/src/App.tsx`)
- Dashboard routes → Legal information: renders legal pages (evidence: `src/frontend/src/App.tsx`)
- Index loading → JSON data access: loads index (evidence: `src/frontend/src/data/useIndex.ts`)
- Overview and lists → Index loading: reads index (evidence: `src/frontend/src/pages/Overview.tsx`)
- Tender list → Index loading: reads index (evidence: `src/frontend/src/pages/Tenders.tsx`)
- Buyer page → Index loading: reads index (evidence: `src/frontend/src/pages/Buyer.tsx`)
- Overview and lists → Dashboard aggregates: summarizes awards (evidence: `src/frontend/src/pages/Overview.tsx`)
- Tender list → Dashboard aggregates: filters awards (evidence: `src/frontend/src/pages/Tenders.tsx`)
- Buyer page → Dashboard aggregates: summarizes buyer (evidence: `src/frontend/src/pages/Buyer.tsx`)
- Tender assessment → JSON data access: loads detail (evidence: `src/frontend/src/pages/TenderDetail.tsx`)
- Tender assessment → Rule explanations: explains rules (evidence: `src/frontend/src/pages/TenderDetail.tsx`)
- Tender assessment → Score display: displays score (evidence: `src/frontend/src/pages/TenderDetail.tsx`)
- Tender assessment → Price comparison: shows comparison (evidence: `src/frontend/src/pages/TenderDetail.tsx`)
- Tender assessment → Anomaly details: shows anomaly (evidence: `src/frontend/src/pages/TenderDetail.tsx`)
- Published JSON → JSON data access: serves dashboard data (evidence: `README.md`)
