# mtperaya/torbidd architecture

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

- Interactive diagram: https://gitdiagram.com/mtperaya/torbidd
- Repository: https://github.com/mtperaya/torbidd

## Overview

TORBIDD is a Thai government software-procurement intelligence platform. Vendors browse and filter opportunities, inspect tender details and qualifications, compare historical prices, and receive targeted alerts; ingestion gathers public procurement records and TOR documents for analysis. The graph also preserves authentication, settings, bookmarks, and administration as product capabilities. Source excerpts verify the ingestion orchestrator’s client, extraction, and persistence calls, and several API-to-service calls; other feature wiring is documented at capability level only, so unsampled connections are omitted.

Main entry points: [`torbidd-app/src/services/database`](https://github.com/mtperaya/torbidd/tree/main/torbidd-app/src/services/database) (Database Services), [`torbidd-app/src/services/ingestion/ingestion.service.ts`](https://github.com/mtperaya/torbidd/blob/main/torbidd-app/src/services/ingestion/ingestion.service.ts) (Ingestion Service), [`torbidd-app/src/app/api/projects/route.ts`](https://github.com/mtperaya/torbidd/blob/main/torbidd-app/src/app/api/projects/route.ts) (Project API), [`torbidd-app/src/app/api/historical/route.ts`](https://github.com/mtperaya/torbidd/blob/main/torbidd-app/src/app/api/historical/route.ts) (Historical API)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_discovery["Opportunity Discovery"]
  node_opportunities_ui["Opportunity Browser<br/>[page.tsx]"]
  node_project_api["Project API<br/>[route.ts]"]
  node_procurement_api["Procurement API<br/>[route.ts]"]
  node_search["Procurement Search"]
  node_details_ui["Opportunity Details<br/>[page.tsx]"]
  node_detail_api["Project Detail API<br/>[route.ts]"]
end

subgraph group_ingestion["Data Ingestion"]
  node_ingestion_api["Ingestion Routes"]
  node_ingestion_service["Ingestion Service"]
  node_egp_client["e-GP Client<br/>[egp-client.ts]"]
  node_gov_client["Gov Data Client"]
  node_document_extractor["TOR Document Extractor"]
  node_public_sources["Government Data Sources"]
end

subgraph group_analysis["AI &amp; Analytics"]
  node_ai_analysis["AI Classification &amp; Qualification"]
  node_historical_ui["Historical Analytics<br/>[page.tsx]"]
  node_historical_api["Historical API<br/>[route.ts]"]
  node_historical_metrics["Historical Metrics"]
end

subgraph group_engagement["User &amp; Alerts"]
  node_auth["Authentication"]
  node_bookmarks["Saved Opportunities<br/>[route.ts]"]
  node_notifications["Notifications &amp; Alerts"]
  node_settings["User Settings<br/>[route.ts]"]
end

subgraph group_platform["Application Data"]
  node_admin["Administration<br/>[page.tsx]"]
  node_database_services["Database Services"]
  node_models[("Domain Models")]
  node_initial_data["Offline Sample Data<br/>[initialData.ts]"]
end

node_vendor(("Technology Vendor"))

node_vendor -->|"browses"| node_opportunities_ui
node_opportunities_ui -.->|"requests projects"| node_project_api
node_project_api -->|"loads projects"| node_database_services
node_project_api -->|"filters fallback data"| node_search
node_procurement_api -->|"searches fallback data"| node_search
node_vendor -->|"inspects tenders"| node_details_ui
node_details_ui -.->|"requests details"| node_detail_api
node_detail_api -->|"loads project data"| node_database_services
node_vendor -->|"compares benchmarks"| node_historical_ui
node_historical_ui -.->|"requests history"| node_historical_api
node_historical_api -->|"loads records"| node_database_services
node_historical_api -->|"calculates metrics"| node_historical_metrics
node_ingestion_api -.->|"dispatches ingestion"| node_ingestion_service
node_ingestion_service -->|"fetches archive data"| node_egp_client
node_ingestion_service -->|"searches tenders"| node_gov_client
node_ingestion_service -->|"extracts documents"| node_document_extractor
node_ingestion_service -->|"persists records"| node_database_services
node_egp_client -.->|"queries e-GP"| node_public_sources
node_gov_client -.->|"queries open data"| node_public_sources
node_vendor -->|"evaluates qualifications"| node_ai_analysis
node_vendor -.->|"signs in"| node_auth
node_vendor -.->|"saves opportunities"| node_bookmarks
node_vendor -->|"receives tender alerts"| node_notifications
node_notifications -->|"reads notification data"| node_database_services
node_vendor -.->|"updates preferences"| node_settings
node_settings -->|"reads and writes settings"| node_database_services
node_database_services -.->|"uses schemas"| node_models
node_project_api -->|"uses offline fallback"| node_initial_data
node_historical_api -->|"uses offline fallback"| node_initial_data
node_admin -.->|"manages synchronization"| node_ingestion_api

click node_opportunities_ui "https://github.com/mtperaya/torbidd/blob/main/torbidd-app/src/app/opportunities/page.tsx"
click node_project_api "https://github.com/mtperaya/torbidd/blob/main/torbidd-app/src/app/api/projects/route.ts"
click node_procurement_api "https://github.com/mtperaya/torbidd/blob/main/torbidd-app/src/app/api/procurements/route.ts"
click node_search "https://github.com/mtperaya/torbidd/blob/main/torbidd-app/src/services/procurement-search.ts"
click node_details_ui "https://github.com/mtperaya/torbidd/blob/main/torbidd-app/src/app/opportunities/%5Bid%5D/page.tsx"
click node_detail_api "https://github.com/mtperaya/torbidd/blob/main/torbidd-app/src/app/api/projects/%5Bid%5D/route.ts"
click node_ingestion_api "https://github.com/mtperaya/torbidd/tree/main/torbidd-app/src/app/api/ingestion"
click node_ingestion_service "https://github.com/mtperaya/torbidd/blob/main/torbidd-app/src/services/ingestion/ingestion.service.ts"
click node_egp_client "https://github.com/mtperaya/torbidd/blob/main/torbidd-app/src/services/ingestion/clients/egp-client.ts"
click node_gov_client "https://github.com/mtperaya/torbidd/blob/main/torbidd-app/src/services/ingestion/clients/govspending-client.ts"
click node_document_extractor "https://github.com/mtperaya/torbidd/blob/main/torbidd-app/src/services/ingestion/document-extractor.ts"
click node_ai_analysis "https://github.com/mtperaya/torbidd/tree/main/torbidd-app/src/services/ai"
click node_historical_ui "https://github.com/mtperaya/torbidd/blob/main/torbidd-app/src/app/historical/page.tsx"
click node_historical_api "https://github.com/mtperaya/torbidd/blob/main/torbidd-app/src/app/api/historical/route.ts"
click node_historical_metrics "https://github.com/mtperaya/torbidd/blob/main/torbidd-app/src/lib/historicalAnalytics.ts"
click node_auth "https://github.com/mtperaya/torbidd/tree/main/torbidd-app/src/app/api/auth"
click node_bookmarks "https://github.com/mtperaya/torbidd/blob/main/torbidd-app/src/app/api/bookmarks/route.ts"
click node_notifications "https://github.com/mtperaya/torbidd/tree/main/torbidd-app/src/app/api/notifications"
click node_settings "https://github.com/mtperaya/torbidd/blob/main/torbidd-app/src/app/api/settings/route.ts"
click node_admin "https://github.com/mtperaya/torbidd/blob/main/torbidd-app/src/app/admin/page.tsx"
click node_database_services "https://github.com/mtperaya/torbidd/tree/main/torbidd-app/src/services/database"
click node_models "https://github.com/mtperaya/torbidd/tree/main/torbidd-app/src/models"
click node_initial_data "https://github.com/mtperaya/torbidd/blob/main/torbidd-app/src/lib/initialData.ts"

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_opportunities_ui,node_project_api,node_procurement_api,node_search,node_details_ui,node_detail_api toneBlue
class node_ingestion_api,node_ingestion_service,node_egp_client,node_gov_client,node_document_extractor,node_public_sources toneAmber
class node_ai_analysis,node_historical_ui,node_historical_api,node_historical_metrics toneMint
class node_auth,node_bookmarks,node_notifications,node_settings toneRose
class node_admin,node_database_services,node_models,node_initial_data,node_vendor toneIndigo
```

## Components

### Opportunity Discovery

- [Opportunity Browser](https://github.com/mtperaya/torbidd/blob/main/torbidd-app/src/app/opportunities/page.tsx): `torbidd-app/src/app/opportunities/page.tsx`
- [Project API](https://github.com/mtperaya/torbidd/blob/main/torbidd-app/src/app/api/projects/route.ts): `torbidd-app/src/app/api/projects/route.ts`
- [Procurement API](https://github.com/mtperaya/torbidd/blob/main/torbidd-app/src/app/api/procurements/route.ts): `torbidd-app/src/app/api/procurements/route.ts`
- [Procurement Search](https://github.com/mtperaya/torbidd/blob/main/torbidd-app/src/services/procurement-search.ts): `torbidd-app/src/services/procurement-search.ts`
- [Opportunity Details](https://github.com/mtperaya/torbidd/blob/main/torbidd-app/src/app/opportunities/%5Bid%5D/page.tsx): `torbidd-app/src/app/opportunities/[id]/page.tsx`
- [Project Detail API](https://github.com/mtperaya/torbidd/blob/main/torbidd-app/src/app/api/projects/%5Bid%5D/route.ts): `torbidd-app/src/app/api/projects/[id]/route.ts`

### Data Ingestion

- [Ingestion Routes](https://github.com/mtperaya/torbidd/tree/main/torbidd-app/src/app/api/ingestion): `torbidd-app/src/app/api/ingestion`
- [Ingestion Service](https://github.com/mtperaya/torbidd/blob/main/torbidd-app/src/services/ingestion/ingestion.service.ts): `torbidd-app/src/services/ingestion/ingestion.service.ts`
- [e-GP Client](https://github.com/mtperaya/torbidd/blob/main/torbidd-app/src/services/ingestion/clients/egp-client.ts): `torbidd-app/src/services/ingestion/clients/egp-client.ts`
- [Gov Data Client](https://github.com/mtperaya/torbidd/blob/main/torbidd-app/src/services/ingestion/clients/govspending-client.ts): `torbidd-app/src/services/ingestion/clients/govspending-client.ts`
- [TOR Document Extractor](https://github.com/mtperaya/torbidd/blob/main/torbidd-app/src/services/ingestion/document-extractor.ts): `torbidd-app/src/services/ingestion/document-extractor.ts`
- **Government Data Sources**

### AI & Analytics

- [AI Classification & Qualification](https://github.com/mtperaya/torbidd/tree/main/torbidd-app/src/services/ai): `torbidd-app/src/services/ai`
- [Historical Analytics](https://github.com/mtperaya/torbidd/blob/main/torbidd-app/src/app/historical/page.tsx): `torbidd-app/src/app/historical/page.tsx`
- [Historical API](https://github.com/mtperaya/torbidd/blob/main/torbidd-app/src/app/api/historical/route.ts): `torbidd-app/src/app/api/historical/route.ts`
- [Historical Metrics](https://github.com/mtperaya/torbidd/blob/main/torbidd-app/src/lib/historicalAnalytics.ts): `torbidd-app/src/lib/historicalAnalytics.ts`

### User & Alerts

- [Authentication](https://github.com/mtperaya/torbidd/tree/main/torbidd-app/src/app/api/auth): `torbidd-app/src/app/api/auth`
- [Saved Opportunities](https://github.com/mtperaya/torbidd/blob/main/torbidd-app/src/app/api/bookmarks/route.ts): `torbidd-app/src/app/api/bookmarks/route.ts`
- [Notifications & Alerts](https://github.com/mtperaya/torbidd/tree/main/torbidd-app/src/app/api/notifications): `torbidd-app/src/app/api/notifications`
- [User Settings](https://github.com/mtperaya/torbidd/blob/main/torbidd-app/src/app/api/settings/route.ts): `torbidd-app/src/app/api/settings/route.ts`

### Application Data

- [Administration](https://github.com/mtperaya/torbidd/blob/main/torbidd-app/src/app/admin/page.tsx): `torbidd-app/src/app/admin/page.tsx`
- [Database Services](https://github.com/mtperaya/torbidd/tree/main/torbidd-app/src/services/database): `torbidd-app/src/services/database`
- [Domain Models](https://github.com/mtperaya/torbidd/tree/main/torbidd-app/src/models): `torbidd-app/src/models`
- [Offline Sample Data](https://github.com/mtperaya/torbidd/blob/main/torbidd-app/src/lib/initialData.ts): `torbidd-app/src/lib/initialData.ts`

### Other components

- **Technology Vendor**

## Connections

- Technology Vendor → Opportunity Browser: browses (evidence: `README.md`)
- Opportunity Browser → Project API: requests projects
- Project API → Database Services: loads projects (evidence: `torbidd-app/src/app/api/projects/route.ts`)
- Project API → Procurement Search: filters fallback data (evidence: `torbidd-app/src/app/api/projects/route.ts`)
- Procurement API → Procurement Search: searches fallback data (evidence: `torbidd-app/src/app/api/procurements/route.ts`)
- Technology Vendor → Opportunity Details: inspects tenders (evidence: `README.md`)
- Opportunity Details → Project Detail API: requests details
- Project Detail API → Database Services: loads project data (evidence: `torbidd-app/src/app/api/projects/[id]/route.ts`)
- Technology Vendor → Historical Analytics: compares benchmarks (evidence: `README.md`)
- Historical Analytics → Historical API: requests history
- Historical API → Database Services: loads records (evidence: `torbidd-app/src/app/api/historical/route.ts`)
- Historical API → Historical Metrics: calculates metrics (evidence: `torbidd-app/src/app/api/historical/route.ts`)
- Ingestion Routes → Ingestion Service: dispatches ingestion
- Ingestion Service → e-GP Client: fetches archive data (evidence: `torbidd-app/src/services/ingestion/ingestion.service.ts`)
- Ingestion Service → Gov Data Client: searches tenders (evidence: `torbidd-app/src/services/ingestion/ingestion.service.ts`)
- Ingestion Service → TOR Document Extractor: extracts documents (evidence: `torbidd-app/src/services/ingestion/ingestion.service.ts`)
- Ingestion Service → Database Services: persists records (evidence: `torbidd-app/src/services/ingestion/ingestion.service.ts`)
- e-GP Client → Government Data Sources: queries e-GP
- Gov Data Client → Government Data Sources: queries open data
- Technology Vendor → AI Classification & Qualification: evaluates qualifications (evidence: `README.md`)
- Technology Vendor → Authentication: signs in
- Technology Vendor → Saved Opportunities: saves opportunities
- Technology Vendor → Notifications & Alerts: receives tender alerts (evidence: `README.md`)
- Notifications & Alerts → Database Services: reads notification data (evidence: `torbidd-app/src/app/api/notifications/route.ts`)
- Technology Vendor → User Settings: updates preferences
- User Settings → Database Services: reads and writes settings (evidence: `torbidd-app/src/app/api/settings/route.ts`)
- Database Services → Domain Models: uses schemas
- Project API → Offline Sample Data: uses offline fallback (evidence: `torbidd-app/src/app/api/projects/route.ts`)
- Historical API → Offline Sample Data: uses offline fallback (evidence: `torbidd-app/src/app/api/historical/route.ts`)
- Administration → Ingestion Routes: manages synchronization
