How rahul1015s/genexpence works
1. This is a Next.js App Router application with a strong split between presentation, API routes, and server-side domain logic. The top-level app/ tree defines the user-facing routes, while app/api/ contains the HTTP boundary for all business operations.
2. The repository is organized around multiple user personas and product modes rather than a single generic UI:
- personal finance/dashboard routes
- professional bookkeeping/invoicing routes
- admin/owner back-office routes
- auth/onboarding and marketing pages
- calculators, analytics, support, pricing, and legal pages
3. The main request flow is consistent across the app: page components in app/**/page.tsx render feature-specific React components from components/**, those features call route handlers in app/api/**/route.ts, and the route handlers delegate into lib/server/** for domain rules and data access.
4. The backend logic is concentrated in lib/server/, which is split by domain: dashboard, personal finance, professional features, invoices, notifications, owner/admin, wealth, and app bootstrap/auth helpers. This is the main boundary where authorization, business rules, and cross-entity orchestration appear to live.
5. Data persistence is model-driven. The models/ directory includes entities such as User, Transaction, Invoice, Client, Investment, Notification, Announcement, OTP, SessionNotice, NetWorthHistory, and audit logs. That layout strongly suggests a database-backed application with a document-model layer, with lib/db/db.ts providing the connection/runtime access point.
6. Authentication and account recovery are a dedicated subsystem. There are separate routes and screens for login, signup, magic-link, OTP/two-factor verification, password reset, email verification, and session notices. Supporting code in lib/auth*, lib/token.ts, lib/crypto.ts, and lib/session-device.ts indicates session management, security tokens, and device/session tracking.
7. The app has an explicit mode/context layer. contexts/ModeContext.tsx, providers/AuthProvider.tsx, and providers/ThemeProvider.tsx sit near the root, while routes like app/dashboard, app/professional, and app/owner imply the UI and APIs switch behavior based on the current user mode and subscription level. lib/subscription.ts and the app/api/user/subscription/* routes reinforce that access is feature-gated.
8. The personal finance dashboard is a large subsystem. It covers transactions, accounts, budgets, goals, recurring items, categories, charts, investments, lent/borrowed tracking, net worth, and dashboard summaries. Its UI lives mostly under components/Dashboard, and its server endpoints are grouped under app/api/dashboard/*, app/api/transactions/*, app/api/investments/*, app/api/lent-borrowed/*, and app/api/wealth/*.
9. The professional/business subsystem is similarly self-contained. It includes clients, invoices, payments, PDF generation, GST summaries, reports, team settings, notifications, and transaction enhancements. The main UI lives under components/Professional, with matching API groups under app/api/professional/*, and invoice-specific helpers in lib/invoice-pdf.ts, lib/invoice-utils.ts, and lib/invoiceNumber.ts.
10. Administrative and owner workflows are separated from end-user functionality. app/admin/* and app/owner/* expose user management, announcements, audit logs, billing, analytics, and spend controls, while API routes under app/api/admin/* provide privileged operations like user deletion, password resets, verification changes, announcements, and overview data. This is a distinct back-office boundary with elevated permissions.
11. Notifications, announcements, and operational messaging are first-class cross-cutting concerns. There are API routes for active announcements, admin notification processing, session notices, and general notifications, plus client-side banner components and email template code in components/email-templates* and lib/email.ts. This suggests both in-app and email delivery paths.
12. Offline and PWA support are part of the architecture, not an afterthought. public/sw.js, components/PwaRegister.tsx, components/App/OfflineSyncManager.tsx, components/App/OfflineStatusIndicator.tsx, and lib/offline/* show a client-side caching/sync layer, likely centered on transaction data and resilient usage when disconnected.
13. Calculators and wealth tools are a separate product surface. app/(dashboard)/calculators, components/calculators/*, and lib/calculators/* contain reusable financial calculation engines and UI shells for loan EMI, SIP, tax, XIRR, and goal planning. The presence of lib/wealth-engine.ts and dedicated wealth routes indicates a computation-heavy subsystem with shared formatting and insight generation.
14. Reusable UI and shell composition are centralized in components/ui/* and layout components such as components/Dashboard/DashboardLayout.tsx, components/Dashboard/DashboardSidebar.tsx, and components/AppRootClient.tsx. The visual layer is built from shared primitives, then specialized per persona and feature.
15. Overall, the architecture is a multi-tenant, role- and mode-aware finance platform: Next.js pages provide the UX, API route handlers expose domain operations, lib/server enforces business logic and authorization, and models/lib/db persist domain state. The main diagram should emphasize the separation between persona-specific feature areas and the shared cross-cutting systems for auth, subscription, notifications, offline sync, and data models.
Main entry points: app App routes · Dashboard Dashboard comps · db.ts DB runtime · models Domain models
Components 26
Presentation
App Router routes and feature UIs
- App routes · Top-level App Router surfaces for persona-specific and public pages
app - Auth pages · Login, signup, OTP, reset, and email verification screens
app/(auth) - Dashboard UI · Personal finance dashboard, wealth, accounts, goals, investments, and transactions
app/dashboard - Professional UI · Professional invoicing, clients, GST, reports, and notifications pages
app/professional - Admin UI · Owner and admin console for users, announcements, audit, billing, and spend
app/admin - Public pages · Home, pricing, support, legal, analytics, and search surfaces
app/page.tsx - Dashboard comps · Personal finance dashboard composition and widgets
components/Dashboard - Professional comps · Client, invoice, GST, report, and settings UI pieces
components/Professional - Admin comps · Owner/admin tables, detail views, and announcement tools
components/Admin - Auth comps · Reusable login, signup, reset, OTP, and magic-link forms
components/auth
API Layer
HTTP route handlers grouped by domain
- Auth API · Authentication, password reset, OTP, session, and signup endpoints
app/api/auth - Dashboard API · Accounts, budgets, goals, recurring items, charting, and transactions
app/api/dashboard - Professional API · Clients, invoices, GST, reports, team, settings, and collaboration endpoints
app/api/professional - Admin API · User administration, announcements, audit, overview, and enforcement actions
app/api/admin - Shared API · User profile, mode, subscription, notifications, search, health, wealth, and personal helpers
app/api
Server Logic
Domain rules, orchestration, and auth guards
- Auth guard · Route authorization, app bootstrap, session policy, and user context
lib/server/route-auth.ts - Dashboard logic · Personal finance orchestration for transactions, summaries, and dashboard views
lib/server/personal-dashboard.ts - Professional logic · Business workflows for clients, invoices, reports, notifications, and collaboration
lib/server/professional.ts - Owner logic · Owner/admin controls, billing, analytics, and elevated operations
lib/server/owner-admin.ts - Wealth logic · Net worth and wealth profile orchestration
lib/server/wealth.ts
Shared Systems
Cross-cutting client and utility subsystems
- Auth stack · Client auth, tokens, crypto, sessions, devices, and subscription gating
lib/auth.ts - Offline stack · Service worker, IndexedDB cache, and transaction sync
lib/offline - Calculators · Reusable loan, SIP, tax, XIRR, formatting, and insight helpers
lib/calculators - Messaging · In-app notices, announcements, and email template delivery
lib/email.ts
Data Model
Persistence models and database access
- DB runtime · Database connection and persistence runtime access
lib/db/db.ts - Domain models · User, transaction, invoice, client, investment, notification, and audit entities
models
Connections 32
- App routes → Auth pages: renders · App Router exposes auth screens
- App routes → Dashboard UI: renders · App Router exposes personal finance surfaces
- App routes → Professional UI: renders · App Router exposes professional surfaces
- App routes → Admin UI: renders · App Router exposes admin surfaces
- App routes → Public pages: renders · App Router exposes public marketing and utility pages
- Auth pages → Auth comps: uses · Auth screens are built from shared forms
- Dashboard UI → Dashboard comps: uses · Dashboard pages compose feature widgets
- Professional UI → Professional comps: uses · Professional pages compose business UI
- Admin UI → Admin comps: uses · Admin pages compose privileged UI
- Auth comps → Auth API: calls · Auth forms submit to auth endpoints
- Dashboard comps → Dashboard API: calls · Dashboard UI fetches and mutates finance data
- Professional comps → Professional API: calls · Professional UI drives business APIs
- Admin comps → Admin API: calls · Admin UI invokes privileged endpoints
- Auth API → Auth guard: delegates · Auth handlers rely on authorization and session helpers
- Dashboard API → Dashboard logic: delegates · Dashboard routes hand off to domain logic
- Professional API → Professional logic: delegates · Professional routes hand off to business logic
- Admin API → Owner logic: delegates · Admin routes hand off to owner/admin logic
- Shared API → Auth guard: guards · Shared platform endpoints still enforce user context and access rules
- Dashboard logic → DB runtime: reads/writes · Dashboard logic persists to the database runtime
- Professional logic → DB runtime: reads/writes · Professional logic persists business data
- Owner logic → DB runtime: reads/writes · Admin workflows operate on persisted records
- Wealth logic → DB runtime: reads/writes · Wealth features persist profile and history state
- Dashboard logic → Domain models: uses · Dashboard logic works over transaction and finance entities
- Professional logic → Domain models: uses · Professional logic works over invoice and client entities
- Owner logic → Domain models: uses · Admin logic works over user, audit, and announcement entities
- Wealth logic → Domain models: uses · Wealth logic works over net worth and profile entities
- Auth stack → Auth API: supports · Identity stack backs authentication endpoints
- Auth stack → Shared API: supports · Mode, subscription, and profile endpoints use shared auth state
- Offline stack → Dashboard comps: supports · Offline sync and status are part of dashboard UX
- Calculators → Dashboard comps: supports · Dashboard wealth and calculators reuse finance engines
- Messaging → Shared API: supports · Announcements, notifications, and emails are delivered through shared messaging
- Messaging → Admin API: supports · Admin operations trigger operational messaging