# chrizefan/humanizer architecture

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

- Interactive diagram: https://gitdiagram.com/chrizefan/humanizer
- Repository: https://github.com/chrizefan/humanizer

## Overview

##### Project type and purpose
- This is a full-stack web application built on Next.js (app directory, pages and API routes) with a Supabase backend.
- Its core purpose is to “humanize” user-supplied text, track usage via a credit system, and manage user projects and subscriptions.

##### File structure
- Top-level “app” directory: Next.js 13+ server-and-client components for UI (page.tsx, layout.tsx) and built-in API routes under app/api.
- “components” folder: Reusable React components for auth, UI, forms, layout.
- “hooks” and “lib”: Client hooks (use-credits, use-supabase-auth) and server utilities for Supabase.
- “supabase/migrations” and “scripts”: SQL migrations, setup and helper scripts for local and cloud Supabase.
- Config files: netlify.toml (deployment), next.config.js, Tailwind and ESLint configs.
- “tests”: End-to-end and integration/test suites validating auth, credit flows, and endpoints.

##### README for insights
- Features: Supabase Auth, credit‐based usage, project CRUD, subscriptions.
- Database schema: users (with credits), projects, usage_logs.
- API Endpoints: /api/humanize, /api/projects, /api/credits, /api/subscription.

##### Essential elements and be detailed
- Core libraries: humanizer library, supabase-server client, hook layer on client side.
- SQL migrations and RLS policy scripts as part of the infra setup.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client Layer
    subgraph "Client Browser"
        direction TB
        Browser["Browser (React UI)"]:::frontend
        subgraph "UI Layer"
            direction TB
            Pages["Next.js UI Pages"]:::frontend
            ReusableComponents["Reusable React Components"]:::frontend
            Hooks["Client Hooks"]:::frontend
        end
    end

    %% Server Layer
    subgraph "Server - Next.js"
        direction TB
        SSR["SSR Routing"]:::backend
        APIRoutes["Next.js API Routes"]:::backend
        SSR --> APIRoutes

        LibServer["Supabase Auth & Server Utils"]:::backend
        AuthLib["Auth Utilities"]:::backend
        Humanizer["Humanizer Library"]:::backend
        Pricing["Subscription Helpers"]:::backend
        Utils["Utility Functions"]:::backend
        Types["Type Definitions"]:::backend
        Middleware["Middleware"]:::backend
        DebugAPI["Debug Cookies API"]:::backend

        APIRoutes --> LibServer
        APIRoutes --> AuthLib
        APIRoutes --> Humanizer
        APIRoutes --> Pricing
        APIRoutes --> Utils
        APIRoutes --> Types
        Pages --> Middleware
        APIRoutes --> Middleware
        APIRoutes --> DebugAPI
    end

    Browser --> Pages
    Pages --> Hooks
    Pages --> ReusableComponents
    Browser --> APIRoutes

    %% Supabase Services
    subgraph "Supabase"
        direction TB
        AuthService["Supabase Auth"]:::external
        Database["Postgres Database"]:::db
    end

    APIRoutes -->|"Validate Token"| AuthService
    LibServer -->|"Query/Update"| Database
    APIRoutes -->|"CRUD Projects & Credits"| Database
    APIRoutes -->|"Log Usage"| Database

    %% Payment Service
    subgraph "Payment"
        direction TB
        Payment["Stripe / Billing Service"]:::external
    end

    APIRoutes -->|"Manage Subscription"| Payment
    Payment -->|"Update Subscription"| Database

    %% Infrastructure & Scripts
    subgraph "Infrastructure"
        direction TB
        Migrations["SQL Migrations"]:::infra
        PolicyScripts["RLS Policy Scripts"]:::infra
        DBSetup["Database Setup Scripts"]:::infra
        DBSetup2["Supabase Setup Scripts"]:::infra
        AdminAPI["Admin Credit API Route"]:::backend
        AdminSQL["Admin Credit SQL Function"]:::infra
        Tests["Auth Test Suite"]:::infra
        Tests2["Comprehensive Test Suite"]:::infra
        Tests3["Consolidated Test Suite"]:::infra
        CIConfig["Tailwind Config"]:::infra
        CIConfig2["PostCSS Config"]:::infra
        CIConfig3["ESLint Config"]:::infra
        Deploy1["Netlify Config"]:::infra
        Deploy2["Next.js Config"]:::infra
    end

    AdminAPI -->|"Grant Credits"| Database
    Tests --> APIRoutes
    Tests2 --> APIRoutes
    Tests3 --> APIRoutes

    %% Click Events
    click Pages "https://github.com/chrizefan/humanizer/tree/main/app/"
    click ReusableComponents "https://github.com/chrizefan/humanizer/tree/main/components/"
    click Hooks "https://github.com/chrizefan/humanizer/tree/main/hooks/"
    click APIRoutes "https://github.com/chrizefan/humanizer/tree/main/app/api/"
    click LibServer "https://github.com/chrizefan/humanizer/blob/main/lib/supabase-server.ts"
    click AuthLib "https://github.com/chrizefan/humanizer/blob/main/lib/auth.ts"
    click Humanizer "https://github.com/chrizefan/humanizer/blob/main/lib/humanizer.ts"
    click Pricing "https://github.com/chrizefan/humanizer/blob/main/lib/pricing.ts"
    click Utils "https://github.com/chrizefan/humanizer/blob/main/lib/utils.ts"
    click Types "https://github.com/chrizefan/humanizer/blob/main/types/index.ts"
    click Middleware "https://github.com/chrizefan/humanizer/blob/main/middleware.ts"
    click DebugAPI "https://github.com/chrizefan/humanizer/blob/main/app/api/debug-cookies/route.ts"
    click Migrations "https://github.com/chrizefan/humanizer/tree/main/supabase/migrations/"
    click PolicyScripts "https://github.com/chrizefan/humanizer/blob/main/scripts/apply-admin-policy.sh"
    click DBSetup "https://github.com/chrizefan/humanizer/blob/main/scripts/setup-database.sh"
    click DBSetup2 "https://github.com/chrizefan/humanizer/blob/main/scripts/setup-supabase.sh"
    click AdminAPI "https://github.com/chrizefan/humanizer/blob/main/app/api/admin/give-credits/route.ts"
    click AdminSQL "https://github.com/chrizefan/humanizer/blob/main/scripts/archive/create-give-credits-function.sql"
    click Tests "https://github.com/chrizefan/humanizer/blob/main/tests/auth-test-suite.js"
    click Tests2 "https://github.com/chrizefan/humanizer/blob/main/tests/comprehensive-test.js"
    click Tests3 "https://github.com/chrizefan/humanizer/blob/main/tests/consolidated-test-suite.js"
    click CIConfig "https://github.com/chrizefan/humanizer/blob/main/tailwind.config.ts"
    click CIConfig2 "https://github.com/chrizefan/humanizer/blob/main/postcss.config.js"
    click CIConfig3 "https://github.com/chrizefan/humanizer/blob/main/.eslintrc.json"
    click Deploy1 "https://github.com/chrizefan/humanizer/blob/main/netlify.toml"
    click Deploy2 "https://github.com/chrizefan/humanizer/blob/main/next.config.js"

    %% Styles
    classDef frontend fill:#cce5ff,stroke:#004085,color:#004085
    classDef backend fill:#d4edda,stroke:#155724,color:#155724
    classDef external fill:#fff3cd,stroke:#856404,color:#856404
    classDef db fill:#d1ecf1,stroke:#0c5460,color:#0c5460
    classDef infra fill:#e2e3e5,stroke:#6c757d,color:#6c757d
```
