# shivanshshuklaiiit/spendwise-ai architecture

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

- Interactive diagram: https://gitdiagram.com/shivanshshuklaiiit/spendwise-ai
- Repository: https://github.com/shivanshshuklaiiit/spendwise-ai

## Overview

Based on an analysis of the provided file tree and README, this project is clearly a full-stack Next.js application that follows the default structure provided by create-next-app. It includes not only the typical Next.js frontend (in the “app” directory with various routes and components) but also backend functionality (API routes under app/api, actions for business logic, and integration files like those for Inngest and Prisma for database access).

- Frontend/UI Layer:
- Represented by the “app” directory.
- Distinguish between the “(auth)” sub-group (for user sign-in/sign-up related pages) and the “(main)” sub-group (for account management, dashboard, and transaction flows).
- “components” directory which holds reusable UI elements (e.g., header, theme provider, and various UI widgets).
- Business Logic / Actions:
- The “actions” folder contains files for specific operations (accounts, dashboard, budget, transaction, sending emails, seeding data).
- This should be diagrammed as a service layer that communicates between the UI and backend processing.
- API Endpoints:
- The “app/api” directory contains endpoints (for Inngest events, seeding, etc.) that enable server-side integrations.
- Data Access/Database Layer:
- The “prisma” directory (with migrations, schema, etc.) and “lib/prisma.js” indicate usage of Prisma for interacting with the database.
- Utility Libraries & External Services:
- The “lib” folder also includes utils for checking user authentication and integration setups (Inngest, for example), highlighting the connection to external event systems and auxiliary services.
- Emailing:
- The “emails” folder containing templates indicates a dedicated component for handling outbound emails.
- Configuration & Environment:
- Files like next.config.mjs, tailwind.config.mjs, and postcss.config.mjs should be included as supportive configurations that drive how components render and interact.

##### Relationships and Data Flow
- How the UI (organized into “auth” and “main” routes) calls frontend actions or makes API calls.
- That user inputs and interactions on the client side trigger calls that go to the “actions” layer, which further may interact with the “API” endpoints.
- A bidirectional interaction between the API endpoints and the database (via Prisma).
- How external events (via Inngest integrated in both app/api/inngest and lib/inngest) interface with your application.

##### Architectural Patterns
- Layered and Modular Architecture: The separation between pages (UI), actions (business logic), API routes (backend endpoints), and database access (Prisma) reflects a clear separation of concerns.
- Next.js Routing & Server Components: Indicate that some parts of the project (especially in “app” with route groups) leverage Next.js’s server components and dynamic routing.
- Integration with Third-Party Services: Outline the integration with external systems like Inngest (for event handling) that are evident in the project structure.
- MVC-like Patterns: Even though Next.js abstracts many server features, the components directory and separation of pages versus logic components can be visualized similar to the Controller (actions/APIs), Model (Prisma schemas), and View (React components).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client Layer
    subgraph "Client Layer"
        UI["Frontend/UI Pages (app)"]:::frontend
        Auth["Authentication Module (app/(auth))"]:::frontend
        Main["Main Application Module (app/(main))"]:::frontend
        Reusable["Reusable UI Components (components)"]:::frontend
    end

    %% Service Layer
    subgraph "Service Layer"
        Actions["Business Logic / Actions (actions)"]:::service
        API["API Endpoints (app/api)"]:::service
    end

    %% Data Layer
    subgraph "Data Access / Database Layer"
        PrismaDir["Prisma Directory (prisma)"]:::database
        PrismaFile["Prisma Client File (lib/prisma.js)"]:::database
    end

    %% Integrations
    subgraph "Utility & External Integrations"
        Inngest["Inngest Integration (lib/inngest)"]:::integration
        CheckUser["Auth Check Utility (lib/checkUser.js)"]:::integration
        Utils["General Utils (lib/utils.js)"]:::integration
        Arcjet["Arcjet Utility (lib/arcjet.js)"]:::integration
        Email["Email Templates (emails)"]:::integration
    end

    %% Configuration
    subgraph "Configuration & Environment"
        NextConfig["Next Config (next.config.mjs)"]:::config
        TailwindConfig["Tailwind Config (tailwind.config.mjs)"]:::config
        PostCSS["PostCSS Config (postcss.config.mjs)"]:::config
    end

    %% Relationships: Client Layer to Service Layer
    Auth -->|"calls"| Actions
    Main -->|"calls"| Actions
    UI -->|"calls"| Actions

    %% Relationships: Service Layer interactions
    Actions -->|"invokes"| API
    Actions -->|"interacts"| PrismaDir
    Actions -->|"sends"| Email

    API -->|"queries"| PrismaDir
    API -->|"uses"| Utils
    API -->|"triggers"| Inngest

    %% Data Layer internal connection (optional grouping)
    PrismaDir -->|"contains"| PrismaFile

    %% Configuration influences all major layers (dotted arrows)
    NextConfig --- UI
    NextConfig --- Actions
    NextConfig --- API
    NextConfig --- PrismaDir
    NextConfig --- Inngest

    TailwindConfig --- UI
    TailwindConfig --- Actions
    TailwindConfig --- API

    PostCSS --- UI
    PostCSS --- Actions
    PostCSS --- API

    %% Styles
    classDef frontend fill:#cce5ff,stroke:#31708f,stroke-width:2px;
    classDef service fill:#d9edf7,stroke:#31708f,stroke-width:2px;
    classDef database fill:#fcf8e3,stroke:#8a6d3b,stroke-width:2px;
    classDef integration fill:#dff0d8,stroke:#3c763d,stroke-width:2px;
    classDef config fill:#f2dede,stroke:#a94442,stroke-width:2px;

    %% Click Events for Client Layer
    click UI "https://github.com/shivanshshuklaiiit/spendwise-ai/tree/master/app"
    click Auth "https://github.com/shivanshshuklaiiit/spendwise-ai/tree/master/app/(auth)"
    click Main "https://github.com/shivanshshuklaiiit/spendwise-ai/tree/master/app/(main)"
    click Reusable "https://github.com/shivanshshuklaiiit/spendwise-ai/tree/master/components"

    %% Click Events for Service Layer
    click Actions "https://github.com/shivanshshuklaiiit/spendwise-ai/tree/master/actions"
    click API "https://github.com/shivanshshuklaiiit/spendwise-ai/tree/master/app/api"

    %% Click Events for Data Access / Database Layer
    click PrismaDir "https://github.com/shivanshshuklaiiit/spendwise-ai/tree/master/prisma"
    click PrismaFile "https://github.com/shivanshshuklaiiit/spendwise-ai/blob/master/lib/prisma.js"

    %% Click Events for Integrations
    click Inngest "https://github.com/shivanshshuklaiiit/spendwise-ai/tree/master/lib/inngest"
    click CheckUser "https://github.com/shivanshshuklaiiit/spendwise-ai/blob/master/lib/checkUser.js"
    click Utils "https://github.com/shivanshshuklaiiit/spendwise-ai/blob/master/lib/utils.js"
    click Arcjet "https://github.com/shivanshshuklaiiit/spendwise-ai/blob/master/lib/arcjet.js"
    click Email "https://github.com/shivanshshuklaiiit/spendwise-ai/tree/master/emails"

    %% Click Events for Configuration
    click NextConfig "https://github.com/shivanshshuklaiiit/spendwise-ai/blob/master/next.config.mjs"
    click TailwindConfig "https://github.com/shivanshshuklaiiit/spendwise-ai/blob/master/tailwind.config.mjs"
    click PostCSS "https://github.com/shivanshshuklaiiit/spendwise-ai/blob/master/postcss.config.mjs"
```
