# arstark07/invest_iq architecture

> Architecture diagram of the GitHub repository arstark07/invest_iq, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-04-10). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/arstark07/invest_iq
- Repository: https://github.com/arstark07/invest_iq

## Overview

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: [`app/(main)`](https://github.com/arstark07/invest_iq/tree/main/app/(main)) (Main shell), [`lib/prisma.js`](https://github.com/arstark07/invest_iq/blob/main/lib/prisma.js) (Prisma client), [`actions/dashboard.js`](https://github.com/arstark07/invest_iq/blob/main/actions/dashboard.js) (Dashboard actions), [`actions/wallet.js`](https://github.com/arstark07/invest_iq/blob/main/actions/wallet.js) (Wallet actions)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_ui["UI routes"]
  node_auth_routes["Auth routes<br/>Next.js route group"]
  node_main_shell["Main shell<br/>App layout"]
  node_dashboard_page["Dashboard<br/>Feature page<br/>[page.jsx]"]
  node_portfolio_page["Portfolio<br/>Feature page<br/>[page.jsx]"]
  node_wallet_page["Wallet<br/>Feature page<br/>[page.jsx]"]
  node_transaction_page["Transactions<br/>Feature page<br/>[page.jsx]"]
  node_account_page["Account<br/>Feature page<br/>[page.jsx]"]
  node_risk_page["Risk check<br/>Feature page<br/>[page.jsx]"]
  node_kyc_page["KYC<br/>Feature page<br/>[page.jsx]"]
  node_calculator_page["Calculator<br/>Feature page<br/>[page.jsx]"]
end

subgraph group_services["Server actions"]
  node_dashboard_actions["Dashboard actions<br/>Server actions<br/>[dashboard.js]"]
  node_wallet_actions["Wallet actions<br/>Server actions<br/>[wallet.js]"]
  node_transaction_actions["Transaction actions<br/>Server actions<br/>[transaction.js]"]
  node_investment_actions["Investment actions<br/>Server actions<br/>[investment.js]"]
  node_risk_actions["Risk actions<br/>Server actions<br/>[risk-assessment.js]"]
  node_kyc_actions["KYC actions<br/>Server actions<br/>[kyc.js]"]
end

subgraph group_core["Shared logic"]
  node_prisma_client[("Prisma client<br/>DB adapter<br/>[prisma.js]")]
  node_domain_logic["Domain logic<br/>Finance utilities"]
  node_auth_guard["Auth guard<br/>Middleware/guard<br/>[middleware.js]"]
  node_email_service["Email service<br/>Notification adapter<br/>[email-service.js]"]
  node_ai_sim["AI + sim<br/>Service adapters"]
end

subgraph group_data["Data layer"]
  node_schema[("Schema<br/>[schema.prisma]")]
  node_seed_data["Seed data<br/>Bootstrap<br/>[seed-data.js]"]
end

subgraph group_integrations["External systems"]
  node_event_bus["Inngest<br/>Async jobs<br/>[route.js]"]
  node_payments["Payments<br/>Webhook ingress<br/>[route.js]"]
end

node_auth_routes -->|"protected by"| node_auth_guard
node_main_shell -->|"hosts"| node_dashboard_page
node_main_shell -->|"hosts"| node_portfolio_page
node_main_shell -->|"hosts"| node_wallet_page
node_main_shell -->|"hosts"| node_transaction_page
node_main_shell -->|"hosts"| node_account_page
node_main_shell -->|"hosts"| node_risk_page
node_main_shell -->|"hosts"| node_kyc_page
node_main_shell -->|"hosts"| node_calculator_page
node_dashboard_page -->|"reads"| node_dashboard_actions
node_wallet_page -->|"uses"| node_wallet_actions
node_transaction_page -->|"uses"| node_transaction_actions
node_portfolio_page -->|"uses"| node_investment_actions
node_risk_page -->|"uses"| node_risk_actions
node_kyc_page -->|"uses"| node_kyc_actions
node_dashboard_actions -->|"persists via"| node_prisma_client
node_wallet_actions -->|"persists via"| node_prisma_client
node_transaction_actions -->|"persists via"| node_prisma_client
node_investment_actions -->|"persists via"| node_prisma_client
node_risk_actions -->|"augments with"| node_ai_sim
node_transaction_actions -->|"notifies"| node_email_service
node_wallet_actions -->|"settles via"| node_payments
node_event_bus -->|"triggers"| node_email_service
node_payments -->|"emits"| node_event_bus
node_schema -->|"drives"| node_prisma_client
node_seed_data -->|"bootstraps"| node_schema
node_auth_guard -->|"checks"| node_prisma_client
node_dashboard_actions -->|"enriches"| node_ai_sim

click node_auth_routes "https://github.com/arstark07/invest_iq/tree/main/app/(auth)"
click node_main_shell "https://github.com/arstark07/invest_iq/tree/main/app/(main)"
click node_dashboard_page "https://github.com/arstark07/invest_iq/blob/main/app/(main)/dashboard/page.jsx"
click node_portfolio_page "https://github.com/arstark07/invest_iq/blob/main/app/(main)/portfolio/page.jsx"
click node_wallet_page "https://github.com/arstark07/invest_iq/blob/main/app/(main)/wallet/page.jsx"
click node_transaction_page "https://github.com/arstark07/invest_iq/blob/main/app/(main)/transaction/create/page.jsx"
click node_account_page "https://github.com/arstark07/invest_iq/blob/main/app/(main)/account/[id]/page.jsx"
click node_risk_page "https://github.com/arstark07/invest_iq/blob/main/app/(main)/risk-assessment/page.jsx"
click node_kyc_page "https://github.com/arstark07/invest_iq/blob/main/app/(main)/kyc/page.jsx"
click node_calculator_page "https://github.com/arstark07/invest_iq/blob/main/app/(main)/calculator/page.jsx"
click node_dashboard_actions "https://github.com/arstark07/invest_iq/blob/main/actions/dashboard.js"
click node_wallet_actions "https://github.com/arstark07/invest_iq/blob/main/actions/wallet.js"
click node_transaction_actions "https://github.com/arstark07/invest_iq/blob/main/actions/transaction.js"
click node_investment_actions "https://github.com/arstark07/invest_iq/blob/main/actions/investment.js"
click node_risk_actions "https://github.com/arstark07/invest_iq/blob/main/actions/risk-assessment.js"
click node_kyc_actions "https://github.com/arstark07/invest_iq/blob/main/actions/kyc.js"
click node_prisma_client "https://github.com/arstark07/invest_iq/blob/main/lib/prisma.js"
click node_domain_logic "https://github.com/arstark07/invest_iq/blob/main/lib/transaction-validation.js"
click node_auth_guard "https://github.com/arstark07/invest_iq/blob/main/middleware.js"
click node_email_service "https://github.com/arstark07/invest_iq/blob/main/lib/email-service.js"
click node_event_bus "https://github.com/arstark07/invest_iq/blob/main/app/api/inngest/route.js"
click node_payments "https://github.com/arstark07/invest_iq/blob/main/app/api/webhooks/razorpay/route.js"
click node_ai_sim "https://github.com/arstark07/invest_iq/blob/main/lib/market-data-simulator.js"
click node_schema "https://github.com/arstark07/invest_iq/blob/main/prisma/schema.prisma"
click node_seed_data "https://github.com/arstark07/invest_iq/blob/main/actions/seed-data.js"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_auth_routes,node_main_shell,node_dashboard_page,node_portfolio_page,node_wallet_page,node_transaction_page,node_account_page,node_risk_page,node_kyc_page,node_calculator_page toneBlue
class node_dashboard_actions,node_wallet_actions,node_transaction_actions,node_investment_actions,node_risk_actions,node_kyc_actions toneAmber
class node_prisma_client,node_domain_logic,node_auth_guard,node_email_service,node_ai_sim toneMint
class node_schema,node_seed_data toneRose
class node_event_bus,node_payments toneIndigo
```

## Components

### UI routes

Next.js App Router pages and route-scoped components

- [Auth routes](https://github.com/arstark07/invest_iq/tree/main/app/(auth)): Next.js route group · Sign-in and sign-up entry points with Clerk flow · `app/(auth)`
- [Main shell](https://github.com/arstark07/invest_iq/tree/main/app/(main)): App layout · Authenticated product area layout and routing boundary · `app/(main)`
- [Dashboard](https://github.com/arstark07/invest_iq/blob/main/app/(main)/dashboard/page.jsx): Feature page · Portfolio overview, widgets, insights, and summaries · `app/(main)/dashboard/page.jsx`
- [Portfolio](https://github.com/arstark07/invest_iq/blob/main/app/(main)/portfolio/page.jsx): Feature page · Investment planning and plan/stock modal flows · `app/(main)/portfolio/page.jsx`
- [Wallet](https://github.com/arstark07/invest_iq/blob/main/app/(main)/wallet/page.jsx): Feature page · Deposits, withdrawals, PIN confirmation, and ledger view · `app/(main)/wallet/page.jsx`
- [Transactions](https://github.com/arstark07/invest_iq/blob/main/app/(main)/transaction/create/page.jsx): Feature page · Create transactions and scan receipts · `app/(main)/transaction/create/page.jsx`
- [Account](https://github.com/arstark07/invest_iq/blob/main/app/(main)/account/[id]/page.jsx): Feature page · Account detail and transaction history views · `app/(main)/account/[id]/page.jsx`
- [Risk check](https://github.com/arstark07/invest_iq/blob/main/app/(main)/risk-assessment/page.jsx): Feature page · Questionnaire-driven risk assessment flow · `app/(main)/risk-assessment/page.jsx`
- [KYC](https://github.com/arstark07/invest_iq/blob/main/app/(main)/kyc/page.jsx): Feature page · Identity verification workflow · `app/(main)/kyc/page.jsx`
- [Calculator](https://github.com/arstark07/invest_iq/blob/main/app/(main)/calculator/page.jsx): Feature page · Investment and finance calculator entry point · `app/(main)/calculator/page.jsx`

### Server actions

Domain-oriented business operations

- [Dashboard actions](https://github.com/arstark07/invest_iq/blob/main/actions/dashboard.js): Server actions · Dashboard data assembly and widget feeds · `actions/dashboard.js`
- [Wallet actions](https://github.com/arstark07/invest_iq/blob/main/actions/wallet.js): Server actions · Deposit, withdrawal, and wallet balance operations · `actions/wallet.js`
- [Transaction actions](https://github.com/arstark07/invest_iq/blob/main/actions/transaction.js): Server actions · Transaction creation, validation, and receipt handling · `actions/transaction.js`
- [Investment actions](https://github.com/arstark07/invest_iq/blob/main/actions/investment.js): Server actions · Portfolio planning and investment workflows · `actions/investment.js`
- [Risk actions](https://github.com/arstark07/invest_iq/blob/main/actions/risk-assessment.js): Server actions · Risk profiling and recommendation generation · `actions/risk-assessment.js`
- [KYC actions](https://github.com/arstark07/invest_iq/blob/main/actions/kyc.js): Server actions · Identity verification and KYC status handling · `actions/kyc.js`

### Shared logic

Reusable domain, auth, and service adapters

- [Prisma client](https://github.com/arstark07/invest_iq/blob/main/lib/prisma.js): DB adapter · Central database access layer · `lib/prisma.js`
- [Domain logic](https://github.com/arstark07/invest_iq/blob/main/lib/transaction-validation.js): Finance utilities · Validation, calculator, and risk helpers · `lib/transaction-validation.js`
- [Auth guard](https://github.com/arstark07/invest_iq/blob/main/middleware.js): Middleware/guard · Route protection and user-scoped access checks · `middleware.js`
- [Email service](https://github.com/arstark07/invest_iq/blob/main/lib/email-service.js): Notification adapter · Renders and sends transactional emails · `lib/email-service.js`
- [AI + sim](https://github.com/arstark07/invest_iq/blob/main/lib/market-data-simulator.js): Service adapters · Recommendations, market data simulation, and broker/payment/KYC simulators · `lib/market-data-simulator.js`

### Data layer

Schema, migrations, and seeded content

- [Schema](https://github.com/arstark07/invest_iq/blob/main/prisma/schema.prisma): Prisma schema · Financial domain models and migrations · `prisma/schema.prisma`
- [Seed data](https://github.com/arstark07/invest_iq/blob/main/actions/seed-data.js): Bootstrap · Sample data and demo setup · `actions/seed-data.js`

### External systems

Inbound and outbound third-party boundaries

- [Inngest](https://github.com/arstark07/invest_iq/blob/main/app/api/inngest/route.js): Async jobs · Background event processing and automation · `app/api/inngest/route.js`
- [Payments](https://github.com/arstark07/invest_iq/blob/main/app/api/webhooks/razorpay/route.js): Webhook ingress · Razorpay and Stripe webhook entry points · `app/api/webhooks/razorpay/route.js`

## Connections

- 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
