# biohazard786/billicious architecture

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

- Interactive diagram: https://gitdiagram.com/biohazard786/billicious
- Repository: https://github.com/biohazard786/billicious

## Overview

##### Main Components
- Frontend Client: This includes the Next.js “app” directory and the various React components in “components”. It is responsible for rendering UI pages such as group pages, bill forms, dashboards, and authentication screens.
- Backend API: Found under “app/api”, this set of APIs handles functionalities for bills, groups, invites, transactions, and users. These endpoints follow RESTful (or Next.js route-based) patterns.
- Authentication Module: Located in “app/auth” and “auth-utils”, this component includes pages for sign-in, sign-up, passkey registration, error handling, and middleware for secure routes.
- Database Layer: The “database” folder contains configuration and connection modules, integrating with Supabase. Also, schema definitions and Kafka utilities (for streaming, if applicable) can be represented here.
- State & Data Management: The “store” (for Zustand and its various slices), “providers”, and “lib” directories represent how application state and cross-component communication (via Tanstack Query and custom hooks) is managed.
- External Services: Include Supabase for the backend, real-time updates, and Hanko for authentication. Also, utility integrations like Kafka (if used beyond basic logging) and possibly Tailwind / Shadcn UI configurations are noted.

##### Relationships and Interactions
- The UI (Frontend React components) sends user actions to the Backend APIs via HTTP requests or fetch calls using Tanstack Query.
- API routes perform CRUD operations on the Supabase database and communicate with authentication systems.
- Real-time updates are pushed via Supabase Realtime to keep all connected clients informed about any changes (e.g., a new expense or group update).
- Global state is maintained using Zustand and provided across the component tree using various providers (e.g., NotificationStoreProvider, DashboardStoreProvider).
- Authentication and authorization are handled both on the client (via "app/auth" and "auth-utils") and on the server (middleware in “middleware.ts”) to secure endpoints.

##### Architectural Patterns & Design Principles
- Modular and Organized Structure: The project separate concerns into clearly defined directories (API, components, providers, store) which suggests a separation of concerns/MVC-like pattern.
- File-Based Routing: The “app” directory relies on Next.js file-based routing to organize pages and API endpoints.
- Declarative UI and State Management: Use of React with Zustand and Tanstack Query indicates a focus on reactive, data-driven UI updates.
- External Service Integration: Supabase and Hanko integration for real-time data updates and modern authentication reflects microservice integration.

##### Relevant Technologies
- Frontend: Next.js 14, React, Shadcn UI, Tailwind CSS, Framer Motion.
- Backend: Next.js API routes, Supabase for database & real-time, Kafka configuration.
- State Management: Zustand, Tanstack Query.
- Authentication: Passkey support using Hanko integrated via custom auth utilities.

## Diagram (Mermaid)

```mermaid
flowchart TD

    %% Frontend Client
    subgraph "Frontend Client"
        subgraph "Pages & Routing"
            F1A["Home Page (app/page.tsx)"] 
            F1B["Group Page (app/group/[slug]/page.tsx)"]
            F1C["Account Page (app/settings/account/page.tsx)"]
        end
        subgraph "UI Components"
            F2A["Dashboard (components/dashboard/dashboard.tsx)"]
            F2B["Sign-In (components/auth/sign-in.tsx)"]
        end
    end

    %% Backend API
    subgraph "Backend API"
        B1["Bills API (app/api/(bills))"]
        B2["Groups API (app/api/(groups))"]
        B3["Invites API (app/api/(invites))"]
        B4["Transactions API (app/api/(transactions))"]
        B5["Users API (app/api/(users))"]
    end

    %% Authentication Module
    subgraph "Authentication Module"
        subgraph "Auth Pages"
            A1["Sign In Page (app/auth/signin/page.tsx)"]
            A2["Sign Up Page (app/auth/signup/page.tsx)"]
        end
        subgraph "Auth Utilities"
            A3["Client Auth Utils (auth-utils/client.ts)"]
            A4["Middleware (auth-utils/middleware.ts)"]
            A5["Server Auth Utils (auth-utils/server.ts)"]
            A6["Utils (auth-utils/utils.ts)"]
        end
    end

    %% Database Layer
    subgraph "Database Layer"
        D1["DB Connect (database/dbConnect.ts)"]
        D2["Schema (database/schema.ts)"]
        D3["Kafka (database/kafka.ts)"]
    end

    %% State & Data Management
    subgraph "State & Data Management"
        subgraph "Zustand Stores"
            S1["Dashboard Store (store/dashboard-store.tsx)"]
            S2["Notification Store (store/notification-store.tsx)"]
        end
        subgraph "Providers"
            S3["Query Provider (providers/query-provider.tsx)"]
            S4["Dashboard Store Provider (providers/dashboard-store-provider.tsx)"]
            S5["Notification Store Provider (providers/notification-store-provider.tsx)"]
        end
    end

    %% External Services
    subgraph "External Services"
        E1["Supabase Database"]
        E2["Supabase Realtime"]
        E3["Hanko Authentication"]
    end

    %% Connections
    %% Frontend to Backend API
    F2A -->|"fetch"| B1
    F2A -->|"fetch"| B2
    F2A -->|"fetch"| B5
    F2B -->|"auth-request"| A1

    %% Backend API to Database Layer
    B1 -->|"CRUD"| D1
    B2 -->|"CRUD"| D1
    B3 -->|"CRUD"| D1
    B4 -->|"CRUD"| D1
    B5 -->|"CRUD"| D1

    %% Database Layer to External Realtime
    D1 -->|"push"| E2

    %% Authentication Module to External Service
    A1 -->|"passkey"| E3
    A2 -->|"passkey"| E3

    %% Frontend interacts with State Management
    F2A -->|"state"| S1
    F2A -->|"state"| S3
    F2B -->|"state"| S2

    %% Class Definitions for Color Coding
    classDef frontend fill:#bbf,stroke:#333,stroke-width:2px;
    classDef backend fill:#afa,stroke:#333,stroke-width:2px;
    classDef auth fill:#fbb,stroke:#333,stroke-width:2px;
    classDef database fill:#ffd,stroke:#333,stroke-width:2px;
    classDef state fill:#efe,stroke:#333,stroke-width:2px;
    classDef external fill:#fcc,stroke:#333,stroke-width:2px;

    %% Assign Classes
    class F1A,F1B,F1C,F2A,F2B frontend;
    class B1,B2,B3,B4,B5 backend;
    class A1,A2,A3,A4,A5,A6 auth;
    class D1,D2,D3 database;
    class S1,S2,S3,S4,S5 state;
    class E1,E2,E3 external;

    %% Click Events for Frontend Client
    click F1A "https://github.com/biohazard786/billicious/blob/main/app/page.tsx"
    click F1B "https://github.com/biohazard786/billicious/blob/main/app/group/[slug]/page.tsx"
    click F1C "https://github.com/biohazard786/billicious/blob/main/app/settings/account/page.tsx"
    click F2A "https://github.com/biohazard786/billicious/blob/main/components/dashboard/dashboard.tsx"
    click F2B "https://github.com/biohazard786/billicious/blob/main/components/auth/sign-in.tsx"

    %% Click Events for Backend API
    click B1 "https://github.com/biohazard786/billicious/tree/main/app/api/(bills)"
    click B2 "https://github.com/biohazard786/billicious/tree/main/app/api/(groups)"
    click B3 "https://github.com/biohazard786/billicious/tree/main/app/api/(invites)"
    click B4 "https://github.com/biohazard786/billicious/tree/main/app/api/(transactions)"
    click B5 "https://github.com/biohazard786/billicious/tree/main/app/api/(users)"

    %% Click Events for Authentication Module
    click A1 "https://github.com/biohazard786/billicious/blob/main/app/auth/signin/page.tsx"
    click A2 "https://github.com/biohazard786/billicious/blob/main/app/auth/signup/page.tsx"
    click A3 "https://github.com/biohazard786/billicious/blob/main/auth-utils/client.ts"
    click A4 "https://github.com/biohazard786/billicious/blob/main/auth-utils/middleware.ts"
    click A5 "https://github.com/biohazard786/billicious/blob/main/auth-utils/server.ts"
    click A6 "https://github.com/biohazard786/billicious/blob/main/auth-utils/utils.ts"

    %% Click Events for Database Layer
    click D1 "https://github.com/biohazard786/billicious/blob/main/database/dbConnect.ts"
    click D2 "https://github.com/biohazard786/billicious/blob/main/database/schema.ts"
    click D3 "https://github.com/biohazard786/billicious/blob/main/database/kafka.ts"

    %% Click Events for State & Data Management
    click S1 "https://github.com/biohazard786/billicious/blob/main/store/dashboard-store.tsx"
    click S2 "https://github.com/biohazard786/billicious/blob/main/store/notification-store.tsx"
    click S3 "https://github.com/biohazard786/billicious/blob/main/providers/query-provider.tsx"
    click S4 "https://github.com/biohazard786/billicious/blob/main/providers/dashboard-store-provider.tsx"
    click S5 "https://github.com/biohazard786/billicious/blob/main/providers/notification-store-provider.tsx"
```
