Architecture
Stack
- App: Flutter (Dart), Material 3, Provider/Riverpod for state, Dio for HTTP, sqflite for
offline cache, flutter_secure_storage for JWT.
- Backend: Node.js 20 + Express, PostgreSQL 18, JWT auth.
- WhatsApp: reuse existing getaseed WhatsApp template API (OTP + reminder). No new dep.
- Hosting: backend under /opt or /var/www behind Apache reverse proxy + certbot SSL;
pm2/systemd process. Domain suggestion: udhaar.itsmehere.com (API: api.udhaar.itsmehere.com).
High-level
Flutter app <--HTTPS/JWT--> Node/Express API <--> PostgreSQL
|
+--> getaseed WhatsApp (OTP + reminders)
Auth flow
- User enters shop phone → POST /auth/send-otp → OTP via WhatsApp (getaseed login_otp).
- POST /auth/verify-otp → returns JWT (access, 30d) + shop profile.
- All /api/* calls carry
Authorization: Bearer <jwt>.
Offline-first (app)
- All reads come from local sqflite first; UI never blocks on network.
- Writes go to local DB immediately + queued in an
outbox table.
- A sync service flushes the outbox to the API when online; server is source of truth,
conflicts resolved last-write-wins on
updated_at (v1 simple).
Multi-tenant
- Every row scoped by
shop_id (from JWT). Server enforces shop_id on every query —
never trust a shop_id from the client body.
Money handling
- Store money as integer paise (BIGINT) everywhere. Never float. Format to ₹ in UI only.
Security (non-negotiable)
- JWT secret + DB creds + WhatsApp token in root-only .env, never committed.
- Rate-limit OTP endpoint (per phone + per IP).
- Input validation at every endpoint (celebrate/zod-style).
- Parameterized SQL only (no string concat).