# ajai-k/echallan-scraper-api architecture

> Architecture diagram of the GitHub repository ajai-k/echallan-scraper-api, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-10). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/ajai-k/echallan-scraper-api
- Repository: https://github.com/ajai-k/echallan-scraper-api

## Overview

Vehicle Challan API looks up traffic challans from Parivahan, returning fresh cached records or scraping the portal when needed. Its main path runs from an API client through authenticated FastAPI routes and service orchestration to portal scraping, OCR-assisted captcha solving, reconciliation in the database, and serialized responses with document links. A scheduled refresh and a standalone CLI are separate entry paths. The README documents additional query and document-serving capabilities; unsampled implementation details are represented only where those relationships are explicit.

Main entry points: [`app.py`](https://github.com/ajai-k/echallan-scraper-api/blob/main/app.py) (FastAPI routes), [`service.py`](https://github.com/ajai-k/echallan-scraper-api/blob/main/service.py) (Lookup orchestration), [`scraper.py`](https://github.com/ajai-k/echallan-scraper-api/blob/main/scraper.py) (Portal scraper), [`db.py`](https://github.com/ajai-k/echallan-scraper-api/blob/main/db.py) (Vehicle and challan store)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["HTTP API"]
  node_api_app["FastAPI routes<br/>[app.py]"]
  node_document_server["Document serving<br/>[app.py]"]
end

subgraph group_workflow["Lookup and refresh"]
  node_service["Lookup orchestration<br/>[service.py]"]
  node_refresh_scheduler["Refresh scheduler<br/>[app.py]"]
  node_date_search["Date-range queries<br/>[service.py]"]
  node_cli["Standalone lookup CLI<br/>[fetch_challan.py]"]
end

subgraph group_scraping["Portal acquisition"]
  node_scraper["Portal scraper<br/>[scraper.py]"]
  node_captcha_ocr["Captcha OCR<br/>[captcha_solver.py]"]
end

subgraph group_storage["Persistence and configuration"]
  node_document_files["Downloaded documents"]
  node_persistence["Reconciliation and serialization<br/>[service.py]"]
  node_challan_store[("Vehicle and challan store<br/>[db.py]")]
  node_configuration["Runtime configuration<br/>[config.py]"]
end

node_client(("API client"))
node_challan_portal["Parivahan portal"]
node_mysql[("MySQL or SQLite")]

node_client -->|"requests"| node_api_app
node_api_app -->|"looks up"| node_service
node_api_app -->|"queries dates"| node_service
node_api_app -->|"lists vehicles"| node_challan_store
node_api_app -->|"triggers refresh"| node_refresh_scheduler
node_refresh_scheduler -->|"schedules refresh"| node_service
node_api_app -->|"mounts files"| node_document_server
node_document_server -->|"serves documents"| node_document_files
node_service -->|"reads and writes"| node_challan_store
node_service -->|"scrapes vehicle"| node_scraper
node_service -->|"checks cache TTL"| node_configuration
node_service -->|"reconciles and serializes"| node_persistence
node_date_search -->|"queries challans"| node_challan_store
node_cli -->|"fetches directly"| node_scraper
node_scraper -->|"solves captcha"| node_captcha_ocr
node_scraper -->|"submits lookup"| node_challan_portal
node_scraper -->|"downloads notices"| node_challan_portal
node_scraper -->|"downloads documents"| node_document_files
node_challan_store -->|"persists records"| node_mysql
node_api_app -->|"uses settings"| node_configuration
node_persistence -->|"builds document links"| node_configuration

click node_api_app "https://github.com/ajai-k/echallan-scraper-api/blob/main/app.py"
click node_document_server "https://github.com/ajai-k/echallan-scraper-api/blob/main/app.py"
click node_service "https://github.com/ajai-k/echallan-scraper-api/blob/main/service.py"
click node_refresh_scheduler "https://github.com/ajai-k/echallan-scraper-api/blob/main/app.py"
click node_date_search "https://github.com/ajai-k/echallan-scraper-api/blob/main/service.py"
click node_cli "https://github.com/ajai-k/echallan-scraper-api/blob/main/fetch_challan.py"
click node_scraper "https://github.com/ajai-k/echallan-scraper-api/blob/main/scraper.py"
click node_captcha_ocr "https://github.com/ajai-k/echallan-scraper-api/blob/main/captcha_solver.py"
click node_persistence "https://github.com/ajai-k/echallan-scraper-api/blob/main/service.py"
click node_challan_store "https://github.com/ajai-k/echallan-scraper-api/blob/main/db.py"
click node_configuration "https://github.com/ajai-k/echallan-scraper-api/blob/main/config.py"

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_api_app,node_document_server,node_client toneBlue
class node_service,node_refresh_scheduler,node_date_search,node_cli,node_mysql toneAmber
class node_scraper,node_captcha_ocr toneMint
class node_document_files,node_persistence,node_challan_store,node_configuration toneRose
class node_challan_portal toneIndigo
```

## Components

### HTTP API

- [FastAPI routes](https://github.com/ajai-k/echallan-scraper-api/blob/main/app.py): `app.py`
- [Document serving](https://github.com/ajai-k/echallan-scraper-api/blob/main/app.py): `app.py`

### Lookup and refresh

- [Lookup orchestration](https://github.com/ajai-k/echallan-scraper-api/blob/main/service.py): `service.py`
- [Refresh scheduler](https://github.com/ajai-k/echallan-scraper-api/blob/main/app.py): `app.py`
- [Date-range queries](https://github.com/ajai-k/echallan-scraper-api/blob/main/service.py): `service.py`
- [Standalone lookup CLI](https://github.com/ajai-k/echallan-scraper-api/blob/main/fetch_challan.py): `fetch_challan.py`

### Portal acquisition

- [Portal scraper](https://github.com/ajai-k/echallan-scraper-api/blob/main/scraper.py): `scraper.py`
- [Captcha OCR](https://github.com/ajai-k/echallan-scraper-api/blob/main/captcha_solver.py): `captcha_solver.py`

### Persistence and configuration

- **Downloaded documents**
- [Reconciliation and serialization](https://github.com/ajai-k/echallan-scraper-api/blob/main/service.py): `service.py`
- [Vehicle and challan store](https://github.com/ajai-k/echallan-scraper-api/blob/main/db.py): `db.py`
- [Runtime configuration](https://github.com/ajai-k/echallan-scraper-api/blob/main/config.py): `config.py`

### Other components

- **API client**
- **Parivahan portal**
- **MySQL or SQLite**

## Connections

- API client → FastAPI routes: requests (evidence: `README.md`)
- FastAPI routes → Lookup orchestration: looks up (evidence: `app.py`)
- FastAPI routes → Lookup orchestration: queries dates (evidence: `app.py`)
- FastAPI routes → Vehicle and challan store: lists vehicles (evidence: `app.py`)
- FastAPI routes → Refresh scheduler: triggers refresh (evidence: `app.py`)
- Refresh scheduler → Lookup orchestration: schedules refresh (evidence: `app.py`)
- FastAPI routes → Document serving: mounts files (evidence: `app.py`)
- Document serving → Downloaded documents: serves documents (evidence: `README.md`)
- Lookup orchestration → Vehicle and challan store: reads and writes (evidence: `service.py`)
- Lookup orchestration → Portal scraper: scrapes vehicle (evidence: `service.py`)
- Lookup orchestration → Runtime configuration: checks cache TTL (evidence: `service.py`)
- Lookup orchestration → Reconciliation and serialization: reconciles and serializes (evidence: `service.py`)
- Date-range queries → Vehicle and challan store: queries challans (evidence: `service.py`)
- Standalone lookup CLI → Portal scraper: fetches directly (evidence: `fetch_challan.py`)
- Portal scraper → Captcha OCR: solves captcha (evidence: `scraper.py`)
- Portal scraper → Parivahan portal: submits lookup (evidence: `README.md`)
- Portal scraper → Parivahan portal: downloads notices (evidence: `README.md`)
- Portal scraper → Downloaded documents: downloads documents (evidence: `README.md`)
- Vehicle and challan store → MySQL or SQLite: persists records (evidence: `db.py`)
- FastAPI routes → Runtime configuration: uses settings (evidence: `app.py`)
- Reconciliation and serialization → Runtime configuration: builds document links (evidence: `service.py`)
