Shared Packages — packages/*
Four TypeScript packages let the apps share a single source of truth for the wire contract, data fetching, and utilities. They are referenced via npm workspaces ("@cropto/x": "*") and imported like any dependency.
@cropto/types
packages/types/src/index.tsShared domain types and enums — User, SellLead, BuyLead, Offer, BuyBid, TrustTier, status enums, and API DTOs. Every app imports these so the client and server agree on shapes:
import type { SellLead, Offer, User, TrustTier } from '@cropto/types'@cropto/utils
packages/utils/src/index.tsShared pure utility functions used across apps (formatting, small helpers). Kept dependency-light so it's safe to import in both Node and browser/React Native contexts.
@cropto/api-client
packages/api-client/src/
├── client.ts Axios instance + JWT injection + error normalisation
├── auth.ts Auth endpoints
├── sell-leads.ts Sell lead endpoints
├── buy-leads.ts Buy lead endpoints
├── products.ts Products / inventory
├── batches.ts Batch endpoints
├── deals.ts Deals
├── orders.ts Orders / receipt / dispatch
├── inquiries.ts Inquiry threads
├── notifications.ts Notifications
├── quota.ts Quota
├── reports.ts Reports / P&L
├── taxonomy.ts Taxonomy tree
├── profiles.ts Farmer/trader profiles
├── public.ts Public (no-auth) endpoints
├── users.ts Public profile
├── dashboard.ts Dashboard tiles
├── lead-display.ts Lead display helpers
├── product-status.ts Product status helpers
├── indianDistricts.ts Static district data
└── types.ts Client-specific typesA typed API client shared by apps/web and apps/mobile. Every network call goes through client.ts, which injects the JWT and normalises errors into the standard { success, data | error } envelope. This is why neither client ever uses raw fetch.
@cropto/hooks
packages/hooks/src/
├── query-keys.ts Centralised React Query key factory (the single source of cache keys)
├── auth.ts Auth hooks
├── sell-leads.ts useSellLeads etc.
├── buy-leads.ts
├── products.ts
├── deals.ts
├── inquiries.ts
├── notifications.ts
├── quota.ts
├── profiles.ts
├── taxonomy.ts
├── dashboard.ts
├── public.ts
└── invalidate-unread.ts Cache invalidation for unread indicatorsReact Query hooks wrapping @cropto/api-client. Shared by web and mobile so both clients fetch, cache, and invalidate identically. query-keys.ts is the canonical key factory — invalidation logic (e.g. clearing unread indicators after markThreadRead) references these keys rather than enumerating filters, so every cache variant is caught.
Dependency direction
Types and utils sit at the bottom (imported by everyone, importing nothing app-specific); api-client builds on them; hooks builds on api-client; the apps sit on top.
