Skip to content

rheakaru/ComPrice

Repository files navigation

ComPrice

Don't compromise with your data. ComPrice it.

Commodity price intelligence for Indian APMC mandis. Surfaces Agmarknet (Govt. of India) data with satellite-view market cards, price history charts, and Claude-generated briefs.

Stack

  • Next.js 14 (App Router) + TypeScript + Tailwind
  • Firebase (Auth + Firestore + App Hosting)
  • Anthropic SDK — claude-sonnet-4-6 for AI briefs
  • Recharts for price history
  • Google Static Maps for satellite tiles (no interactive maps in v1)

Local setup

cp .env.local.example .env.local
# fill in: DATA_GOV_IN_API_KEY, ANTHROPIC_API_KEY, GOOGLE_MAPS_API_KEY,
#         NEXT_PUBLIC_FIREBASE_CONFIG, FIREBASE_ADMIN_KEY
npm install
npm run dev

If your machine has a corporate proxy / TLS interceptor (Zscaler, Cloudflare WARP, etc.) and fetch() to data.gov.in fails with self-signed-cert errors, either:

  • Add the proxy's root CA via NODE_EXTRA_CA_CERTS=/path/to/ca.pem (preferred), or
  • For local dev only: NODE_TLS_REJECT_UNAUTHORIZED=0 npm run dev. Never set this in prod.

Verify the Agmarknet client

NODE_TLS_REJECT_UNAUTHORIZED=0 npx tsx scripts/smoke-agmarknet.ts

Should print 5 normalized records for Tomato/Karnataka and the aggregated grid view.

Seed commodities

The /api/commodities route auto-seeds on first call. To seed manually:

npx tsx scripts/seed-commodities.ts

Firestore emulator

npm install -g firebase-tools
firebase emulators:start

The emulator UI is at http://localhost:4000.

Architecture

app/
  page.tsx                                              # Home grid (auth-gated)
  login/page.tsx
  market/[marketId]/commodity/[commodityId]/page.tsx    # Detail view
  api/
    commodities/route.ts                                # List + auto-seed
    grid/route.ts                                       # Cached, stale-fallback
    market/[marketId]/commodity/[commodityId]/route.ts  # 90d history + AI brief
    ai/brief/route.ts                                   # Standalone brief generator
    health/route.ts                                     # Env validation status
components/  shadcn-style UI primitives + feature components
lib/
  agmarknet.ts          # data.gov.in client + DD/MM/YYYY → ISO normalization
  commodity-aliases.ts  # Top-30 + alias map
  firebase-admin.ts     # Server SDK
  firebase-client.ts    # Browser SDK
  google-maps.ts        # Geocoding + Static Maps URL builder
  anthropic.ts          # Claude wrapper for briefs
  cache.ts              # Firestore cache helpers (with stale fallback)
  markets-store.ts      # Geocodes + caches Static Maps URL per market (once, ever)
types/
  agmarknet.ts          # Raw + normalized record shapes
  domain.ts             # API response contracts

Cache TTLs

Key TTL Notes
grid_{commodity}_{state} 6 h Stale fallback on Agmarknet errors
detail_{market}_{commodity} 1 h
brief_{market}_{commodity} 1 h Avoid burning Anthropic tokens
Geocoded lat/lng (per market) Forever Mandis don't move
Static Maps URL (per market) 90 d Image content stable; URL key rotation buffer

Agmarknet quirks (handled in lib/agmarknet.ts)

  • Dates arrive as DD/MM/YYYY; we normalize to ISO at ingest
  • Markets report sparsely — we always show most recent record per market, never "today's"
  • Volume is absent from the data.gov.in resource — we surface "Volume: N/A" with a tooltip
  • % change compares to the previous record for that market+commodity, not yesterday
  • Multiple varieties per market+day are averaged in the grid; broken out on the detail page

What's deliberately not in v1

  • Volume scraping from agmarknet.gov.in
  • Satellite imagery analytics (placeholder card on detail page)
  • Inter-mandi arbitrage view (placeholder card)
  • Price predictions (placeholder card)
  • Interactive maps — Static Maps images only

Deploy

firebase deploy --only firestore:rules,firestore:indexes
firebase apphosting:backends:create comprice    # one-time
git push   # App Hosting builds from your connected git repo

Set the same .env.local keys as App Hosting secrets via the Firebase console.

Compliance

ComPrice is not SEBI-registered. We do not provide buy/sell recommendations. AI briefs are descriptive and explicitly avoid trading advice.

About

Don't compromise on your data. ComPrice it

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages