# urvashi73/expense-tracker-clean architecture

> Architecture diagram of the GitHub repository urvashi73/expense-tracker-clean, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-06-19). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/urvashi73/expense-tracker-clean
- Repository: https://github.com/urvashi73/expense-tracker-clean

## Overview

##### Project type and purpose
- This is a full-stack web application (“FinTrack”) built on Next.js.
- It provides users with transaction management (CRUD), AI-powered receipt scanning, budget tracking, dynamic charts, and automated email alerts/reports.

##### File structure
- Top-level directories:
- expense/app – Next.js “app” router with subfolders for (auth) and (main) routes
- expense/app/api – serverless functions (Inngest workflows, seed endpoints)
- expense/components – reusable UI components and primitives
- expense/lib – shared libraries (Prisma client, Inngest client, auth checks, utilities)
- expense/prisma – schema & migrations for database
- expense/emails – JSX email templates
- expense/actions – domain logic used by UI & API
- Config & build files: next.config.mjs, tsconfig/jsconfig, eslint, postcss, package.json
- Background job runner using Inngest (expense/app/api/inngest/route.js & expense/lib/inngest)

##### Insights from the README
- Tech stack: Next.js (React + server components), Prisma (ORM), Inngest (background tasks), AI receipt scanner, email notifications.
- Key features: transaction CRUD, charts (Pie/Bar), budget alerts, monthly reports.

##### Main components and their relationships
a. Frontend (Next.js “app” router)
- Renders pages under expense/app/(auth) & expense/app/(main)
- Uses React components (expense/components & expense/app/**/_components)
- Invokes client-side hooks (use-fetch) to call internal APIs
b. API Layer (Next.js serverless routes)
- expense/app/api/* – handles HTTP requests, calls actions and lib functions
- Inngest workflow endpoints handle background tasks (send-email, seed)
c. Business Logic (expense/actions & expense/lib)
- Encapsulates transaction, account, budget, dashboard data processing
- Shared by both API handlers and client actions
d. Database (PostgreSQL or MySQL via Prisma)
- Schema defined in expense/prisma/schema.prisma
- Accessed via expense/lib/prisma.js
e. Background Worker (Inngest)
- Orchestrates async tasks: budget-alert emails, monthly report emails, receipt OCR processing
- Invoked by scheduled events or API triggers
f. External Services
- Email provider (SMTP or transactional service)
- AI/OCR service for receipt scanning (could be a third-party API)

##### Architectural patterns and design principles
- Separation of concerns: clear split between UI, API, business logic, and data layers
- Serverless functions for on-demand and scheduled workloads (Inngest)
- Prisma ORM for type-safe, centralized data access
- React Server Components (Next.js app router) for SEO and performance
- Shared “actions” directory enabling DRY logic reuse between frontend and backend

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client Layer
    subgraph "Client" 
        Browser["Browser/Mobile Client"]:::frontend
    end

    %% Next.js Server
    subgraph "Next.js Server"
        subgraph "App Router (expense/app)" 
            AuthRoutes["Auth Routes\n(expense/app/(auth))"]:::frontend
            MainRoutes["Main Routes\n(expense/app/(main))"]:::frontend
            click AuthRoutes "https://github.com/urvashi73/expense-tracker-clean/tree/main/expense/app/(auth)"
            click MainRoutes "https://github.com/urvashi73/expense-tracker-clean/tree/main/expense/app/(main)"

            subgraph "Account Page" 
                Chart["Account Chart"]:::frontend
                Table["Transaction Table"]:::frontend
                click Chart "https://github.com/urvashi73/expense-tracker-clean/blob/main/expense/app/(main)/account/_components/account-chart.jsx"
                click Table "https://github.com/urvashi73/expense-tracker-clean/blob/main/expense/app/(main)/account/_components/transaction-table.jsx"
            end

            subgraph "Dashboard Page"
                ACard["Account Card"]:::frontend
                Progress["Budget Progress"]:::frontend
                Overview["Transaction Overview"]:::frontend
                DPage["Dashboard Page"]:::frontend
                click ACard "https://github.com/urvashi73/expense-tracker-clean/blob/main/expense/app/(main)/dashboard/_components/account-card.jsx"
                click Progress "https://github.com/urvashi73/expense-tracker-clean/blob/main/expense/app/(main)/dashboard/_components/budget-progress.jsx"
                click Overview "https://github.com/urvashi73/expense-tracker-clean/blob/main/expense/app/(main)/dashboard/_components/transaction-overview.jsx"
                click DPage "https://github.com/urvashi73/expense-tracker-clean/blob/main/expense/app/(main)/dashboard/page.jsx"
            end

            subgraph "Transaction Page"
                CreatePage["Create Transaction"]:::frontend
                Scanner["Receipt Scanner"]:::frontend
                Form["Transaction Form"]:::frontend
                click CreatePage "https://github.com/urvashi73/expense-tracker-clean/blob/main/expense/app/(main)/transaction/create/page.jsx"
                click Scanner "https://github.com/urvashi73/expense-tracker-clean/blob/main/expense/app/(main)/transaction/_components/receipt-scanner.jsx"
                click Form "https://github.com/urvashi73/expense-tracker-clean/blob/main/expense/app/(main)/transaction/_components/transaction-form.jsx"
            end
        end

        subgraph "Shared UI Components"
            UI["UI Components\n(expense/components)"]:::frontend
            click UI "https://github.com/urvashi73/expense-tracker-clean/tree/main/expense/components"
        end

        Hooks["use-fetch Hook\n(expense/hooks/use-fetch.jsx)"]:::frontend
        click Hooks "https://github.com/urvashi73/expense-tracker-clean/blob/main/expense/hooks/use-fetch.jsx"
    end

    %% API Layer
    subgraph "API Layer" 
        APILayer["Serverless Routes\n(expense/app/api)"]:::backend
        InngestRoute["Inngest Workflow Endpoint\n(route.js)"]:::worker
        SeedRoute["Seed Data Endpoint\n(route.js)"]:::backend
        click APILayer "https://github.com/urvashi73/expense-tracker-clean/tree/main/expense/app/api"
        click InngestRoute "https://github.com/urvashi73/expense-tracker-clean/blob/main/expense/app/api/inngest/route.js"
        click SeedRoute "https://github.com/urvashi73/expense-tracker-clean/blob/main/expense/app/api/seed/route.js"
    end

    %% Business Logic
    subgraph "Business Logic Layer"
        Actions["Actions\n(expense/actions/*.js)"]:::backend
        Lib["Shared Libraries\n(expense/lib/*.js)"]:::backend
        click Actions "https://github.com/urvashi73/expense-tracker-clean/tree/main/expense/actions"
        click Lib "https://github.com/urvashi73/expense-tracker-clean/tree/main/expense/lib"
    end

    %% Database
    Database["Database\n(PostgreSQL via Prisma)"]:::db
    click Database "https://github.com/urvashi73/expense-tracker-clean/blob/main/expense/prisma/schema.prisma"

    %% Inngest Worker
    subgraph "Inngest Worker"
        Worker["Inngest Worker"]:::worker
    end

    %% External Services
    ExternalAI["AI/OCR Service"]:::external
    ExternalEmail["Email Service"]:::external

    %% Connections
    Browser -->|"Page requests & API calls"| AuthRoutes
    Browser -->|"Page requests & API calls"| MainRoutes
    MainRoutes -->|"Renders UI using"| UI
    MainRoutes -->|"Calls hook"| Hooks
    Hooks -->|"Fetch API"| APILayer
    APILayer -->|"Invoke business logic"| Actions
    APILayer -->|"Use utilities"| Lib
    Actions -->|"DB queries via Prisma"| Database
    Lib -->|"DB access via prisma.js"| Database
    APILayer -->|"Trigger background job"| InngestRoute
    InngestRoute -->|"Enqueue task"| Worker
    Worker -->|"Uses business logic & lib"| Actions
    Worker -->|"DB read/write"| Database
    Worker -->|"Send emails"| ExternalEmail
    MainRoutes -->|"Send image"| ExternalAI
    APILayer -->|"Call AI service"| ExternalAI

    %% Styles
    classDef frontend fill:#E3F2FD,stroke:#2196F3,color:#0D47A1,stroke-width:2px;
    classDef backend fill:#E8F5E9,stroke:#4CAF50,color:#1B5E20,stroke-width:2px;
    classDef db fill:#FFF3E0,stroke:#FB8C00,color:#E65100,stroke-width:2px;
    classDef worker fill:#ECEFF1,stroke:#607D8B,color:#263238,stroke-width:2px;
    classDef external fill:#F3E5F5,stroke:#9C27B0,color:#4A148C,stroke-width:2px;
```
