# piyush-eon/ai-finance-platform architecture

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

- Interactive diagram: https://gitdiagram.com/piyush-eon/ai-finance-platform
- Repository: https://github.com/piyush-eon/ai-finance-platform

## Overview

##### Main System Components

a) Frontend Layer:
- Next.js Application (app directory structure)
- Authentication Layer (Clerk integration)
- Main Application Features:
- Dashboard
- Account Management
- Transaction Management
- Budget Tracking

b) Backend Services:
- API Routes (/app/api)
- Background Processing (Inngest)
- Security Layer (ArcJet)
- Email Service (Resend)
- AI Integration (Gemini API)

c) Database Layer:
- Supabase Database
- Prisma ORM Layer

##### Component Relationships

a) Client-Side Flow:
- Authentication flow through Clerk
- Protected routes under (main) directory
- Public routes under (auth) directory

b) Data Flow:
- API routes handling data operations
- Prisma interactions with the database
- Background job processing through Inngest
- Email notifications via Resend

##### Specific Implementation Details

Architectural patterns:

a) Next.js App Router Structure:
- Routes by (auth) and (main)
- API routes separation
- Server and client components

b) Feature Modules:
- Account management
- Transaction processing
- Budget tracking
- Dashboard analytics

##### Key Technical Elements to Highlight

- Prisma Schema and Migrations
- Authentication flow with Clerk
- Background job processing with Inngest
- Email templating system
- AI integration points
- Security middleware

**[Client Layer]**
- ↓
**[Authentication/Security Layer]**
- ↓
**[Application Layer]**
- ↓
**[Service Layer]**
- ↓
**[Database Layer]**

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph Client
        Browser["Web Browser"]
    end

    subgraph AuthLayer["Authentication Layer"]
        Clerk["Clerk Auth"]
        AuthLayout["Auth Layout"]:::auth
        click AuthLayout "https://github.com/piyush-eon/ai-finance-platform/blob/main/app/(auth)/layout.js"
    end

    subgraph MainApp["Main Application"]
        MainLayout["Main Layout"]:::main
        click MainLayout "https://github.com/piyush-eon/ai-finance-platform/blob/main/app/(main)/layout.js"

        subgraph Features["Core Features"]
            Dashboard["Dashboard"]:::feature
            click Dashboard "https://github.com/piyush-eon/ai-finance-platform/tree/main/app/(main)/dashboard"
            Account["Account Management"]:::feature
            click Account "https://github.com/piyush-eon/ai-finance-platform/tree/main/app/(main)/account"
            Transaction["Transaction Management"]:::feature
            click Transaction "https://github.com/piyush-eon/ai-finance-platform/tree/main/app/(main)/transaction"
            BudgetTrack["Budget Tracking"]:::feature
            click BudgetTrack "https://github.com/piyush-eon/ai-finance-platform/blob/main/app/(main)/dashboard/_components/budget-progress.jsx"
            ReceiptScanner["Receipt Scanner"]:::feature
            click ReceiptScanner "https://github.com/piyush-eon/ai-finance-platform/blob/main/app/(main)/transaction/_components/recipt-scanner.jsx"
        end

        subgraph Actions["Core Actions"]
            AccountActions["Account Actions"]:::action
            click AccountActions "https://github.com/piyush-eon/ai-finance-platform/blob/main/actions/account.js"
            TransactionActions["Transaction Actions"]:::action
            click TransactionActions "https://github.com/piyush-eon/ai-finance-platform/blob/main/actions/transaction.js"
            BudgetActions["Budget Actions"]:::action
            click BudgetActions "https://github.com/piyush-eon/ai-finance-platform/blob/main/actions/budget.js"
            DashboardActions["Dashboard Actions"]:::action
            click DashboardActions "https://github.com/piyush-eon/ai-finance-platform/blob/main/actions/dashboard.js"
        end
    end

    subgraph BackendServices["Backend Services"]
        APIRoutes["API Routes"]:::api
        click APIRoutes "https://github.com/piyush-eon/ai-finance-platform/tree/main/app/api"
        Inngest["Background Processing"]:::service
        click Inngest "https://github.com/piyush-eon/ai-finance-platform/blob/main/app/api/inngest/route.js"
        ArcJet["Security Layer"]:::security
        click ArcJet "https://github.com/piyush-eon/ai-finance-platform/blob/main/lib/arcjet.js"
        EmailService["Email Service"]:::service
        click EmailService "https://github.com/piyush-eon/ai-finance-platform/blob/main/actions/send-email.js"
        GeminiAI["AI Integration"]:::service
    end

    subgraph DataLayer["Data Layer"]
        PrismaORM["Prisma ORM"]:::database
        click PrismaORM "https://github.com/piyush-eon/ai-finance-platform/blob/main/lib/prisma.js"
        Schema["Database Schema"]:::database
        click Schema "https://github.com/piyush-eon/ai-finance-platform/blob/main/prisma/schema.prisma"
        Migrations["Migrations"]:::database
        click Migrations "https://github.com/piyush-eon/ai-finance-platform/tree/main/prisma/migrations"
        SupabaseDB[(Supabase Database)]:::database
    end

    Browser --> Clerk
    Clerk --> AuthLayout
    Clerk --> MainLayout

    MainLayout --> Features
    Features --> Actions
    Actions --> APIRoutes
    APIRoutes --> BackendServices
    BackendServices --> PrismaORM
    PrismaORM --> SupabaseDB
    Schema --> PrismaORM
    Migrations --> SupabaseDB

    ReceiptScanner --> GeminiAI
    Actions --> EmailService
    Actions --> Inngest
    APIRoutes --> ArcJet

    classDef main fill:#2563eb,color:white
    classDef auth fill:#4f46e5,color:white
    classDef feature fill:#0891b2,color:white
    classDef action fill:#059669,color:white
    classDef api fill:#ca8a04,color:white
    classDef service fill:#c026d3,color:white
    classDef security fill:#dc2626,color:white
    classDef database fill:#475569,color:white
```
