# suvepatra004/format-doc-now architecture

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

- Interactive diagram: https://gitdiagram.com/suvepatra004/format-doc-now
- Repository: https://github.com/suvepatra004/format-doc-now

## Overview

##### Project type and purpose
- PDFox is a full-stack, single-page web application (SPA) for AI-enhanced content formatting, built with React (TypeScript) on the frontend and Supabase (Auth + PostgreSQL + Edge Functions) on the backend.
- It provides real-time preview, local formatting, optional Gemini AI integration, user authentication, and multiple export formats (PDF, TXT).

##### File structure
- Top-level “src” folder contains the React app: pages, components, hooks, integrations, lib, UI.
- “src/integrations/supabase” and “supabase/functions” hold backend integration and serverless functions.
- Supabase-related files: config.toml, migrations, functions for AI formatting and email.
- Build/config files: vite.config.ts, tailwind.config.ts, tsconfigs.

##### Key insights from the README
- Frontend uses React 18 + Vite + Tailwind + shadcn/ui + Framer Motion + React Router.
- Backend is Supabase (Auth, PostgreSQL with RLS) with Edge Functions:
- format-with-ai: calls Google Gemini AI for formatting
- send-contact-email
- Local formatting engine (regex & custom logic) runs in the browser.
- Client-side PDF/TXT generation using html2pdf.js and FileSaver.js.

##### Main components & interactions
a. Components
- Client Browser (SPA):
– UI Layer: React pages & shadcn/ui components
– Formatting Engine: Local regex + structural analysis + output generation modules
– Export Modules: html2pdf.js, FileSaver.js
– State & Hooks: useAuth, use-toast, use-mobile
– Local Storage for privacy
- Backend (Supabase):
– Auth Service (Email verification, JWT)
– PostgreSQL Database (user profiles, pricing, usage logs, documents)
– Edge Functions: format-with-ai, send-contact-email
- External Service:
– Google Gemini AI API
- Deployment & Hosting:
– Vite Dev/Prod server (static assets)
– Supabase hosting for db and functions

b. Relationships & data flows
1. User interacts with React UI → updates local store & preview via local formatting engine
2. For advanced AI formatting: UI → Supabase Edge Function (format-with-ai) → Google Gemini AI → returns formatted HTML/Text → UI
3. Auth flows: UI ↔ Supabase Auth (sign-up/login, JWT)
4. Protected data requests: UI ↔ Supabase Database (via Supabase client)
5. Contact form: UI → Supabase Edge Function (send-contact-email) → SMTP service
6. Export: UI triggers html2pdf.js/FileSaver.js to download document
7. Static assets: Browser fetches index.html + JS bundle from Vite/hosting

c. Architectural patterns & principles
- SPA (React) with client-driven routing (React Router)
- BaaS + Serverless Functions for backend logic
- Multi-layered formatting engine (client-side + optional AI)
- Strict separation: Presentation (components) vs Business logic (hooks, formatting engine) vs Data (Supabase)
- Configuration as code: Vite, Tailwind, tsconfig

d. Key technologies per component
- Frontend: React 18, TypeScript, Vite, Tailwind CSS, shadcn/ui, Framer Motion, React Router
- Formatting: Custom regex engine, html2pdf.js, FileSaver.js
- Backend: Supabase Auth, Postgres, Edge Functions (TypeScript)
- External AI: Google Gemini API

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph "Browser (SPA)"
        subgraph "UI Layer"
            UI1["Components"]:::frontend
            UI2["UI Components"]:::frontend
            UI3["Pages"]:::frontend
        end
        subgraph "State & Hooks"
            H1["useAuth"]:::frontend
            H2["use-toast"]:::frontend
            H3["use-mobile"]:::frontend
        end
        FE["Formatting Engine"]:::frontend
        EM["Export Modules\n(html2pdf.js, FileSaver.js)"]:::frontend
        LS["Local Storage"]:::frontend
    end

    subgraph "Supabase (BaaS)"
        Auth["Auth Service\n(Email, JWT)"]:::backend
        DB["PostgreSQL DB\n(User Profiles, Pricing, Logs)"]:::backend
        subgraph "Edge Functions"
            EF1["format-with-ai"]:::functions
            EF2["send-contact-email"]:::functions
        end
    end

    GA["Google Gemini AI"]:::external
    SMTP["SMTP/Email Service"]:::external

    subgraph "Deployment & Hosting"
        VITE["Vite Config & Entry"]:::hosting
        TAIL["Tailwind & PostCSS"]:::hosting
    end

    %% Flows
    UI1 --> FE
    UI2 --> FE
    UI3 --> FE
    FE --> UI3
    UI3 --> EM
    UI3 --> LS

    UI3 -->|"Auth (HTTPS)"| Auth
    Auth -->|"JWT Token"| UI3

    UI3 -->|"SQL Queries"| DB

    UI3 --> EF1
    EF1 --> GA
    GA --> EF1
    EF1 --> UI3

    UI3 --> EF2
    EF2 --> SMTP

    VITE --> UI1
    VITE --> UI2
    VITE --> UI3

    %% Click Events
    click UI1 "https://github.com/suvepatra004/format-doc-now/tree/main/src/components"
    click UI2 "https://github.com/suvepatra004/format-doc-now/tree/main/src/components/ui"
    click UI3 "https://github.com/suvepatra004/format-doc-now/tree/main/src/pages"
    click H1 "https://github.com/suvepatra004/format-doc-now/blob/main/src/hooks/useAuth.tsx"
    click H2 "https://github.com/suvepatra004/format-doc-now/blob/main/src/hooks/use-toast.ts"
    click H3 "https://github.com/suvepatra004/format-doc-now/blob/main/src/hooks/use-mobile.tsx"
    click FE "https://github.com/suvepatra004/format-doc-now/blob/main/src/lib/utils.ts"
    click Auth "https://github.com/suvepatra004/format-doc-now/blob/main/src/integrations/supabase/client.ts"
    click Auth "https://github.com/suvepatra004/format-doc-now/blob/main/src/integrations/supabase/types.ts"
    click DB "https://github.com/suvepatra004/format-doc-now/tree/main/supabase/migrations"
    click EF1 "https://github.com/suvepatra004/format-doc-now/blob/main/supabase/functions/format-with-ai/index.ts"
    click EF2 "https://github.com/suvepatra004/format-doc-now/blob/main/supabase/functions/send-contact-email/index.ts"
    click VITE "https://github.com/suvepatra004/format-doc-now/blob/main/vite.config.ts"
    click VITE "https://github.com/suvepatra004/format-doc-now/blob/main/src/main.tsx"
    click VITE "https://github.com/suvepatra004/format-doc-now/blob/main/index.html"
    click TAIL "https://github.com/suvepatra004/format-doc-now/blob/main/tailwind.config.ts"
    click TAIL "https://github.com/suvepatra004/format-doc-now/blob/main/postcss.config.js"

    %% Styles
    classDef frontend fill:#cce5ff,stroke:#3399ff,color:#000;
    classDef backend fill:#d4edda,stroke:#28a745,color:#000;
    classDef functions fill:#ffe5b4,stroke:#ff8c00,color:#000;
    classDef external fill:#f8d7da,stroke:#dc3545,color:#000;
    classDef hosting fill:#e2e3ff,stroke:#6f42c1,color:#000;
```
