# vlsk3104/finance-app architecture

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

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

## Overview

##### Main Components
- Frontend (Presentation Layer):
- Next.js “app” Directory: Contains route-based pages, including authentication (sign-in, sign-up) and dashboard areas.
- UI Components: In the “components” folder (including UI subcomponents) and in “features/*/components” for domain-specific presentations.
- Providers: “providers/query-provider.tsx” and “providers/sheet-provider.tsx” to manage state, queries, or UI overlays.
- Business/Feature Layers:
- “features” Directory: Includes separate sets for accounts, categories, transactions, and summary. Each has its own API functions, hooks, and components tailored to their domain.
- Custom Hooks and Util Libraries: “hooks” and “lib” directories support business logic and utilities.
- Backend/API Layer:
- API Routes: Located under “app/api”, which manage CRUD operations for the domains (accounts, categories, transactions, summary).
- Middleware: “middleware.ts” may handle cross-cutting concerns like authentication or logging.
- Database/Data Layer:
- Database Config and Schema: “db” directory includes the Drizzle ORM configuration (drizzle.ts), migrations (SQL files and snapshots), and schema definitions.
- Migration Scripts: In the “scripts” folder, e.g., migration and seeding logic.

##### Relationships and Interactions
- Users interact with the system via the Frontend pages (auth and dashboard) which are rendered by Next.js.
- UI Components utilize React hooks and providers to manage state and data fetching.
- When actions (like creating or editing an account, transaction, or category) occur on the frontend, the appropriate API routes under “app/api” are called.
- The API layer communicates with the database using the Drizzle configuration in “db”, ensuring that data is queried or mutated as necessary.
- Domain-specific logic is encapsulated in the “features” directories, which include reusable API hooks that abstract the API calls for data manipulation.

##### Architectural Patterns and Design Principles
- Next.js App Directory Routing: Emphasize the built-in routing and server-side rendering (or Next.js edge functions) that manage both pages and API endpoints.
- Feature-Based Modularity: Each feature (accounts, categories, transactions, summary) has its own isolated modules (components, hooks, APIs) to promote scalability and separation of concerns.
- Component Reusability: The “components” folder offers reusable UI pieces that likely follow a design system (evidenced by the “components/ui” subdirectory).

##### Specify the Relevant Technologies, Frameworks, and Libraries
- Next.js for full-stack React rendering and routing.
- TypeScript (as indicated by the .tsx and .ts files) providing type safety.
- Drizzle ORM for database interactions along with SQL migrations.
- Tailwind CSS for styling (as per the tailwind.config.ts file).
- Various UI libraries/components customized in the “components/ui” folder.

##### Elements
- From User → Frontend Pages (Next.js routes).
- From Frontend → API Endpoints (through feature hooks or direct API calls).
- From API Endpoints → Database (using Drizzle ORM).
- From database responses back up the chain.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Top-level User
    User["User"]:::util

    %% Frontend (Presentation Layer)
    subgraph "Frontend (Presentation Layer)"
        Auth["Authentication: Pages"]:::presentation
        SignIn["Sign In Page"]:::presentation
        SignUp["Sign Up Page"]:::presentation
        Dash["Dashboard Pages"]:::presentation
        Auth --> SignIn
        Auth --> SignUp
    end

    %% Providers
    subgraph "Providers"
        ProviderQuery["Query Provider"]:::providers
        ProviderSheet["Sheet Provider"]:::providers
    end

    %% UI Components
    subgraph "UI Components"
        GlobalUI["Global UI Components"]:::presentation
        UILib["UI Library Components"]:::presentation
        FeatureUI["Feature-specific UI Components"]:::presentation
    end

    %% Business Logic / Features
    subgraph "Business Logic / Features"
        AccountsFeature["Accounts Feature"]:::feature
        CategoriesFeature["Categories Feature"]:::feature
        TransactionsFeature["Transactions Feature"]:::feature
        SummaryFeature["Summary Feature"]:::feature
        CustomHooks["Custom Hooks"]:::util
        UtilityLib["Utility Libraries"]:::util
    end

    %% Backend/API Layer
    subgraph "Backend/API Layer"
        APIAccounts["API: Accounts"]:::api
        APICategories["API: Categories"]:::api
        APITransactions["API: Transactions"]:::api
        APISummary["API: Summary"]:::api
        Middleware["Middleware"]:::api
    end

    %% Database/Data Layer
    subgraph "Database/Data Layer"
        DrizzleSchema["Drizzle ORM & Schema"]:::database
        Migrations["Migrations"]:::database
        MigrationScripts["Migration & Seeding Scripts"]:::database
    end

    %% Connections - from User to Frontend
    User --> SignIn
    User --> SignUp
    User --> Dash

    %% From Frontend to Providers
    Dash --> ProviderQuery
    Dash --> ProviderSheet

    %% From Providers to UI Components
    ProviderQuery --> GlobalUI
    ProviderQuery --> FeatureUI
    ProviderSheet --> GlobalUI
    ProviderSheet --> FeatureUI

    %% From UI Components to Business Logic / Features
    FeatureUI --> AccountsFeature
    FeatureUI --> CategoriesFeature
    FeatureUI --> TransactionsFeature
    FeatureUI --> SummaryFeature
    FeatureUI --> CustomHooks
    FeatureUI --> UtilityLib

    %% From Business Logic / Features to Backend/API Layer
    AccountsFeature --> APIAccounts
    CategoriesFeature --> APICategories
    TransactionsFeature --> APITransactions
    SummaryFeature --> APISummary

    %% From Backend/API Layer to Database/Data Layer
    APIAccounts --> DrizzleSchema
    APICategories --> DrizzleSchema
    APITransactions --> DrizzleSchema
    APISummary --> DrizzleSchema
    Middleware --> DrizzleSchema

    %% Within Database Layer
    DrizzleSchema --> Migrations
    Migrations --> MigrationScripts

    %% Click Events
    click SignIn "https://github.com/vlsk3104/finance-app/blob/main/app/(auth)/sign-in/[[...sign-in]]/page.tsx"
    click SignUp "https://github.com/vlsk3104/finance-app/blob/main/app/(auth)/sign-up/[[...sign-up]]/page.tsx"
    click Dash "https://github.com/vlsk3104/finance-app/tree/main/app/(dashboard)"
    click GlobalUI "https://github.com/vlsk3104/finance-app/tree/main/components/"
    click UILib "https://github.com/vlsk3104/finance-app/tree/main/components/ui/"
    click FeatureUI "https://github.com/vlsk3104/finance-app/tree/main/features/accounts/components"
    click ProviderQuery "https://github.com/vlsk3104/finance-app/blob/main/providers/query-provider.tsx"
    click ProviderSheet "https://github.com/vlsk3104/finance-app/blob/main/providers/sheet-provider.tsx"
    click AccountsFeature "https://github.com/vlsk3104/finance-app/tree/main/features/accounts"
    click CategoriesFeature "https://github.com/vlsk3104/finance-app/tree/main/features/categories"
    click TransactionsFeature "https://github.com/vlsk3104/finance-app/tree/main/features/transactions"
    click SummaryFeature "https://github.com/vlsk3104/finance-app/tree/main/features/summary"
    click CustomHooks "https://github.com/vlsk3104/finance-app/blob/main/hooks/use-confirm.tsx"
    click UtilityLib "https://github.com/vlsk3104/finance-app/blob/main/lib/hono.ts"
    click APIAccounts "https://github.com/vlsk3104/finance-app/blob/main/app/api/[[...route]]/accounts.ts"
    click APICategories "https://github.com/vlsk3104/finance-app/blob/main/app/api/[[...route]]/categories.ts"
    click APITransactions "https://github.com/vlsk3104/finance-app/blob/main/app/api/[[...route]]/transactions.ts"
    click APISummary "https://github.com/vlsk3104/finance-app/blob/main/app/api/[[...route]]/summary.ts"
    click Middleware "https://github.com/vlsk3104/finance-app/blob/main/middleware.ts"
    click DrizzleSchema "https://github.com/vlsk3104/finance-app/blob/main/db/drizzle.ts"
    click Migrations "https://github.com/vlsk3104/finance-app/tree/main/db/migrations/"
    click MigrationScripts "https://github.com/vlsk3104/finance-app/blob/main/scripts/migrate.ts"

    %% Styles
    classDef presentation fill:#ffcccc,stroke:#333,stroke-width:2px;
    classDef providers fill:#ccffcc,stroke:#333,stroke-width:2px;
    classDef feature fill:#ccccff,stroke:#333,stroke-width:2px;
    classDef util fill:#ffffcc,stroke:#333,stroke-width:2px;
    classDef api fill:#ccffff,stroke:#333,stroke-width:2px;
    classDef database fill:#ffccff,stroke:#333,stroke-width:2px;
```
