How amogh2212/vahan works
Purpose and entry points
This is an India vehicle-registration analytics system: it ingests VAHAN/TDC data into SQL storage, serves an interactive dashboard and reporting views, supports natural-language/tracked queries, and produces RTO-level EV and contextual-factor insights. Runtime entry point: server.mjs; browser entry points: public/index.html, public/app.js. Operational entry points are script-driven, notably scripts/import-to-db.mjs, scripts/vahan-scraper.mjs, and scripts/run-rto-reports.mjs.
HTTP application boundary
server.mjs composes the HTTP service. Routing/security are separated into lib/http-router.mjs and lib/http-security.mjs; authentication is in lib/auth.mjs. The server exposes application/query/report functionality to static browser clients under public/, rather than embedding presentation logic in the data pipelines. routes/rto-daily-routes.mjs is a distinct route module for daily RTO data.
Data acquisition and persistence
VAHAN scraping is an external-system boundary with retry/failure evidence retained locally. scripts/vahan-scraper.mjs collects data; canonical outputs include data/vahan/vahan_fuel_monthly.csv and data/vahan/vahan_state_maker_fuel.csv; failed source responses are preserved in data/vahan/failures/. Import jobs transfer acquired data into the relational model defined by db/schema.sql, via scripts/import-to-db.mjs and scripts/import-to-neon.mjs.
Query and dashboard layer
The query subsystem turns user-facing requests into normalized, validated data access: lib/query-engine.mjs, lib/query-normalization.mjs, and lib/db.mjs. Its public contract is documented in docs/query-contract-v1.md, with a machine-readable corpus at data/query-tests/dashboard-query-contract-v1.json. Main dashboard/map/compare clients consume this backend through public/app.js, public/map.js, and public/compare.js. This is a key correctness boundary: user/AI phrasing should be normalized before database querying.
Reporting and RTO intelligence
Domain services produce structured reports above raw registrations: national/monthly/OEM views in lib/registrations.mjs, lib/maker-registrations.mjs, and lib/monthly-sales-report.mjs; RTO reporting and insights in lib/rto-reports.mjs, lib/rto-insights.mjs, and lib/rto-daily-snapshots.mjs. Corresponding browser report pages live under public/reports/, including public/reports/rto-reports.js and public/reports/monthly-sales.js. Daily snapshot execution is operationalized by scripts/run-rto-daily-snapshots.mjs.
RTO factor enrichment pipeline
A separate enrichment pipeline associates RTO outcomes with external contextual factors, source evidence, events, validation, and generated narrative. Its stages are represented by lib/rto-factor-source-collector.mjs, lib/rto-factor-events.mjs, lib/rto-factor-validation.mjs, and lib/rto-factor-narrative.mjs; orchestration is in lib/rto-factor-agent.mjs and lib/rto-factor-daily-automation.mjs. Source registry data is versioned at data/rto-factor-source-registry.json. This boundary should preserve provenance and validation separately from derived explanations.
Runtimes, infrastructure, and automation
The application is Node.js/ESM (.mjs) with a SQL database abstraction. Repository artifacts indicate local PostgreSQL plus Neon deployment/migration support (scripts/configure-local-postgres.mjs, scripts/apply-neon-schema.mjs), and Cockroach compatibility checking (.env.cockroach.test.example, scripts/cockroach-test-runner.mjs). GitHub Actions schedule tracked-query, RTO-daily, and production-risk workflows under .github/workflows/. External integrations include the VAHAN source system, optional local/hosted AI query providers suggested by scripts/check-ollama.mjs and scripts/groq-query-provider-unit-check.mjs, and Telegram notifications through lib/telegram-bot.mjs.
Main entry points: http-router.mjs Routing, security & auth · db.mjs Database abstraction · server.mjs Node HTTP server · rto-daily-snapshots.mjs Daily RTO snapshots
Components 22
HTTP & browser
- Node HTTP server · Composes the service and static browser delivery.
server.mjs - Routing, security & auth
lib/http-router.mjs - Daily RTO routes
routes/rto-daily-routes.mjs - Dashboard clients
public/app.js
Acquisition & SQL
- VAHAN scraper · Retains failed source responses as evidence.
scripts/vahan-scraper.mjs - VAHAN source
- VAHAN canonical files
data/vahan/vahan_fuel_monthly.csv - Database import jobs
scripts/import-to-db.mjs - Relational schema
db/schema.sql - SQL database
Query & reporting
- Query engine
lib/query-engine.mjs - Query normalization · Normalizes user and AI phrasing before database access.
lib/query-normalization.mjs - Database abstraction
lib/db.mjs - Registration reports · Produces national, monthly, and OEM reporting views.
lib/registrations.mjs
RTO intelligence
- RTO reports & insights
lib/rto-reports.mjs - Daily RTO snapshots
lib/rto-daily-snapshots.mjs - RTO factor agent · Coordinates provenance, validation, and derived narrative.
lib/rto-factor-agent.mjs - Factor source collector
lib/rto-factor-source-collector.mjs - Factor validation
lib/rto-factor-validation.mjs - Factor narrative
lib/rto-factor-narrative.mjs
Automation & integrations
- Scheduled workflows · Runs tracked-query, RTO-daily, and production-risk automation.
- Telegram notifications
lib/telegram-bot.mjs
Connections 25
- Node HTTP server → Routing, security & auth: delegates requests
- Node HTTP server → Daily RTO routes: mounts
- Node HTTP server → Dashboard clients: serves
- Routing, security & auth → Query engine: query API
- Routing, security & auth → Registration reports: report API
- Daily RTO routes → Daily RTO snapshots: daily data API
- Dashboard clients → Routing, security & auth: requests data
- VAHAN source → VAHAN scraper: registration data
- VAHAN scraper → VAHAN canonical files: writes CSV and failures
- VAHAN canonical files → Database import jobs: input
- Relational schema → SQL database: defines
- Database import jobs → SQL database: loads
- Query engine → Query normalization: normalizes requests
- Query normalization → Database abstraction: validated query
- Database abstraction → SQL database: SQL access
- Registration reports → Database abstraction: aggregates registrations
- RTO reports & insights → Database abstraction: queries RTO outcomes
- Daily RTO snapshots → SQL database: persists daily state
- RTO factor agent → Factor source collector: collects evidence
- Factor source collector → Factor validation: source evidence
- Factor validation → Factor narrative: validated factors
- Factor narrative → RTO reports & insights: contextual insights
- Scheduled workflows → Daily RTO snapshots: runs daily
- Scheduled workflows → RTO factor agent: runs enrichment
- Scheduled workflows → Telegram notifications: notifies