Skip to content

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 ​

text
packages/types/src/index.ts

Shared 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:

ts
import type { SellLead, Offer, User, TrustTier } from '@cropto/types'

@cropto/utils ​

text
packages/utils/src/index.ts

Shared 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 ​

text
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 types

A 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 ​

text
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 indicators

React 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.

Internal technical documentation — Cropto