# satwik-dubey/nextgig architecture

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

- Interactive diagram: https://gitdiagram.com/satwik-dubey/nextgig
- Repository: https://github.com/satwik-dubey/nextgig

## Overview

##### Project type and purpose
- NextGig is a full-stack Next.js application (app directory uses Next.js App Router).
- It offers end-to-end career services: user profile management, AI-driven resume & cover letters, quizzes, industry insights.
- It combines synchronous UI routes, serverless API routes, background jobs, a relational database, and third-party integrations.

##### File structure for architectural hints
- app/ – contains Next.js frontend pages (auth, main) and API routes (app/api).
- lib/ & app/lib/ – helper modules, Prisma client, Inngest orchestration code.
- prisma/ – database schema and migrations (NeonDB via Prisma).
- actions/ – encapsulated business actions (resume, cover letter, interviews) invoked by routes or Inngest.
- public/, components/, hooks/ – static assets, UI components, custom hooks.
- middleware.js – global request layer (e.g., Clerk authentication).
- next.config.mjs, postcss.config.mjs, Tailwind CSS integration.

##### Extract runtime architecture from README
- Frontend: Next.js + Tailwind CSS, deployed on Vercel.
- Backend: Node.js serverless routes + Inngest functions, uses Express-style handlers (via Inngest).
- Auth: Clerk (middleware + React components).
- Database: NeonDB (PostgreSQL) accessed via Prisma ORM.
- AI: Google Gemini API for text generation.
- External data sources: periodic industry updates, ingested by scheduled Inngest jobs.

##### Main components
1. Client (Web Browser)
2. Next.js Frontend (SSR + React in app/ pages)
3. Next.js Server/API Layer
– API routes (app/api/inngest/route.js)
– Business logic modules (actions/, app/lib/helper.js, app/lib/schema.js)
4. Inngest Orchestration
– Scheduled jobs (industry insights every 10 days)
– Background functions (app/lib/inngest/functions.js)
5. Authentication Service: Clerk
6. Database: NeonDB (Prisma ORM)
7. AI Service: Google Gemini API
8. External Data Sources: industry trend feeds
9. Deployment environment: Vercel

##### Relationships & data flows
- Client ↔ Next.js Frontend: HTTP(S) for SSR/SSG pages, client-side navigation with React.
- Frontend → API Layer: fetch() calls to /api/* endpoints (interview.js, resume.js, user.js).
- API Layer → Business Actions: invokes functions in actions/ and app/lib.
- Business Actions → Prisma Client → NeonDB: CRUD for user profiles, resumes, quizzes.
- API Layer → Google Gemini: generate cover letters, resume content.
- Inngest Scheduler ↔ API Layer: triggers periodic background jobs (industry insights ingest).
- Inngest Functions → External Data Sources: fetch and summarize with AI, store to DB.
- All inbound requests pass through middleware.js for Clerk auth.

##### Architectural patterns & design principles
- Separation of concerns: UI (components/ + app/) vs. business logic (actions/ + app/lib) vs. data layer (prisma/).
- Serverless functions pattern: Next.js API routes & Inngest jobs, no dedicated monolith server.
- Orchestration/Event-driven: Inngest manages background tasks, scheduling, and retries.
- ORM abstraction: Prisma schema defines models (prisma/schema.prisma), migrations guarantee versioning.
- Externalized config: next.config.mjs, environment variables for DB, Clerk, Google Gemini.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Deployment Boundary
    subgraph "Vercel Environment"
        direction TB

        %% Frontend Layer
        subgraph "Frontend Layer"
            direction TB
            Client["Web Browser"]:::external
            NextJSFrontend["Next.js Frontend\n(app/)"]:::frontend
        end

        %% API & Service Layer
        subgraph "API & Service Layer"
            direction TB
            Middleware["middleware.js\n(Clerk Auth)"]:::api
            APILayer["Next.js API Routes\n(app/api/)"]:::api
            ServiceLayer["Service Layer\n(actions/, lib/)"]:::service
        end

        %% Background Layer
        subgraph "Background Layer"
            direction TB
            Inngest["Inngest Orchestration\n(lib/inngest/)"]:::background
        end
    end

    %% Data Store
    PrismaClient["Prisma Client\n(lib/prisma.js)"]:::service
    NeonDB["NeonDB\nPostgreSQL\n(prisma/)"]:::db

    %% External Services
    Clerk["Clerk Auth"]:::external
    GoogleGemini["Google Gemini API"]:::external
    DataFeeds["Industry Data Feeds"]:::external

    %% Relationships
    Client --> NextJSFrontend
    Client --React SDK--> Clerk
    Client -->|fetch /api/*| Middleware
    Middleware -->|validate| Clerk
    Middleware --> APILayer
    APILayer --> ServiceLayer
    APILayer -->|generate content| GoogleGemini
    ServiceLayer --> PrismaClient
    PrismaClient --> NeonDB
    Inngest -->|trigger jobs| ServiceLayer
    DataFeeds -.->|scheduled fetch| Inngest
    NextJSFrontend -->|SSR/SSG pages| APILayer

    %% Click Events
    click NextJSFrontend "https://github.com/satwik-dubey/nextgig/tree/main/app/"
    click APILayer "https://github.com/satwik-dubey/nextgig/blob/main/app/api/inngest/route.js"
    click Middleware "https://github.com/satwik-dubey/nextgig/blob/main/middleware.js"
    click ServiceLayer "https://github.com/satwik-dubey/nextgig/tree/main/actions/"
    click Inngest "https://github.com/satwik-dubey/nextgig/blob/main/lib/inngest/functions.js"
    click PrismaClient "https://github.com/satwik-dubey/nextgig/blob/main/lib/prisma.js"
    click NeonDB "https://github.com/satwik-dubey/nextgig/blob/main/prisma/schema.prisma"

    %% Styles
    classDef frontend fill:#cce4ff,stroke:#0366d6,stroke-width:2px
    classDef api fill:#d1f0d1,stroke:#28a745,stroke-width:2px
    classDef service fill:#d4f1be,stroke:#85bb65,stroke-width:2px
    classDef background fill:#fff3bf,stroke:#f0ad4e,stroke-width:2px
    classDef db fill:#ffe4cc,stroke:#f39c12,stroke-width:2px
    classDef external fill:#ebedef,stroke:#6c757d,stroke-width:2px
```
