# amansingh0807/genform architecture

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

- Interactive diagram: https://gitdiagram.com/amansingh0807/genform
- Repository: https://github.com/amansingh0807/genform

## Overview

##### Project Type and Purpose
- Full-stack SaaS web application
- Purpose: AI-driven form generation, user subscriptions, analytics dashboard

##### File Structure
Top-level directories:
- app/      – Next.js 13 “app router” (UI pages, layouts, server actions, API routes)
- actions/  – Server-side form and user operations (Prisma + Stripe + AI)
- components/ & components/ui/ – React UI building blocks
- lib/      – Shared libraries (Prisma client, Stripe client, utilities)
- prisma/   – Database schema & migration scripts
- hooks/    – Custom React hooks (e.g. use-mobile)
- public/   – Static assets (e.g. screenshots)
- types/    – TypeScript type definitions
- middleware.ts – Next.js middleware (auth / routing guard)
Configuration files: next.config.ts, tsconfig.json, tailwind.config.ts

##### README
- Frontend: Next.js + React + Tailwind CSS
- Backend: Node.js via Next.js server actions + API routes, Prisma ORM
- External services: Stripe (subscriptions & payments), LLM (Gemini API)
- Hosting: Vercel / Render

##### Main Components & Their Interactions
A. Frontend (Next.js “app”):
– Layouts & pages under app/ for:
- Public routes (landing, sign-in, sign-up, success)
- Authenticated dashboard routes (forms management, analytics, upgrade)
- Form rendering (app/forms/[formId]/page.tsx)
– UI Components (components/ & components/ui/) used by pages
– React server components vs. client components (note files importing “use client”)
– Middleware handles auth checks on protected routes
B. Server Layer:
– Server Actions (actions/*.ts) invoked from React (form CRUD, submit, stats, subscription)
– Next.js API Routes (app/api/stripe/checkout-session/route.ts) for Stripe checkout sessions
– lib/prisma.ts exposes Prisma client to actions & API routes
– lib/stripe-client.ts + lib/stripe.ts encapsulate Stripe integration
– Gemini (AI) calls inside actions/generateForm.ts
C. Database:
– Prisma ORM maps to relational database (PostgreSQL) as defined in prisma/schema.prisma
– Migrations under prisma/migrations
– Models: User, Form, Submission, Subscription, etc.
D. External Services:
– Stripe API: payments, subscriptions
– Gemini (or another LLM) for AI form generation
– (Optional) Supabase – mentioned in README but not obvious in code
E. Hosting & Deployment:
– Vercel/Render hosting full stack via Next.js deployment
– Environment variables for DB_URL, STRIPE keys, AI keys

##### Architectural Patterns & Principles
- Server-side rendering + incremental static regeneration (Next.js)
- Server Actions for mutations (Next.js 13 feature)
- API Routes for third-party integrations
- Database abstraction via Prisma (repository pattern)
- Single codebase for frontend + backend (monorepo style)
- Component-based UI (atomic design in components/ui/)
- Middleware for cross-cutting concerns (authentication)

## Diagram (Mermaid)

```mermaid
flowchart TD
    classDef client fill:#D0E8FF,stroke:#0366D6,color:#0366D6
    classDef ui fill:#E8F1FF,stroke:#1E40AF,color:#1E40AF
    classDef server fill:#F3F4F6,stroke:#4B5563,color:#4B5563
    classDef api fill:#E5E7EB,stroke:#6B7280,color:#6B7280
    classDef db fill:#DEF7EC,stroke:#047857,color:#047857
    classDef external stroke-dasharray: 5 5,fill:#FFF4E5,stroke:#D97706,color:#B45309
    classDef config fill:#E0F2FE,stroke:#0284C7,color:#0369A1

    subgraph "Client Layer"
        Browser["Browser (React)"]:::client
    end

    subgraph "Next.js Application Layer"
        subgraph "UI Router"
            Router["Next.js UI Router"]:::ui
            click Router "https://github.com/amansingh0807/genform/tree/master/app/"
            subgraph "Auth Pages"
                AuthLayout["Auth Layout & Pages"]:::ui
                click AuthLayout "https://github.com/amansingh0807/genform/blob/master/app/(auth)/layout.tsx"
            end
            subgraph "Public Pages"
                HomeLayout["Home Layout & Pages"]:::ui
                click HomeLayout "https://github.com/amansingh0807/genform/blob/master/app/(home)/layout.tsx"
            end
            subgraph "Dashboard Pages"
                Dashboard["Dashboard Pages"]:::ui
                click Dashboard "https://github.com/amansingh0807/genform/blob/master/app/dashboard/layout.tsx"
            end
            FormRender["Form Rendering Pages"]:::ui
            click FormRender "https://github.com/amansingh0807/genform/blob/master/app/forms/[formId]/layout.tsx"
            Success["Success Page"]:::ui
            click Success "https://github.com/amansingh0807/genform/blob/master/app/success/page.tsx"
            NotFound["Not Found Page"]:::ui
            click NotFound "https://github.com/amansingh0807/genform/blob/master/app/not-found.tsx"
        end

        subgraph "UI Components"
            Components["React UI Components"]:::ui
            click Components "https://github.com/amansingh0807/genform/tree/master/components/"
            UILib["UI Library Components"]:::ui
            click UILib "https://github.com/amansingh0807/genform/tree/master/components/ui/"
            Hooks["Custom Hooks"]:::ui
            click Hooks "https://github.com/amansingh0807/genform/blob/master/hooks/use-mobile.tsx"
            Styles["Global Styles"]:::ui
            click Styles "https://github.com/amansingh0807/genform/blob/master/app/globals.css"
        end

        subgraph "Server Layer"
            Middleware["Middleware (Auth Guard)"]:::server
            click Middleware "https://github.com/amansingh0807/genform/blob/master/middleware.ts"
            Actions["Server Actions"]:::server
            click Actions "https://github.com/amansingh0807/genform/blob/master/actions/getForms.ts"
            click Actions "https://github.com/amansingh0807/genform/blob/master/actions/generateForm.ts"
            click Actions "https://github.com/amansingh0807/genform/blob/master/actions/publishForm.ts"
            click Actions "https://github.com/amansingh0807/genform/blob/master/actions/deleteForm.ts"
            click Actions "https://github.com/amansingh0807/genform/blob/master/actions/updateForm.ts"
            click Actions "https://github.com/amansingh0807/genform/blob/master/actions/formStats.ts"
            click Actions "https://github.com/amansingh0807/genform/blob/master/actions/submitForm.ts"
            click Actions "https://github.com/amansingh0807/genform/blob/master/actions/userSubscription.ts"
            StripeAPI["Stripe Checkout API Route"]:::api
            click StripeAPI "https://github.com/amansingh0807/genform/blob/master/app/api/stripe/checkout-session/route.ts"
            PrismaClient["Prisma Client Library"]:::server
            click PrismaClient "https://github.com/amansingh0807/genform/blob/master/lib/prisma.ts"
            StripeLib["Stripe Integration Libraries"]:::server
            click StripeLib "https://github.com/amansingh0807/genform/blob/master/lib/stripe-client.ts"
            click StripeLib "https://github.com/amansingh0807/genform/blob/master/lib/stripe.ts"
            Utils["Utility Functions"]:::server
            click Utils "https://github.com/amansingh0807/genform/blob/master/lib/utils.ts"
            click Utils "https://github.com/amansingh0807/genform/blob/master/lib/pricingplan.ts"
            Config["Configuration Files"]:::config
            click Config "https://github.com/amansingh0807/genform/blob/master/next.config.ts"
            Types["Type Definitions"]:::config
            click Types "https://github.com/amansingh0807/genform/blob/master/types/form.ts"
        end
    end

    subgraph "Database Layer"
        DB["PostgreSQL Database"]:::db
        click DB "https://github.com/amansingh0807/genform/blob/master/prisma/schema.prisma"
        Migrations["Migrations"]:::db
        click Migrations "https://github.com/amansingh0807/genform/tree/master/prisma/migrations/"
    end

    subgraph "External Services Layer"
        StripeExt["Stripe API"]:::external
        AI["Gemini AI Service"]:::external
        Hosting["Vercel/Render Hosting"]:::external
    end

    Browser --> Router
    Browser --> Components
    Browser --> UILib
    Browser --> Hooks

    Router --> Actions
    Router --> StripeAPI

    Actions --> PrismaClient
    Actions --> StripeExt
    Actions --> AI
    Actions --> Utils

    PrismaClient --> DB
    Migrations --> DB

    Middleware --> Router

    Hosting --> Router
    Hosting --> DB
    Hosting --> StripeExt
    Hosting --> AI
```
