# dmdeepakmehta/spend architecture

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

- Interactive diagram: https://gitdiagram.com/dmdeepakmehta/spend
- Repository: https://github.com/dmdeepakmehta/spend

## Overview

##### Project type and purpose
- This is a full-stack web application: an AI-driven personal finance platform built with Next.js (App Router), Tailwind CSS, Prisma (PostgreSQL via Supabase), Inngest for background jobs, ArcJet for AI embedding, Clerk for authentication, Shadcn/UI for components, and Resend for emails.
- Users sign up/sign in, manage budgets, view dashboards, create transactions (with receipt scanning), and receive summary emails.

##### File structure
- Top-level config: next.config.mjs, postcss.config.mjs, tailwind.config.js, middleware.js, jsconfig.json, .eslintrc.json.
- “app” directory (Next.js App Router): authentication routes (app/(auth)), main UI (app/(main)), global layout (app/layout.js), API routes (app/api/inngest, app/api/seed).
- “actions” directory: Inngest cron / function definitions (account.js, budget.js, dashboard.js, seed.js, send-email.js, transaction.js).
- “lib” directories:
- app/lib/schema.js (Zod or GraphQL schemas)
- lib/arcjet.js (AI embeddings), lib/checkUser.js, lib/inngest/client.js, lib/inngest/function.js, lib/prisma.js, lib/utils.js
- “prisma” folder: database schema and migrations.
- “components” and “components/ui”: shared React UI and Shadcn offerings.
- “data”: seed or static data (categories, landing).
- “emails”: JSX templates for Resend.

##### README for additional insights
- The stack: Next.js, Supabase, Tailwind, Prisma, Inngest, ArcJet, Shadcn UI, Clerk, Resend.
- Environment variables drive database, authentication, AI API keys, email service.

## Diagram (Mermaid)

```mermaid
graph TB
  %% External Services
  Clerk["Clerk Auth"]:::external
  ArcJet["ArcJet AI Service"]:::external
  Resend["Resend Email Service"]:::external

  %% Database
  Postgres[(PostgreSQL DB on Supabase)]:::db

  %% Browser Client
  subgraph "Browser Client"
    Browser["Browser UI"]:::frontend
  end

  %% Frontend Layer
  subgraph "Frontend Layer"
    subgraph "Next.js App Router (app/)"
      AppDir["app/"]:::frontend
      click AppDir "https://github.com/dmdeepakmehta/spend/tree/main/app/"
      GlobalLayout["Global layout (layout.js)"]:::frontend
      click GlobalLayout "https://github.com/dmdeepakmehta/spend/blob/main/app/layout.js"
      subgraph "Auth Routes"
        AuthLayout["layout.js"]:::frontend
        click AuthLayout "https://github.com/dmdeepakmehta/spend/blob/main/app/(auth)/layout.js"
        SignIn["sign-in page"]:::frontend
        click SignIn "https://github.com/dmdeepakmehta/spend/blob/main/app/(auth)/sign-in/[[...sign-in]]/page.jsx"
        SignUp["sign-up page"]:::frontend
        click SignUp "https://github.com/dmdeepakmehta/spend/blob/main/app/(auth)/sign-up/[[...sign-up]]/page.jsx"
      end
      subgraph "Main Routes"
        MainLayout["layout.js"]:::frontend
        click MainLayout "https://github.com/dmdeepakmehta/spend/blob/main/app/(main)/layout.js"
        Dashboard["Dashboard page"]:::frontend
        click Dashboard "https://github.com/dmdeepakmehta/spend/blob/main/app/(main)/dashboard/page.jsx"
        AccountPage["Account page"]:::frontend
        click AccountPage "https://github.com/dmdeepakmehta/spend/blob/main/app/(main)/account/[id]/page.jsx"
        TransactionCreate["Create Transaction page"]:::frontend
        click TransactionCreate "https://github.com/dmdeepakmehta/spend/blob/main/app/(main)/transaction/create/page.jsx"
      end
    end
    subgraph "UI Components"
      UIPrimitives["components/ui/"]:::frontend
      click UIPrimitives "https://github.com/dmdeepakmehta/spend/tree/main/components/ui/"
      Header["Header"]:::frontend
      click Header "https://github.com/dmdeepakmehta/spend/blob/main/components/header.jsx"
      Hero["Hero"]:::frontend
      click Hero "https://github.com/dmdeepakmehta/spend/blob/main/components/hero.jsx"
      Drawer["CreateAccountDrawer"]:::frontend
      click Drawer "https://github.com/dmdeepakmehta/spend/blob/main/components/create-account-drawer.jsx"
    end
    GlobalsCSS["globals.css"]:::frontend
    click GlobalsCSS "https://github.com/dmdeepakmehta/spend/blob/main/app/globals.css"
  end

  %% Backend Layer
  subgraph "Next.js Server"
    NJS["Next.js Server"]:::internal
    Middleware["middleware.js"]:::internal
    click Middleware "https://github.com/dmdeepakmehta/spend/blob/main/middleware.js"
    Schema["Zod Schemas"]:::internal
    click Schema "https://github.com/dmdeepakmehta/spend/blob/main/app/lib/schema.js"
    Utils["utils.js"]:::internal
    click Utils "https://github.com/dmdeepakmehta/spend/blob/main/lib/utils.js"
    CheckUser["checkUser.js"]:::internal
    click CheckUser "https://github.com/dmdeepakmehta/spend/blob/main/lib/checkUser.js"
  end

  %% API Routes
  subgraph "API Routes"
    InngestWebhook["/api/inngest (route.js)"]:::internal
    click InngestWebhook "https://github.com/dmdeepakmehta/spend/blob/main/app/api/inngest/route.js"
    SeedAPI["/api/seed (route.js)"]:::internal
    click SeedAPI "https://github.com/dmdeepakmehta/spend/blob/main/app/api/seed/route.js"
  end

  %% ORM & Database
  PrismaClient["Prisma Client (lib/prisma.js)"]:::internal
  click PrismaClient "https://github.com/dmdeepakmehta/spend/blob/main/lib/prisma.js"

  subgraph "Prisma Schema"
    SchemaPrisma["schema.prisma"]:::internal
    click SchemaPrisma "https://github.com/dmdeepakmehta/spend/blob/main/prisma/schema.prisma"
    Migrations["prisma/migrations/"]:::internal
    click Migrations "https://github.com/dmdeepakmehta/spend/tree/main/prisma/migrations/"
  end

  %% Background Jobs
  subgraph "Inngest"
    InngestClient["Inngest Client"]:::internal
    click InngestClient "https://github.com/dmdeepakmehta/spend/blob/main/lib/inngest/client.js"
    InngestFunction["Inngest Function"]:::internal
    click InngestFunction "https://github.com/dmdeepakmehta/spend/blob/main/lib/inngest/function.js"
    ActionsAccount["actions/account.js"]:::internal
    click ActionsAccount "https://github.com/dmdeepakmehta/spend/blob/main/actions/account.js"
    ActionsBudget["actions/budget.js"]:::internal
    click ActionsBudget "https://github.com/dmdeepakmehta/spend/blob/main/actions/budget.js"
    ActionsDashboard["actions/dashboard.js"]:::internal
    click ActionsDashboard "https://github.com/dmdeepakmehta/spend/blob/main/actions/dashboard.js"
    ActionsTransaction["actions/transaction.js"]:::internal
    click ActionsTransaction "https://github.com/dmdeepakmehta/spend/blob/main/actions/transaction.js"
    ActionsSendEmail["actions/send-email.js"]:::internal
    click ActionsSendEmail "https://github.com/dmdeepakmehta/spend/blob/main/actions/send-email.js"
    ActionsSeed["actions/seed.js"]:::internal
    click ActionsSeed "https://github.com/dmdeepakmehta/spend/blob/main/actions/seed.js"
  end

  %% Data & Config
  DataSeeds["data/"]:::internal
  click DataSeeds "https://github.com/dmdeepakmehta/spend/tree/main/data/"
  ConfigNext["next.config.mjs"]:::internal
  click ConfigNext "https://github.com/dmdeepakmehta/spend/blob/main/next.config.mjs"
  TailwindCFG["tailwind.config.js"]:::internal
  click TailwindCFG "https://github.com/dmdeepakmehta/spend/blob/main/tailwind.config.js"
  PostCSSCFG["postcss.config.mjs"]:::internal
  click PostCSSCFG "https://github.com/dmdeepakmehta/spend/blob/main/postcss.config.mjs"
  ESLint[".eslintrc.json"]:::internal
  click ESLint "https://github.com/dmdeepakmehta/spend/blob/main/.eslintrc.json"
  JSConfig["jsconfig.json"]:::internal
  click JSConfig "https://github.com/dmdeepakmehta/spend/blob/main/jsconfig.json"

  %% External Flows
  Browser -->|navigates| AppDir
  Browser -->|loads CSS| GlobalsCSS
  Header -->|used in| AppDir
  Hero -->|used in| AppDir
  Drawer -->|used in| AppDir
  UIPrimitives -->|used in| AppDir

  AppDir -->|SSR/CSR| NJS
  NJS -->|invokes| InngestWebhook
  NJS -->|invokes| SeedAPI
  NJS -->|uses| Schema
  NJS -->|uses| Utils
  NJS -->|uses| CheckUser
  NJS -->|passes through| Middleware

  InngestWebhook -->|triggers| InngestClient
  InngestClient --> InngestFunction
  InngestFunction --> ActionsAccount
  InngestFunction --> ActionsBudget
  InngestFunction --> ActionsDashboard
  InngestFunction --> ActionsTransaction
  InngestFunction --> ActionsSendEmail
  InngestFunction --> ActionsSeed

  ActionsAccount --> PrismaClient
  ActionsBudget --> PrismaClient
  ActionsDashboard --> PrismaClient
  ActionsTransaction --> PrismaClient
  ActionsSendEmail --> PrismaClient
  ActionsSeed --> PrismaClient

  ActionsDashboard -->|embeddings| ArcJet
  ActionsTransaction -->|receipt parsing| ArcJet
  ActionsSendEmail -->|sends via| Resend

  NJS -->|DB queries| PrismaClient
  PrismaClient --> Postgres

  %% Class Definitions
  classDef frontend fill:#ADD8E6,stroke:#000;
  classDef internal fill:#90EE90,stroke:#000;
  classDef external fill:#FFA500,stroke:#000;
  classDef db fill:#DDDDDD,stroke:#000,stroke-width:2px;
```
