How arstark07/invest_iq works
1. Overall shape
- Invest_IQ is a Next.js 15 App Router application with a strong split between:
- route-based UI under app/
- server-side business actions under actions/
- shared service/util layers under lib/
- database schema/migrations under prisma/
- It behaves like a financial platform with multiple bounded domains rather than a single-purpose app.
2. Routing and page composition
- The UI is divided into two top-level route groups:
- app/(auth) for sign-in/sign-up
- app/(main) for the authenticated product area
- Main product pages cover dashboard, portfolio, wallet, transaction creation, account detail, calculator, KYC, risk assessment, and seed/testing.
- Most pages are thin route shells that compose feature-specific components from app/(main)/*/_components and components/.
3. Authentication and app boundary
- Authentication is handled by Clerk, with dedicated sign-in/sign-up routes and redirect flow configured in environment variables.
- middleware.js and lib/checkUser.js indicate a guard layer that likely protects authenticated routes and user-scoped operations.
- The auth boundary separates public landing/auth flows from the internal finance workspace.
4. Core product domains
- The main functional subsystems are:
- Dashboard: portfolio overview, metrics, widgets, insights
- Portfolio / Investment planning: plan creation, stock/plan detail modals, recommendations
- Wallet: deposits, withdrawals, PIN-based confirmation, transaction list
- Transactions: transaction creation, receipt scanning, validation, receipt notifications
- Risk assessment: questionnaire-driven profile generation and recommendations
- KYC: identity verification flow
- Account management: account-specific views and transaction histories
- These are distinct enough to diagram as separate modules with shared persistence.
5. Stateful business logic lives in server actions
- The actions/ folder is the main application service layer.
- Files like account.js, wallet.js, transaction.js, investment.js, risk-assessment.js, kyc.js, dashboard.js, recommendations.js, and budget.js suggest domain-oriented server actions.
- actions/seed.js and actions/seed-data.js support bootstrapping sample data.
- These actions are the primary bridge between UI interactions and backend services/database.
6. Persistence layer
- Data is stored in PostgreSQL via Supabase, accessed through Prisma.
- prisma/schema.prisma and the migration history show schema evolution for financial entities such as budgets, merchants, categories, and other transactional fields.
- lib/prisma.js is the central DB client, so most business workflows likely flow:
- UI → server action → Prisma → Supabase/Postgres
7. External integrations and service adapters
- The app integrates with several external services through wrappers in lib/:
- Clerk for authentication
- Razorpay for payment processing/webhooks
- Resend for email delivery
- ArcJet for security/rate limiting
- Gemini / Google Generative AI for recommendations and insights
- Inngest for background jobs and event processing
- These integrations are isolated behind service modules such as payment-gateway.js, email-service.js, broker-integration.js, simulate-payment.js, simulate-broker.js, and lib/inngest/*.
8. Event-driven and webhook-driven workflows
- app/api/webhooks/razorpay and app/api/webhooks/stripe act as external event ingress points.
- app/api/inngest/route.js exposes the Inngest handler for asynchronous/background execution.
- This suggests a split between:
- synchronous user actions in server actions
- asynchronous automations such as notifications, checks, and scheduled workflows via Inngest/webhooks
9. Notification and email subsystem
- Email templates live in emails/, including:
- low-balance alerts
- overspend alerts
- transaction receipts
- lib/email-service.js likely renders/sends these templates.
- This subsystem is downstream of financial events such as transaction creation, wallet changes, or budget/risk thresholds.
10. AI, analytics, and simulation
- The platform includes AI-assisted finance features via actions/recommendations.js, lib/risk-assessment.js, and investment calculators.
- There is also a simulation layer:
- lib/market-data-simulator.js
- lib/simulate-broker.js
- lib/simulate-kyc.js
- lib/simulate-payment.js
- These modules suggest the app can demonstrate financial workflows without depending entirely on live market/broker/payment systems.
11. Client-side component structure
- Shared UI lives in components/, including:
- top-level shell elements like header/hero
- modals/drawers for account creation, asset detail, payment simulation
- calculator components
- finance-specific prompts and alerts
- components/ui/ is a Shadcn/Radix component library used across features.
- The client layer is mostly presentational and interactive, with domain data coming from server actions or hooks.
12. Data and helper layers
- data/ contains static content such as landing-page copy and categories.
- hooks/use-fetch.js indicates at least some client-side fetching abstraction.
- lib/utils.js, transaction-validation.js, investment-calculator.js, risk-constants.js, and similar modules hold pure domain logic that can be reused across UI, actions, and automation.
13. Operational and supporting pieces
- app/api/seed and app/(main)/seed support data bootstrapping and local/demo setup.
- scripts/generate-report.* and the report/ folder are supporting artifacts, likely for documentation or project reporting rather than runtime behavior.
- components.json, Tailwind config, and the Shadcn UI setup indicate a design-system-driven frontend implementation.
14. Primary architectural flow to draw
- The cleanest diagram is:
- Browser/UI pages in app/(main) and app/(auth)
- → server actions and API routes
- → shared domain/service modules in lib/
- → Prisma
- → Supabase/Postgres
- Side channels feed into the system from Razorpay webhooks, Inngest, and email delivery, while AI/simulation modules augment financial decision-making and testing.
Main entry points: (main) Main shell · prisma.js Prisma client · dashboard.js Dashboard actions · wallet.js Wallet actions
Components 25
UI routes
Next.js App Router pages and route-scoped components
- Auth routes · Sign-in and sign-up entry points with Clerk flow
app/(auth) - Main shell · Authenticated product area layout and routing boundary
app/(main) - Dashboard · Portfolio overview, widgets, insights, and summaries
app/(main)/dashboard/page.jsx - Portfolio · Investment planning and plan/stock modal flows
app/(main)/portfolio/page.jsx - Wallet · Deposits, withdrawals, PIN confirmation, and ledger view
app/(main)/wallet/page.jsx - Transactions · Create transactions and scan receipts
app/(main)/transaction/create/page.jsx - Account · Account detail and transaction history views
app/(main)/account/[id]/page.jsx - Risk check · Questionnaire-driven risk assessment flow
app/(main)/risk-assessment/page.jsx - KYC · Identity verification workflow
app/(main)/kyc/page.jsx - Calculator · Investment and finance calculator entry point
app/(main)/calculator/page.jsx
Server actions
Domain-oriented business operations
- Dashboard actions · Dashboard data assembly and widget feeds
actions/dashboard.js - Wallet actions · Deposit, withdrawal, and wallet balance operations
actions/wallet.js - Transaction actions · Transaction creation, validation, and receipt handling
actions/transaction.js - Investment actions · Portfolio planning and investment workflows
actions/investment.js - Risk actions · Risk profiling and recommendation generation
actions/risk-assessment.js - KYC actions · Identity verification and KYC status handling
actions/kyc.js
Shared logic
Reusable domain, auth, and service adapters
- Prisma client · Central database access layer
lib/prisma.js - Domain logic · Validation, calculator, and risk helpers
lib/transaction-validation.js - Auth guard · Route protection and user-scoped access checks
middleware.js - Email service · Renders and sends transactional emails
lib/email-service.js - AI + sim · Recommendations, market data simulation, and broker/payment/KYC simulators
lib/market-data-simulator.js
Data layer
Schema, migrations, and seeded content
Connections 28
- Auth routes → Auth guard: protected by · Authenticated flows are separated from public auth entry points
- Main shell → Dashboard: hosts · Main layout renders the product dashboard area
- Main shell → Portfolio: hosts · Main layout renders portfolio routes
- Main shell → Wallet: hosts · Main layout renders wallet routes
- Main shell → Transactions: hosts · Main layout renders transaction routes
- Main shell → Account: hosts · Main layout renders account detail routes
- Main shell → Risk check: hosts · Main layout renders risk assessment routes
- Main shell → KYC: hosts · Main layout renders KYC routes
- Main shell → Calculator: hosts · Main layout renders calculator routes
- Dashboard → Dashboard actions: reads · Dashboard UI is assembled from server-side data
- Wallet → Wallet actions: uses · Wallet UI triggers balance and cash movement actions
- Transactions → Transaction actions: uses · Transaction form and receipt scan depend on transaction actions
- Portfolio → Investment actions: uses · Portfolio planning delegates to investment service actions
- Risk check → Risk actions: uses · Risk questionnaire feeds recommendation actions
- KYC → KYC actions: uses · KYC UI invokes verification actions
- Dashboard actions → Prisma client: persists via · Dashboard aggregates account and finance records from the database
- Wallet actions → Prisma client: persists via · Wallet operations update stored balances and transactions
- Transaction actions → Prisma client: persists via · Transactions are validated and stored through Prisma
- Investment actions → Prisma client: persists via · Portfolio state and investment plans are stored in the database
- Risk actions → AI + sim: augments with · Risk scoring and recommendations use AI/simulation helpers
- Transaction actions → Email service: notifies · Receipts and alerts are sent through email templates
- Wallet actions → Payments: settles via · Wallet funding and withdrawals connect to payment webhooks and gateways
- Inngest → Email service: triggers · Background jobs can fan out into notifications
- Payments → Inngest: emits · External payment events can enter async processing
- Schema → Prisma client: drives · Schema defines the database models used by the client
- Seed data → Schema: bootstraps · Seed content matches the finance domain schema
- Auth guard → Prisma client: checks · User lookup and session-scoped guards may depend on stored user state
- Dashboard actions → AI + sim: enriches · Dashboard insights and recommendations can use AI helpers