This document maps API endpoints, server-side helpers, and data flow.
- Next.js App Router allows placing route handlers inside
src/app/api/*. - Example endpoints:
src/app/api/auth/*— authentication helperssrc/app/api/schemes/*— scheme listing and filter endpointssrc/app/api/market-prices/*— market data proxy
- Business logic and adapters are located in
src/lib/to keep route handlers thin. - Example:
src/lib/mongodb.ts,src/lib/indexedDB.ts,src/lib/utils.ts.
- UI components call client-side utilities in
src/lib/client*or directlyfetch()app routes. - App routes validate and sanitize inputs, then call
src/lib/*services. - Services interact with external APIs or databases and return typed results.
- Store provider keys and DB URIs in environment variables and avoid committing secrets.
- Use server-only runtime for secrets (Next.js server components or route handlers).