# atharvm2504/fairsplit architecture

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

- Interactive diagram: https://gitdiagram.com/atharvm2504/fairsplit
- Repository: https://github.com/atharvm2504/fairsplit

## Overview

##### Project type and purpose
- This is a full-stack web application built with Next.js (React) that replicates Splitwise functionality: group expense tracking, balances, reimbursements, receipt scanning, and optional AI-powered expense categorization.
- It targets both end users (browser/PWA) and operators (self-hosting via Docker or Vercel).

##### File structure
- Top-level:
- src/app – Next.js 13 “App Router” pages, layouts, API routes
- src/components & src/components/ui – shared React components / design system
- src/trpc – tRPC client & server routers for typed RPC endpoints
- prisma – database schema and migrations (PostgreSQL via Prisma ORM)
- public – static assets (logo)
- scripts & Dockerfiles – local-dev, container build, DB startup
- .github/workflows – CI/CD pipelines
- Key configuration:
- next.config.mjs, tailwind.config.js, postcss.config.js – build & styling
- .env.example, container.env.example – runtime feature flags (S3, OpenAI)
- Dockerfile & compose.yaml – container orchestration

##### README for additional insights
- Stack: Next.js + Tailwind + shadcn/UI, Prisma + PostgreSQL, Vercel hosting.
- Features: health checks (/api/health), optional S3 upload (/api/s3-upload), OpenAI GPT-4 integration.
- Deployment modes: local dev, Docker container, Vercel serverless.
- CI/CD: GitHub Actions (ci.yml, cd.yml) build, test, deploy.

a. Main components
- Client: Browser / PWA
- Next.js application (Pages + API routes + tRPC server)
- React component library (shadcn/UI)
- Database: PostgreSQL (hosted via Vercel or local Docker)
- Storage: AWS S3 (or S3-compatible endpoint) for expense documents
- External AI: OpenAI GPT-4 Vision for receipt extraction / category inference
- CI/CD & Hosting: GitHub Actions, Docker, Vercel
b. Relationships & interactions
- Browser → Next.js pages (SSR/CSR) & tRPC client
- Next.js → tRPC routers → Prisma Client → PostgreSQL
- Next.js API route /api/s3-upload → S3 SDK → S3 bucket
- Next.js server → OpenAI API when feature flag enabled
- GitHub → CI pipeline → Docker image → Vercel deployment
c. Architectural patterns
- Monorepo single-codebase full-stack (Next.js App Router)
- RPC pattern (tRPC) for type-safe client-server comms
- ORM layer (Prisma) for DB abstraction & migrations
- Feature flags via environment variables
- Progressive Web App support (manifest, splash, offline)
d. Key technologies / frameworks
- Next.js 13 (App Router, server components)
- React + shadcn/UI + TailwindCSS
- tRPC for backend APIs
- Prisma + PostgreSQL
- AWS S3 or compatible for file storage
- OpenAI GPT-4 Vision
- Docker & GitHub Actions for CI/CD
- Vercel for hosting

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Presentation Layer
    subgraph "Presentation Layer"
        direction TB
        Browser["Browser / PWA"]:::frontend
        AppRouter["Next.js App Router (Pages & Layouts)"]:::frontend
        SharedComponents["Shared React Components"]:::frontend
        PWAManifest["PWA Manifest & Splash"]:::frontend
        StaticAssets["Static Assets (logo)"]:::frontend
    end

    %% API Layer
    subgraph "API Layer"
        direction TB
        NextServer["Next.js Server (API Routes & Server Components)"]:::internal
        HealthAPI["/api/health"]:::internal
        S3UploadAPI["/api/s3-upload"]:::internal
        TRPCRoute["/api/trpc/[trpc]"]:::internal
        TRPCClient["tRPC Client Setup"]:::internal
        TRPCRouters["tRPC Routers"]:::internal
        Utils["Utility Libraries"]:::internal
        FeatureFlags["Feature Flags Config"]:::internal
    end

    %% Data Layer
    subgraph "Data Layer"
        direction TB
        PrismaSchema["Prisma Schema & Migrations"]:::datastore
        PrismaClient["Prisma Client Initialization"]:::internal
        Postgres["PostgreSQL Database"]:::datastore
    end

    %% External Services
    subgraph "External Services"
        direction TB
        S3["AWS S3 Storage"]:::external
        OpenAI["OpenAI GPT-4 Vision API"]:::external
    end

    %% Deployment & CI/CD
    subgraph "Deployment & CI/CD"
        direction TB
        GitHub["GitHub Actions CI/CD"]:::infra
        Docker["Docker & Compose"]:::infra
        Vercel["Vercel Hosting"]:::infra
        Config["Configuration Files"]:::infra
        I18n["Internationalization Messages"]:::infra
        Tests["Test Config"]:::infra
    end

    %% Connections
    Browser -->|"HTTP/SSR/CSR"| AppRouter
    Browser -->|"Imports"| SharedComponents
    Browser -->|"Manifest/Splash"| PWAManifest
    Browser -->|"Static Files"| StaticAssets

    AppRouter -->|"tRPC Requests"| TRPCClient
    AppRouter -->|"API Calls"| NextServer

    TRPCClient -->|"RPC over HTTP"| TRPCRoute
    TRPCRoute -->|"Invoke Procedures"| TRPCRouters
    TRPCRouters -->|"Prisma Client"| PrismaClient
    PrismaClient -->|"SQL Queries"| Postgres

    NextServer -->|"Health Check"| HealthAPI
    NextServer -->|"S3 SDK"| S3UploadAPI
    NextServer -->|"Feature-flagged SDK"| OpenAI
    NextServer -->|"Utils & API Wrappers"| Utils
    NextServer -->|"Feature Flags"| FeatureFlags

    S3UploadAPI -->|"Uploads"| S3
    OpenAI -->|"Extract/Categorize"| NextServer

    GitHub -->|"Run Pipelines"| Docker
    Docker -->|"Build & Run"| AppRouter
    Docker -->|"Connect"| Postgres
    Docker -->|"Env Files"| Config

    GitHub -->|"Deploy"| Vercel
    Config -->|"next.config.js & .env"| AppRouter
    I18n -->|"messages/*.json"| AppRouter
    Tests -->|"jest.config.ts"| AppRouter

    %% Click Events
    click AppRouter "https://github.com/atharvm2504/fairsplit/tree/main/src/app"
    click HealthAPI "https://github.com/atharvm2504/fairsplit/tree/main/src/app/api/health"
    click S3UploadAPI "https://github.com/atharvm2504/fairsplit/blob/main/src/app/api/s3-upload/route.ts"
    click TRPCRoute "https://github.com/atharvm2504/fairsplit/blob/main/src/app/api/trpc/[trpc]/route.ts"
    click TRPCClient "https://github.com/atharvm2504/fairsplit/blob/main/src/trpc/client.tsx"
    click TRPCClient "https://github.com/atharvm2504/fairsplit/blob/main/src/trpc/query-client.ts"
    click TRPCRouters "https://github.com/atharvm2504/fairsplit/tree/main/src/trpc/routers"
    click PrismaSchema "https://github.com/atharvm2504/fairsplit/blob/main/prisma/schema.prisma"
    click PrismaSchema "https://github.com/atharvm2504/fairsplit/tree/main/prisma/migrations"
    click PrismaClient "https://github.com/atharvm2504/fairsplit/blob/main/src/lib/prisma.ts"
    click FeatureFlags "https://github.com/atharvm2504/fairsplit/blob/main/src/lib/featureFlags.ts"
    click FeatureFlags "https://github.com/atharvm2504/fairsplit/blob/main/container.env.example"
    click SharedComponents "https://github.com/atharvm2504/fairsplit/tree/main/src/components"
    click SharedComponents "https://github.com/atharvm2504/fairsplit/tree/main/src/components/ui"
    click Utils "https://github.com/atharvm2504/fairsplit/blob/main/src/lib/api.ts"
    click Utils "https://github.com/atharvm2504/fairsplit/blob/main/src/lib/health.ts"
    click Utils "https://github.com/atharvm2504/fairsplit/blob/main/src/lib/utils.ts"
    click PWAManifest "https://github.com/atharvm2504/fairsplit/blob/main/src/app/manifest.ts"
    click PWAManifest "https://github.com/atharvm2504/fairsplit/blob/main/src/app/apple-pwa-splash.tsx"
    click StaticAssets "https://github.com/atharvm2504/fairsplit/tree/main/public/logo"
    click Config "https://github.com/atharvm2504/fairsplit/blob/main/next.config.mjs"
    click Config "https://github.com/atharvm2504/fairsplit/blob/main/.env.example"
    click Docker "https://github.com/atharvm2504/fairsplit/tree/main/Dockerfile"
    click Docker "https://github.com/atharvm2504/fairsplit/blob/main/compose.yaml"
    click Docker "https://github.com/atharvm2504/fairsplit/blob/main/scripts/build-image.sh"
    click Docker "https://github.com/atharvm2504/fairsplit/blob/main/scripts/container-entrypoint.sh"
    click Docker "https://github.com/atharvm2504/fairsplit/blob/main/.devcontainer/docker-compose.yml"
    click GitHub "https://github.com/atharvm2504/fairsplit/blob/main/.github/workflows/ci.yml"
    click GitHub "https://github.com/atharvm2504/fairsplit/blob/main/.github/workflows/cd.yml"
    click I18n "https://github.com/atharvm2504/fairsplit/tree/main/messages"
    click Tests "https://github.com/atharvm2504/fairsplit/blob/main/jest.config.ts"

    %% Styles
    classDef frontend fill:#D0E7FF,stroke:#0366D6,color:#0366D6
    classDef internal fill:#DFFFE0,stroke:#228B22,color:#228B22
    classDef datastore fill:#FFF4D0,stroke:#D2691E,color:#D2691E
    classDef external fill:#F0D0FF,stroke:#800080,color:#800080
    classDef infra fill:#E0E0E0,stroke:#505050,color:#505050
```
