# syedtazyeen/datum architecture

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

- Interactive diagram: https://gitdiagram.com/syedtazyeen/datum
- Repository: https://github.com/syedtazyeen/datum

## Overview

##### Main components
a. Frontend (Remix/React Router SSR)
b. Backend / Server-side API (Remix actions & loaders)
c. Database layer (Drizzle ORM + PostgreSQL)
d. Authentication service (Supabase Auth)
e. OCR & LLM external services (invoice parsing logic)
f. Session & state management (session storage/resolvers)
g. Static assets & build pipeline (Vite, public folder)

##### Relationships and data flows
- User browser ↔ Remix SSR (entry.client.tsx & entry.server.tsx)
- SSR routes (app/routes.ts & app/pages/…) invoke:
- Loaders (app/session/loaders.ts) for fetching data
- Actions (app/actions/*.ts) for mutations (auth-callback, invoice, onboard, etc.)
- Actions → Business logic (app/lib/*.ts) → Database (app/db/client.ts via Drizzle ORM)
- Authentication flows → Supabase client (app/supabase/client.ts)
- Invoice processing:
- File upload component (app/components/files/drag-upload.tsx) → server action
- Server action calls OCR/LLM (app/lib/invoice.ts) → returns structured data
- Data saved via Drizzle ORM into PostgreSQL

##### Architectural patterns & design principles
- Server-side rendering (Remix) with nested routing patterns (app/pages/(dashboard)/…)
- Layered architecture: UI → API actions → business-logic libraries → ORM → database
- Clean separation:
- UI components (app/components/ui & common)
- Domain logic (app/lib)
- Data access (app/db/api & client)
- Configuration (drizzle.config.ts, vite.config.ts, tsconfig.json)
- CI/CD / migrations: Drizzle migrations folder with snapshot & journal

##### Technologies, frameworks & libraries
- React 19 + Remix SSR + React Router config (react-router.config.ts)
- Tailwind CSS (app/app.css) + Radix UI (components/ui)
- Drizzle ORM (drizzle.config.ts, app/db/schema.ts) + PostgreSQL
- Supabase Auth (app/supabase/client.ts)
- Zod for request-payload validation (implied via lib/utils or lib/response)
- Vite for dev server & build (vite.config.ts)

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client Side
    subgraph "Client Side"
        direction TB
        EntryClient["entry.client.tsx"]:::frontend
        click EntryClient "https://github.com/syedtazyeen/datum/blob/main/app/entry.client.tsx"
        EntryServer["entry.server.tsx"]:::frontend
        click EntryServer "https://github.com/syedtazyeen/datum/blob/main/app/entry.server.tsx"
        Root["root.tsx"]:::frontend
        click Root "https://github.com/syedtazyeen/datum/blob/main/app/root.tsx"
    end

    %% Routing Layer
    subgraph "Routing Layer"
        direction TB
        Routes["routes.ts"]:::frontend
        click Routes "https://github.com/syedtazyeen/datum/blob/main/app/routes.ts"
        Pages["pages/"]:::frontend
        click Pages "https://github.com/syedtazyeen/datum/tree/main/app/pages/"
    end

    %% Business/API Layer
    subgraph "Business/API Layer"
        direction TB
        AuthCallback["auth-callback.ts"]:::api
        click AuthCallback "https://github.com/syedtazyeen/datum/blob/main/app/actions/auth-callback.ts"
        InvoiceAction["invoice.ts"]:::api
        click InvoiceAction "https://github.com/syedtazyeen/datum/blob/main/app/actions/invoice.ts"
        Onboard["onboard.ts"]:::api
        click Onboard "https://github.com/syedtazyeen/datum/blob/main/app/actions/onboard.ts"
        SignOut["sign-out.ts"]:::api
        click SignOut "https://github.com/syedtazyeen/datum/blob/main/app/actions/sign-out.ts"
        Theme["theme.ts"]:::api
        click Theme "https://github.com/syedtazyeen/datum/blob/main/app/actions/theme.ts"
        Loaders["loaders.ts"]:::api
        click Loaders "https://github.com/syedtazyeen/datum/blob/main/app/session/loaders.ts"
        Resolvers["resolvers.ts"]:::api
        click Resolvers "https://github.com/syedtazyeen/datum/blob/main/app/session/resolvers.ts"
    end

    %% Domain Logic
    subgraph "Domain Logic"
        direction TB
        InvoiceLib["invoice.ts"]:::api
        click InvoiceLib "https://github.com/syedtazyeen/datum/blob/main/app/lib/invoice.ts"
    end

    %% Persistence Layer
    subgraph "Persistence Layer"
        direction TB
        DBClient["client.ts"]:::db
        click DBClient "https://github.com/syedtazyeen/datum/blob/main/app/db/client.ts"
        DBSchema["schema.ts"]:::db
        click DBSchema "https://github.com/syedtazyeen/datum/blob/main/app/db/schema.ts"
        DBAPIAuth["auth.ts"]:::db
        click DBAPIAuth "https://github.com/syedtazyeen/datum/blob/main/app/db/api/auth.ts"
        DBAPIInvoice["invoice.ts"]:::db
        click DBAPIInvoice "https://github.com/syedtazyeen/datum/blob/main/app/db/api/invoice.ts"
        DBAPITeam["team.ts"]:::db
        click DBAPITeam "https://github.com/syedtazyeen/datum/blob/main/app/db/api/team.ts"
        DBAPIUser["user.ts"]:::db
        click DBAPIUser "https://github.com/syedtazyeen/datum/blob/main/app/db/api/user.ts"
        Migrations["migrations/"]:::devops
        click Migrations "https://github.com/syedtazyeen/datum/tree/main/app/db/migrations/"
        DrizzleCfg["drizzle.config.ts"]:::devops
        click DrizzleCfg "https://github.com/syedtazyeen/datum/blob/main/drizzle.config.ts"
    end

    %% External Services
    subgraph "External Services"
        direction TB
        Supabase["Supabase Auth"]:::external
        click Supabase "https://github.com/syedtazyeen/datum/blob/main/app/supabase/client.ts"
        OCRLLM["OCR & LLM"]:::external
    end

    %% DevOps / Infra
    subgraph "DevOps/Infra"
        direction TB
        Public["public/"]:::devops
        click Public "https://github.com/syedtazyeen/datum/tree/main/public/"
        AppCSS["app.css"]:::devops
        click AppCSS "https://github.com/syedtazyeen/datum/blob/main/app/app.css"
        ViteCfg["vite.config.ts"]:::devops
        click ViteCfg "https://github.com/syedtazyeen/datum/blob/main/vite.config.ts"
        TSConfig["tsconfig.json"]:::devops
        click TSConfig "https://github.com/syedtazyeen/datum/blob/main/tsconfig.json"
        PackageJSON["package.json"]:::devops
        click PackageJSON "https://github.com/syedtazyeen/datum/blob/main/package.json"
    end

    %% Data Flows
    User["User Browser"]:::frontend
    User -->|HTTP| EntryClient
    User -->|HTTP| EntryServer
    EntryServer --> Root
    Root --> Routes
    Routes --> Pages
    Pages -->|Loader| Loaders
    Pages -->|Action| AuthCallback
    Pages -->|Action| InvoiceAction
    Pages -->|Action| Onboard
    Pages -->|Action| SignOut
    Pages -->|Action| Theme

    Loaders --> DBClient
    Loaders --> DBAPIAuth
    AuthCallback --> Supabase
    AuthCallback --> Loaders
    InvoiceAction --> InvoiceLib
    InvoiceLib --> OCRLLM
    InvoiceLib --> DBClient
    InvoiceLib --> DBAPIInvoice
    Onboard --> DBClient
    Onboard --> DBAPIUser
    SignOut --> Supabase
    Theme --> DBClient

    DBClient --> DBSchema
    DBClient --> DBAPITeam

    %% Styles
    classDef frontend fill:#cce5ff,stroke:#004085,color:#004085;
    classDef api fill:#d4edda,stroke:#155724,color:#155724;
    classDef db fill:#fff3cd,stroke:#856404,color:#856404;
    classDef external fill:#f5c6cb,stroke:#721c24,color:#721c24;
    classDef devops fill:#e2e3e5,stroke:#818182,color:#1b1e21;
```
