# sarveshchavhan/finance-app architecture

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

- Interactive diagram: https://gitdiagram.com/sarveshchavhan/finance-app
- Repository: https://github.com/sarveshchavhan/finance-app

## Overview

##### Project Type and Purpose
- This is a full-stack web application built with Next.js (App Router), TypeScript, Tailwind CSS, and Drizzle ORM.
- The app provides user authentication (sign-in/sign-up), a dashboard, and API endpoints for accounts, authors, and books.

##### File Structure Analysis
- **app/**
- UI routes and layouts (app/layout.tsx)
- Auth pages (app/(auth)/sign-in, sign-up)
- Dashboard pages and shared header (app/(dashboard))
- API routes under app/api/[[...route]] handling REST-style calls
- Global CSS (app/globals.css)
- Test page (app/test)
- **components/**
- Reusable UI components (header, navigation, buttons, dialogs)
- **db/**
- Drizzle ORM setup (db/drizzle.ts, db/schema.ts)
- SQL migrations under drizzle/ with metadata in drizzle/meta/
- **lib/**
- Utility functions (lib/utils.ts)
- Root configs: Next.js (next.config.ts), Tailwind (tailwind.config.ts), ESLint, TypeScript, PostCSS, package.json.
- **middleware.ts** for any custom Next.js edge logic.
- **script/migrate.ts** for running migrations.

##### Key Components
a. Client Browser (React UI)
b. Next.js Server (Node.js)
- App Router (server-side page rendering)
- Static asset serving (public/)
- API Route Handlers under app/api/…
- Middleware layer
c. Database (e.g., PostgreSQL)
- Drizzle ORM abstraction
- SQL migrations and snapshots
d. Developer Tools & CI/CD (optional)
- Vercel Deployment (implicit)
- Migrations script

##### Relationships and Data Flow
- Browser → Next.js Frontend
- Page requests (SSR/SSG) and static assets
- Frontend → API Routes
- Fetch calls to /api/accounts, /api/authors, /api/books
- API Routes → Drizzle ORM
- Queries and mutations against the database
- Drizzle ORM → Database
- SQL migrations applied via script/migrate.ts
- Middleware runs on inbound requests for auth/session checks

##### Architectural Patterns & Principles
- Separation of Concerns:
- Presentation (React components, pages)
- API layer (Next.js serverless functions)
- Data layer (Drizzle ORM + SQL)
- File-based routing for pages and API endpoints
- Single codebase for frontend and backend (monorepo style)

##### Essential Details to Capture
- File-based routing structure (app/(auth), app/(dashboard), app/api)
- Shared components layer (components/ui, components/navigation)
- Configuration boundary (next.config.ts, tailwind.config.ts)
- The role of middleware.ts between client requests and handlers
- The migration workflow (drizzle/ + script/migrate.ts)

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client Layer
    subgraph "Client Layer (Browser)" 
        direction TB
        Layout["Layout"]:::frontend
        Styles["Global CSS"]:::frontend
        SignIn["Sign-In Page"]:::frontend
        SignUp["Sign-Up Page"]:::frontend
        DashboardLayout["Dashboard Layout"]:::frontend
        DashboardPage["Dashboard Page"]:::frontend
        subgraph "Components"
            direction TB
            HeaderLogo["Header Logo"]:::frontend
            Navigation["Navigation"]:::frontend
            NavButton["Nav Button"]:::frontend
            WelcomeMsg["Welcome Message"]:::frontend
            ButtonUI["UI Button"]:::frontend
            DialogUI["UI Dialog"]:::frontend
            SheetUI["UI Sheet"]:::frontend
        end
    end

    %% Server Layer
    subgraph "Server Layer (Next.js)" 
        direction TB
        subgraph "App Router & Pages"
            direction TB
            ServerLayout["Layout"]:::server
            AuthPages["Auth Pages"]:::server
            DashboardPages["Dashboard Pages"]:::server
            TestPage["Test Page"]:::server
        end
        StaticAssets["Static Assets (public/)"]:::server
        Middleware["Middleware"]:::server
        subgraph "API Routes"
            direction TB
            APIRoute["Catch-All Route"]:::api
            AccountsAPI["Accounts API"]:::api
            AuthorsAPI["Authors API"]:::api
            BooksAPI["Books API"]:::api
        end
    end

    %% Data Layer
    subgraph "Data Layer (Database)" 
        direction TB
        subgraph "Drizzle ORM"
            direction TB
            DrizzleSetup["Drizzle Setup"]:::db
            Schema["Schema"]:::db
            Config["Drizzle Config"]:::db
        end
        subgraph "SQL Migrations"
            direction TB
            M0000["0000_lively_gabe_jones.sql"]:::docs
            M0001["0001_glorious_mathemanic.sql"]:::docs
            M0002["0002_parallel_hannibal_king.sql"]:::docs
            M0003["0003_polite_blackheart.sql"]:::docs
            M0004["0004_nervous_hardball.sql"]:::docs
            Snap0["meta/0000_snapshot.json"]:::docs
            Snap1["meta/0001_snapshot.json"]:::docs
            Snap2["meta/0002_snapshot.json"]:::docs
            Snap3["meta/0003_snapshot.json"]:::docs
            Snap4["meta/0004_snapshot.json"]:::docs
            Journal["meta/_journal.json"]:::docs
        end
        DB["PostgreSQL"]:::database
        MigrateScript["Migration Script"]:::docs
    end

    %% Utility & Config
    Util["Utility Functions"]:::docs
    subgraph "Config Files"
        nextcfg["next.config.ts"]:::docs
        tailwindcfg["tailwind.config.ts"]:::docs
        postcss["postcss.config.mjs"]:::docs
        eslintcfg["eslint.config.mjs"]:::docs
        tsconfig["tsconfig.json"]:::docs
        pkgjson["package.json"]:::docs
        lockjson["package-lock.json"]:::docs
        readme["README.md"]:::docs
        gitignore[".gitignore"]:::docs
    end

    %% Relationships
    Layout -->|"renders via"| ServerLayout
    SignIn -->|"renders via"| AuthPages
    SignUp -->|"renders via"| AuthPages
    DashboardPage -->|"renders via"| DashboardPages
    DashboardLayout -->|"renders via"| DashboardPages
    HeaderLogo --> Layout
    Navigation --> Layout
    NavButton --> Navigation
    WelcomeMsg --> DashboardPage
    ButtonUI -->|used in| AuthPages
    DialogUI -->|used in| AuthPages
    SheetUI -->|used in| AuthPages

    ServerLayout -->|"SSR/SSG"| Layout
    AuthPages -->|pages| SignIn
    AuthPages -->|pages| SignUp
    DashboardPages -->|pages| DashboardPage
    TestPage -->|page| TestPage

    Layout --> StaticAssets
    AuthPages --> StaticAssets
    DashboardPages --> StaticAssets

    Layout --> Middleware
    AuthPages --> Middleware
    DashboardPages --> Middleware
    TestPage --> Middleware

    Middleware --> APIRoute
    APIRoute --> AccountsAPI
    APIRoute --> AuthorsAPI
    APIRoute --> BooksAPI

    AccountsAPI -->|queries| DrizzleSetup
    AuthorsAPI -->|queries| DrizzleSetup
    BooksAPI -->|queries| DrizzleSetup

    DrizzleSetup --> Schema
    DrizzleSetup --> Config
    DrizzleSetup --> DB

    M0000 --> DB
    M0001 --> DB
    M0002 --> DB
    M0003 --> DB
    M0004 --> DB
    Snap0 --> DB
    Snap1 --> DB
    Snap2 --> DB
    Snap3 --> DB
    Snap4 --> DB
    Journal --> DB
    MigrateScript --> DB

    Util -->|used by| APIRoute
    Util -->|used by| Middleware

    nextcfg --> ServerLayout
    tailwindcfg --> Styles
    postcss --> Styles
    eslintcfg --> Util
    tsconfig --> Util
    pkgjson --> Util
    lockjson --> Util
    readme --> Util
    gitignore --> Util

    %% Click Events
    click Layout "https://github.com/sarveshchavhan/finance-app/blob/main/app/layout.tsx"
    click Styles "https://github.com/sarveshchavhan/finance-app/blob/main/app/globals.css"
    click SignIn "https://github.com/sarveshchavhan/finance-app/blob/main/app/(auth)/sign-in/[[...sign-in]]/page.tsx"
    click SignUp "https://github.com/sarveshchavhan/finance-app/blob/main/app/(auth)/sign-up/[[...sign-up]]/page.tsx"
    click DashboardLayout "https://github.com/sarveshchavhan/finance-app/blob/main/app/(dashboard)/layout.tsx"
    click DashboardPage "https://github.com/sarveshchavhan/finance-app/blob/main/app/(dashboard)/page.tsx"
    click HeaderLogo "https://github.com/sarveshchavhan/finance-app/blob/main/components/header-logo.tsx"
    click Navigation "https://github.com/sarveshchavhan/finance-app/blob/main/components/navigation.tsx"
    click NavButton "https://github.com/sarveshchavhan/finance-app/blob/main/components/nav-button.tsx"
    click WelcomeMsg "https://github.com/sarveshchavhan/finance-app/blob/main/components/welcome-msg.tsx"
    click ButtonUI "https://github.com/sarveshchavhan/finance-app/blob/main/components/ui/button.tsx"
    click DialogUI "https://github.com/sarveshchavhan/finance-app/blob/main/components/ui/dialog.tsx"
    click SheetUI "https://github.com/sarveshchavhan/finance-app/blob/main/components/ui/sheet.tsx"
    click ServerLayout "https://github.com/sarveshchavhan/finance-app/blob/main/app/layout.tsx"
    click AuthPages "https://github.com/sarveshchavhan/finance-app/tree/main/app/(auth)"
    click DashboardPages "https://github.com/sarveshchavhan/finance-app/tree/main/app/(dashboard)"
    click TestPage "https://github.com/sarveshchavhan/finance-app/blob/main/app/test/page.tsx"
    click StaticAssets "https://github.com/sarveshchavhan/finance-app/tree/main/public/"
    click Middleware "https://github.com/sarveshchavhan/finance-app/blob/main/middleware.ts"
    click APIRoute "https://github.com/sarveshchavhan/finance-app/blob/main/app/api/[[...route]]/route.ts"
    click AccountsAPI "https://github.com/sarveshchavhan/finance-app/blob/main/app/api/[[...route]]/accounts.ts"
    click AuthorsAPI "https://github.com/sarveshchavhan/finance-app/blob/main/app/api/[[...route]]/authors.ts"
    click BooksAPI "https://github.com/sarveshchavhan/finance-app/blob/main/app/api/[[...route]]/books.ts"
    click DrizzleSetup "https://github.com/sarveshchavhan/finance-app/blob/main/db/drizzle.ts"
    click Schema "https://github.com/sarveshchavhan/finance-app/blob/main/db/schema.ts"
    click Config "https://github.com/sarveshchavhan/finance-app/blob/main/drizzle.config.ts"
    click M0000 "https://github.com/sarveshchavhan/finance-app/blob/main/drizzle/0000_lively_gabe_jones.sql"
    click M0001 "https://github.com/sarveshchavhan/finance-app/blob/main/drizzle/0001_glorious_mathemanic.sql"
    click M0002 "https://github.com/sarveshchavhan/finance-app/blob/main/drizzle/0002_parallel_hannibal_king.sql"
    click M0003 "https://github.com/sarveshchavhan/finance-app/blob/main/drizzle/0003_polite_blackheart.sql"
    click M0004 "https://github.com/sarveshchavhan/finance-app/blob/main/drizzle/0004_nervous_hardball.sql"
    click Snap0 "https://github.com/sarveshchavhan/finance-app/blob/main/drizzle/meta/0000_snapshot.json"
    click Snap1 "https://github.com/sarveshchavhan/finance-app/blob/main/drizzle/meta/0001_snapshot.json"
    click Snap2 "https://github.com/sarveshchavhan/finance-app/blob/main/drizzle/meta/0002_snapshot.json"
    click Snap3 "https://github.com/sarveshchavhan/finance-app/blob/main/drizzle/meta/0003_snapshot.json"
    click Snap4 "https://github.com/sarveshchavhan/finance-app/blob/main/drizzle/meta/0004_snapshot.json"
    click Journal "https://github.com/sarveshchavhan/finance-app/blob/main/drizzle/meta/_journal.json"
    click MigrateScript "https://github.com/sarveshchavhan/finance-app/blob/main/script/migrate.ts"
    click Util "https://github.com/sarveshchavhan/finance-app/blob/main/lib/utils.ts"
    click nextcfg "https://github.com/sarveshchavhan/finance-app/blob/main/next.config.ts"
    click tailwindcfg "https://github.com/sarveshchavhan/finance-app/blob/main/tailwind.config.ts"
    click postcss "https://github.com/sarveshchavhan/finance-app/blob/main/postcss.config.mjs"
    click eslintcfg "https://github.com/sarveshchavhan/finance-app/blob/main/eslint.config.mjs"
    click tsconfig "https://github.com/sarveshchavhan/finance-app/blob/main/tsconfig.json"
    click pkgjson "https://github.com/sarveshchavhan/finance-app/blob/main/package.json"
    click lockjson "https://github.com/sarveshchavhan/finance-app/blob/main/package-lock.json"
    click readme "https://github.com/sarveshchavhan/finance-app/blob/main/README.md"
    click gitignore "https://github.com/sarveshchavhan/finance-app/blob/main/.gitignore"

    %% Styles
    classDef frontend fill:#cce5ff,stroke:#004085,color:#004085
    classDef server fill:#d4edda,stroke:#155724,color:#155724
    classDef api fill:#fff3cd,stroke:#856404,color:#856404
    classDef db fill:#ffe5b4,stroke:#b35f00,color:#b35f00
    classDef database fill:#f8d7da,stroke:#721c24,color:#721c24
    classDef docs fill:#e2e3e5,stroke:#6c757d,color:#6c757d
```
