How nishal77/udhaarclear works
1. Overall shape
- This is a multi-surface Next.js App Router application: a public marketing site, an authenticated SaaS dashboard, a payment portal, and a server-side API layer.
- The main architectural split is between app/ route groups, reusable feature components in components/, and server/domain code in lib/.
2. Route boundaries
- app/(auth) contains login/signup screens.
- app/(dashboard) contains the main product: customers, invoices, analytics, payments, reports, reminders, team, settings, WhatsApp/email logs, and MSME/legal features.
- app/onboarding and app/pay/[id] are separate flows that sit outside the normal dashboard experience.
- app/api/* is the backend surface for all business operations.
3. Authentication and onboarding flow
- Auth is OTP-based, with routes for login, signup, OTP verification, and callback handling.
- lib/auth/otp-cookie.ts and proxy.ts indicate session/state enforcement at the edge/middleware boundary.
- app/onboarding handles post-auth setup before a user fully enters the dashboard.
4. Core business domain
- The product centers on receivables management: customers, invoices, reminders, payments, and collections.
- Customer and invoice CRUD exist in both pages and API routes, with matching create/edit/detail screens.
- Legal notice and MSME-related pages suggest debt-recovery workflows beyond simple invoicing.
5. Analytics subsystem
- Analytics is a first-class area with dedicated dashboard pages for heatmap, predictive insights, recovery analytics, and digest views.
- These screens are backed by API routes under app/api/analytics/*.
- UI components in components/analytics appear to be reusable visualizations driven by backend-derived collection data.
6. Reminder and notification engine
- Reminders are orchestrated by a server-side service layer in lib/services/reminder-service.ts and lib/cron/reminder-engine.ts.
- app/api/cron/send-reminders suggests scheduled execution, likely via a hosted cron trigger.
- Delivery channels include email and WhatsApp, with tracking endpoints for email open events and log dashboards for message history.
7. Payments and collection confirmation
- Razorpay is the external payment rail, with dedicated client, payment-link, and webhook helpers in lib/razorpay.
- The payment experience has its own public flow under app/pay/[id], plus confirm/verify endpoints for completing and validating payment events.
- Payment status updates likely feed back into invoices, reminders, and analytics.
8. Settings and tenant administration
- The settings area is modular: profile, billing, team, integrations, webhooks, WhatsApp, and payments.
- components/settings/* and app/(dashboard)/settings/* indicate separate server and client responsibilities.
- Team/business pages suggest multi-business or multi-user workspace management rather than a single-user app.
9. Shared dashboard shell
- The authenticated UI is wrapped by shared layout components: sidebar, top bar, page header, mobile nav, notification dropdown, and dashboard shell.
- Most feature pages are thin route wrappers around feature-specific components, keeping page files light and presentation logic centralized.
- Shared primitives in components/ui and components/shared standardize charts, cards, loading states, and empty states.
10. Domain libraries and integrations
- lib/validations defines schema-level input validation for customers, invoices, and shared structures.
- lib/utils contains common formatting and domain helpers such as currency, date, phone, GST, and API error handling.
- Email, WhatsApp, PDF generation, and Razorpay clients are isolated in lib/email, lib/whatsapp, lib/pdf, and lib/razorpay, keeping external integrations out of page code.
11. Persistence and data contracts
- Prisma is the primary database layer, with schema and migrations under prisma/.
- lib/prisma/client.ts is the main database access point, while types/database.ts and other type files provide typed contracts for external payloads.
- The architecture suggests server routes and services read/write the database, then drive UI state through pages and dashboards.
12. Testing and verification
- Vitest-based tests cover utility and domain logic such as currency formatting, validations, and tone engine behavior.
- This indicates the repo is not only UI-heavy; it also has testable backend/domain rules around reminders, messaging tone, and validation.
Overall, the diagram should show a Next.js front end composed of several route groups, a server API layer for CRUD/integrations/analytics, a shared domain/service layer in lib/, and external dependencies for auth/session, database, payments, email, WhatsApp, and scheduled reminder delivery.
Main entry points: layout Dashboard shell · (dashboard) Receivables · lib Integrations · api Business API
Components 23
Public site
Marketing and pricing surfaces for anonymous visitors.
- Landing site · Homepage, pricing, and marketing content for acquisition.
app/page.tsx
Auth flow
OTP-based sign-in and account creation.
- Auth pages · Login and signup screens for the OTP-based authentication experience.
app/(auth) - Onboarding · Setup flow that runs before full dashboard access.
app/onboarding
Dashboard app
Authenticated product surfaces and shared shell.
- Dashboard shell · Sidebar, top bar, headers, mobile nav, and notification chrome for authenticated views.
components/layout - Receivables · Customers, invoices, payments, reminders, legal notices, and reports.
app/(dashboard) - Analytics UI · Heatmap, predictive, recovery, and digest dashboards backed by API data.
components/analytics - Settings · Profile, billing, team, integrations, webhooks, WhatsApp, and payment settings.
app/(dashboard)/settings - Team admin · Business and member administration for multi-user or multi-business usage.
app/(dashboard)/team - Tone engine · Controls reminder and message tone for recovery communications.
app/(dashboard)/tone-engine/page.tsx
API layer
Route handlers for business operations, analytics, payments, and webhooks.
- Auth API · Login, signup, verification, and callback endpoints.
app/api/auth - Business API · Customers, invoices, dashboard stats, onboarding, and business payment details.
app/api - Analytics API · Heatmap, predictive, and recovery data endpoints for dashboard analytics.
app/api/analytics - Payments API · Payment links, confirm/verify endpoints, and payment-status workflows.
app/api/pay - Reminder API · Reminder creation, reminder sending, and email-open tracking endpoints.
app/api/reminders - Webhooks · Razorpay and WhatsApp webhook entrypoints.
app/api/webhooks
Server domain
Reusable auth, services, integrations, validation, and data access code.
- Auth state · OTP cookie and auth utilities enforced at the edge boundary.
lib/auth/otp-cookie.ts - Reminder service · Reminder orchestration and scheduled delivery logic.
lib/services/reminder-service.ts - Integrations · Email, WhatsApp, Razorpay, PDF, and payment-routing helpers.
lib - Data layer · Database client, schema, migrations, and typed contracts.
lib/prisma/client.ts
External systems
Database, payment, email, WhatsApp, and hosting-triggered jobs.
- Database · Persistent store accessed through Prisma and migrations.
prisma/schema.prisma - Email/WhatsApp · Outbound OTP, reminder, and notification delivery channels.
lib/email/client.ts - Razorpay · External payment processor used for links, confirmations, and webhooks.
lib/razorpay/client.ts - Hosted cron · External scheduler that invokes reminder sending.
app/api/cron/send-reminders/route.ts
Connections 31
- Landing site → Auth pages: start signup · Public visitors move into login or signup flows.
- Auth pages → Auth API: verify OTP · Login and signup screens submit OTP actions to the auth API.
- Auth API → Auth state: set session · Auth handlers read and write OTP/session state.
- Auth state → Email/WhatsApp: send OTP · OTP delivery uses email or other messaging channels.
- Auth API → Onboarding: post-auth · Authenticated users are directed into onboarding before the dashboard.
- Onboarding → Business API: save setup · Onboarding persists business and account setup data.
- Dashboard shell → Receivables: wraps · Shared chrome hosts the primary product areas.
- Dashboard shell → Analytics UI: wraps · Analytics screens use the same authenticated shell.
- Dashboard shell → Settings: wraps · Settings pages live inside the shared dashboard frame.
- Dashboard shell → Team admin: wraps · Team management pages are part of the same workspace shell.
- Dashboard shell → Tone engine: wraps · Tone configuration is exposed as a dashboard area.
- Receivables → Business API: CRUD · Customer, invoice, report, and dashboard pages depend on business APIs.
- Receivables → Payments API: collect · Payment and invoice flows rely on payment endpoints.
- Receivables → Reminder API: remind · Reminder actions and history are driven by reminder APIs.
- Receivables → Webhooks: receive events · Payment and message events feed back through webhook handlers.
- Analytics UI → Analytics API: load insights · Dashboard analytics components consume analytics APIs.
- Settings → Business API: update config · Profile, billing, integrations, and webhook settings persist through APIs.
- Settings → Webhooks: configure · Webhook and provider settings affect incoming event handlers.
- Team admin → Business API: manage workspace · Business and member changes are stored through business APIs.
- Tone engine → Reminder service: shape messaging · Tone controls influence reminder generation and delivery behavior.
- Business API → Data layer: read/write · Business routes persist domain records through the data layer.
- Analytics API → Data layer: aggregate · Analytics handlers derive insights from persisted records.
- Payments API → Integrations: process payments · Payment routes use Razorpay helpers and payment-link utilities.
- Reminder API → Reminder service: orchestrate · Reminder endpoints call the reminder service layer.
- Reminder API → Integrations: deliver · Reminder delivery uses email and WhatsApp adapters.
- Webhooks → Integrations: ingest events · Webhook handlers validate provider payloads and update state.
- Reminder service → Hosted cron: scheduled by · Reminder sending is triggered by an external cron job.
- Reminder service → Email/WhatsApp: send notifications · Service layer dispatches reminder messages through communication providers.
- Integrations → Razorpay: use · Payment helpers connect to Razorpay.
- Integrations → Email/WhatsApp: use · Email and WhatsApp clients connect to delivery providers.
- Data layer → Database: persist · Prisma-backed code stores and reads application data from the database.