# faizananwar2801/fab-pay architecture

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

- Interactive diagram: https://gitdiagram.com/faizananwar2801/fab-pay
- Repository: https://github.com/faizananwar2801/fab-pay

## Overview

##### Project type and purpose
- This is a full-stack monorepo managed by Turborepo.
- It contains two Next.js frontends—`merchant-app` (merchant-facing portal) and `user-app` (end-user dashboard)—plus a backend webhook service (`bank-webhook`) and shared packages for UI components, state management, database models, and configuration.
- The project’s goal is to power a financial platform: users can transfer money, merchants can receive payments, and the system processes bank webhooks and persists transactions in a database.

##### File structure
- Top-level folders
- `apps/merchant-app`: Next.js app with NextAuth for authentication, API routes under `/app/api`, and React components under `/app` and `/components`.
- `apps/user-app`: Next.js app structured with a `(dashboard)` route group, API routes for auth and user data, and feature pages for transfers, transactions, etc.
- `apps/bank-webhook`: a small Node/TypeScript HTTP service (`src/index.ts`) that receives bank webhooks and writes events to the database.
- Shared packages
- `packages/db`: Prisma schema, migrations, seed script, and database client wrapper.
- `packages/store`: React state atoms/hooks for client-side state (e.g., balance).
- `packages/ui`: shared React component library (buttons, cards, inputs).
- `packages/eslint-config` & `packages/typescript-config`: linting and TypeScript base configs.
- Tooling & CI
- `.github/workflows`: build and deploy pipelines.
- `docker/Dockerfile.user`: containerization instructions for the user app.

##### Key architecture insights from README
- Uses Turborepo for task orchestration and caching.
- Leverages TypeScript across all layers.
- NextAuth for authentication.
- Prisma ORM for database access and migrations.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client UIs
    subgraph "Client UIs"
        MerchantApp["Merchant App<br/>Next.js 14"]:::frontend
        UserApp["User App<br/>Next.js 14"]:::frontend
    end

    %% Backend Services
    subgraph "Backend Services"
        BankWebhookService["Bank Webhook Service<br/>Node.js TypeScript"]:::backend
    end

    %% Libraries
    subgraph "Shared Libraries"
        UIlib["UI Library"]:::library
        StorePkg["Store Package"]:::library
        DBpkg["DB Package"]:::library
        ESLintCfg["ESLint Config"]:::config
        TSCfg["TypeScript Config"]:::config
    end

    %% External Services
    subgraph "External Services"
        NextAuth["Auth Service<br/>(NextAuth)"]:::external
        PaymentGateway["Payment Gateway / Bank API"]:::external
    end

    %% Data Layer
    subgraph "Data"
        PrismaDB["Prisma DB<br/>PostgreSQL"]:::database
    end

    %% Tooling & CI
    subgraph "Tooling & CI"
        CI["CI/CD (GitHub Actions)"]:::tool
        Turbo["Turborepo"]:::tool
        Docker["Docker Containerization<br/>Dockerfile.user"]:::tool
    end

    %% Relationships
    MerchantApp -->|imports at build| UIlib
    MerchantApp -->|imports at build| StorePkg
    MerchantApp -->|imports at build| DBpkg
    UserApp -->|imports at build| UIlib
    UserApp -->|imports at build| StorePkg
    UserApp -->|imports at build| DBpkg

    MerchantApp -->|Auth Request| NextAuth
    UserApp -->|Auth Request| NextAuth

    MerchantApp -->|DB access via Prisma| PrismaDB
    UserApp -->|DB access via Prisma| PrismaDB
    BankWebhookService -->|DB access via Prisma| PrismaDB

    PaymentGateway -->|POST /webhook| BankWebhookService

    CI -->|triggers build| Turbo
    Turbo -->|builds| MerchantApp
    Turbo -->|builds| UserApp
    Turbo -->|builds| BankWebhookService
    Turbo -->|builds| UIlib
    Turbo -->|builds| StorePkg
    Turbo -->|builds| DBpkg

    CI -->|builds container| Docker

    %% Click Events
    click MerchantApp "https://github.com/faizananwar2801/fab-pay/tree/main/apps/merchant-app"
    click UserApp "https://github.com/faizananwar2801/fab-pay/tree/main/apps/user-app"
    click BankWebhookService "https://github.com/faizananwar2801/fab-pay/blob/main/apps/bank-webhook/src/index.ts"
    click DBpkg "https://github.com/faizananwar2801/fab-pay/tree/main/packages/db"
    click UIlib "https://github.com/faizananwar2801/fab-pay/tree/main/packages/ui"
    click StorePkg "https://github.com/faizananwar2801/fab-pay/tree/main/packages/store"
    click ESLintCfg "https://github.com/faizananwar2801/fab-pay/tree/main/packages/eslint-config"
    click TSCfg "https://github.com/faizananwar2801/fab-pay/tree/main/packages/typescript-config"
    click CI "https://github.com/faizananwar2801/fab-pay/blob/main/github/workflows/build.yml"
    click CI "https://github.com/faizananwar2801/fab-pay/blob/main/github/workflows/deploy.yml"
    click Docker "https://github.com/faizananwar2801/fab-pay/blob/main/docker/Dockerfile.user"
    click Turbo "https://github.com/faizananwar2801/fab-pay/blob/main/turbo.json"

    %% Styles
    classDef frontend fill:#D6EAF8,stroke:#3498DB
    classDef backend fill:#D5F5E3,stroke:#27AE60
    classDef database fill:#FDEBD0,stroke:#E67E22
    classDef library fill:#EBF5FB,stroke:#5DADE2
    classDef external fill:#EAECEE,stroke:#85929E,stroke-dasharray:5 5
    classDef tool fill:#F5EEF8,stroke:#8E44AD
    classDef config fill:#F9EBEA,stroke:#C0392B
```
