# aryan7691/finsight architecture

> Architecture diagram of the GitHub repository aryan7691/finsight, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-08-25). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/aryan7691/finsight
- Repository: https://github.com/aryan7691/finsight

## Overview

##### Project type and purpose
- This is a full-stack, server-rendered React application built with Next.js (app directory), Prisma ORM, and Inngest for background jobs, focused on personal finance management (accounts, budgets, transactions, email notifications).

##### File structure
- Top-level directories:
- app/ – Next.js “app router” pages, layouts, server & client components
- actions/ – shared server functions for CRUD and background tasks (account, budget, transaction, email, seed)
- lib/ – utilities (Prisma client, Inngest client and function wrappers, auth checks)
- prisma/ – database schema + migration history
- components/ – reusable UI components (drawers, headers, forms, tables, UI primitives)
- hooks/ – custom React hooks (use-fetch)
- emails/ – email templates (JSX)
- public/, styles, config files
- API endpoints:
- app/api/inngest/route.js – entrypoint for Inngest webhooks
- app/api/seed/route.js – seeding endpoint
- Build & deployment:
- next.config.mjs, tailwind.config.js, jsconfig.json, ESLint, PostCSS.

##### README
- (Empty in this case; architecture must be inferred from code.)

##### Main components and interactions
a. Frontend (Next.js App)
– Server Components (SSR pages under app/…)
– Client Components (transaction form, charts, tables)
– Custom hooks (use-fetch) for calling internal API
b. API Layer (Next.js API routes)
– REST or webhook endpoints for seeding & Inngest
c. Business Logic (actions/)
– account.js, budget.js, transaction.js, send-email.js, seed.js
– Invoked either directly by API routes or by background jobs
d. Background Job Processor (Inngest)
– lib/inngest/client.js & function.js register and invoke long-running jobs
e. Database (PostgreSQL via Prisma)
– lib/prisma.js provides a singleton client
– prisma/schema.prisma defines models (Account, Transaction, Budget, etc.)
f. External Services
– Email service (SendGrid, SES, etc. – invoked by send-email actions)

##### Architectural patterns & design principles
- Container pattern (clear separation between frontend, backend, DB, jobs)
- Server Components in Next.js for SSR and data fetching
- Single source of truth for business logic in actions/
- Background processing via event-driven Inngest functions
- Prisma migrations for schema evolution

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% User
    User["User Browser"]:::frontend

    %% Next.js App Container
    subgraph "Next.js App" 
        direction TB
        subgraph "Server & Client Components"
            direction TB
            SSR["Server Components"]:::frontend
            CC["Client Components"]:::frontend
        end
        subgraph "API Layer"
            direction TB
            InngestEndpoint["Inngest Webhook Endpoint"]:::backend
            SeedEndpoint["Seeding Endpoint"]:::backend
        end
    end

    %% Business Logic Actions
    subgraph "Business Logic (actions)" 
        direction TB
        AAcc["account.js"]:::backend
        ABud["budget.js"]:::backend
        ATrans["transaction.js"]:::backend
        ASendEmail["send-email.js"]:::backend
        ASeed["seed.js"]:::backend
        ADash["dashboard.js"]:::backend
    end

    %% Inngest Worker
    subgraph "Inngest Worker / Jobs"
        direction TB
        InClient["lib/inngest/client.js"]:::jobs
        InFunction["lib/inngest/function.js"]:::jobs
    end

    %% Database
    subgraph "Database (PostgreSQL)"
        direction TB
        PrismaClient["lib/prisma.js"]:::database
        Schema["prisma/schema.prisma"]:::database
        Migrations["prisma/migrations"]:::database
    end

    %% Email Templates & Service
    Template["Email Templates"]:::external
    EmailService["External Email Service"]:::external

    %% UI Components
    subgraph "UI Components"
        direction TB
        Comps["components/"]:::frontend
    end

    %% Custom Hooks & Utils
    Hooks["use-fetch.js"]:::frontend
    Utils["lib utils & auth checks"]:::backend

    %% Global Config
    Config["Global Styles & Config"]:::config

    %% Connections
    User -->|"HTTP Request"| SSR
    User -->|"Client Interactions"| CC
    SSR -->|"Server-side Data"| AAcc
    CC -->|"fetch API"| InngestEndpoint
    CC -->|"fetch API"| SeedEndpoint
    SSR -->|"calls Actions"| AAcc
    SSR -->|"calls Actions"| ABud
    SSR -->|"calls Actions"| ATrans
    InngestEndpoint -->|"invoke"| ASeed
    SeedEndpoint -->|"invoke"| ASeed
    CC -->|"useFetch Hook"| Hooks
    Hooks -->|"HTTP"| InngestEndpoint
    InngestEndpoint -->|"publish job"| InClient
    InClient -->|"execute"| InFunction
    InFunction -->|"calls Actions"| AAcc
    InFunction -->|"calls Actions"| ABud
    InFunction -->|"calls Actions"| ATrans
    InFunction -->|"calls Actions"| ASendEmail
    AAcc -->|"DB Read/Write"| PrismaClient
    ABud -->|"DB Read/Write"| PrismaClient
    ATrans -->|"DB Read/Write"| PrismaClient
    ASeed -->|"DB Seed"| PrismaClient
    PrismaClient -->|"reads schema"| Schema
    PrismaClient -->|"applies migrations"| Migrations
    ASendEmail -->|"send email"| EmailService
    ASendEmail -->|"uses template"| Template
    Comps -->|"used by"| CC
    Utils -->|"used by"| SSR
    Config -->|"styles and config"| SSR
    Config -->|"styles and config"| CC

    %% Click Events
    click SSR "https://github.com/aryan7691/finsight/tree/main/app/"
    click CC "https://github.com/aryan7691/finsight/tree/main/app/"
    click InngestEndpoint "https://github.com/aryan7691/finsight/blob/main/app/api/inngest/route.js"
    click SeedEndpoint "https://github.com/aryan7691/finsight/blob/main/app/api/seed/route.js"
    click AAcc "https://github.com/aryan7691/finsight/blob/main/actions/account.js"
    click ABud "https://github.com/aryan7691/finsight/blob/main/actions/budget.js"
    click ATrans "https://github.com/aryan7691/finsight/blob/main/actions/transaction.js"
    click ASendEmail "https://github.com/aryan7691/finsight/blob/main/actions/send-email.js"
    click ASeed "https://github.com/aryan7691/finsight/blob/main/actions/seed.js"
    click ADash "https://github.com/aryan7691/finsight/blob/main/actions/dashboard.js"
    click InClient "https://github.com/aryan7691/finsight/blob/main/lib/inngest/client.js"
    click InFunction "https://github.com/aryan7691/finsight/blob/main/lib/inngest/function.js"
    click PrismaClient "https://github.com/aryan7691/finsight/blob/main/lib/prisma.js"
    click Schema "https://github.com/aryan7691/finsight/blob/main/prisma/schema.prisma"
    click Migrations "https://github.com/aryan7691/finsight/tree/main/prisma/migrations"
    click Template "https://github.com/aryan7691/finsight/blob/main/emails/template.jsx"
    click Comps "https://github.com/aryan7691/finsight/tree/main/components/"
    click Hooks "https://github.com/aryan7691/finsight/blob/main/hooks/use-fetch.js"
    click Utils "https://github.com/aryan7691/finsight/tree/main/lib/"
    click Config "https://github.com/aryan7691/finsight/blob/main/tailwind.config.js"

    %% Styles
    classDef frontend fill:#cce5ff,stroke:#004085,color:#004085
    classDef backend fill:#d4edda,stroke:#155724,color:#155724
    classDef jobs fill:#ffeeba,stroke:#856404,color:#856404
    classDef database fill:#e2e3e5,stroke:#6c757d,color:#6c757d
    classDef external fill:#f8f9fa,stroke:#818182,color:#818182
    classDef config fill:#f5c6cb,stroke:#721c24,color:#721c24
```
