# hmad28/next-js-portfolio architecture

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

- Interactive diagram: https://gitdiagram.com/hmad28/next-js-portfolio
- Repository: https://github.com/hmad28/next-js-portfolio

## Overview

##### Project type and purpose
- This is a full-stack Next.js 13 application (using the App Router).
- It serves a portfolio site with dynamic pages (`/portfolio/[slug]`), an admin dashboard (`/dashboard`), file‐upload endpoints, and persists data to a relational database via Drizzle ORM (backed by Prisma schema).

##### File structure
- Top-level “app” directory holds all React server and client components, page routes, layouts, and API routes (`app/api/.../route.ts`).
- The “components” directory contains shared UI components and custom form widgets (inputs, rich‐text editor, tag selector).
- The “lib” directory implements core utilities:
- `lib/db/` initializes Drizzle (with `prisma/schema.prisma`)
- `lib/api.ts` abstracts API calls
- `lib/uploadthing.ts` and `app/api/uploadthing` handle file uploading to Uploadthing (likely S3 under the hood)
- Configuration and build files include `next.config.ts`, `drizzle.config.ts`, `tsconfig.json`, lint/postcss configs, and deployment via Vercel is implied.

##### README

1. Next.js Frontend (React App)
- Server Components (app/page.tsx, layout.tsx, dynamic pages)
- Client Components (app/components/client.tsx, form widgets)
2. Next.js API Layer (Serverless Functions)
- Portfolio CRUD endpoints (`app/api/portfolios/route.ts`, `[id]/route.ts`)
- Uploadthing endpoint (`app/api/uploadthing/route.ts`)
- File upload handler (`app/api/upload/route.ts`)
3. Business-Logic / ORM Layer
- Drizzle ORM (configured in `drizzle.config.ts`)
- Prisma schema (`prisma/schema.prisma`)
- DB utilities (`lib/db/index.ts`, `lib/db/schema.ts`)
4. Database
- PostgreSQL (or MySQL)—the SQL RDBMS backing Drizzle.
5. File Storage Service
- Uploadthing-managed storage (S3 or equivalent)
6. Deployment / CDN
- Vercel (hosting static assets, serverless functions, CDN)

- Browser → Next.js Frontend (SSR or SSG pages)
- Frontend → API Layer (fetch fetches to `/api/portfolios`, `/api/uploadthing`)
- API Layer → ORM Layer (Drizzle calls)
- ORM Layer → Database (SQL queries)
- Upload endpoint → Uploadthing → S3 storage → Return file URL
- User-initiated form submissions → API → DB or Storage → Frontend refresh

c. Architectural patterns & design principles
- App Router (Next.js 13) with nested layouts and dynamic routing
- Server Components for data fetching and initial page render
- Client Components for interactivity (forms, rich-text editor, uploads)
- API routes as serverless functions for business logic
- Layered architecture (Presentation → API → ORM → DB)
- Separation of concerns: UI vs. data vs. storage

d. Key technologies/frameworks
- Next.js 13 (App Router, React Server & Client Components)
- Drizzle ORM + Prisma schema for database modeling
- Uploadthing for file uploads (S3 or other object store)
- Vercel hosting and CDN
- TypeScript throughout

## Diagram (Mermaid)

```mermaid
graph TB
    %% External
    Browser["User Browser"]:::external
    PublicAssets["Public Assets (public/)"]:::cdn
    CDN["Vercel CDN"]:::cdn

    Browser -->|"HTTP(S) request"| CDN
    CDN -->|"serves static pages/assets"| PublicAssets
    CDN -->|"serves SSR pages"| NextApp

    %% Frontend Layer
    subgraph "Frontend Layer"
        direction TB
        NextApp["Next.js App (app/)"]:::appCode
        Layout["Root Layout (app/layout.tsx)"]:::appCode
        Styles["Global Styles (app/globals.css)"]:::appCode
        Landing["Landing Page (app/page.tsx)"]:::appCode
        About["About Page (app/about/page.tsx)"]:::appCode
        PortfolioList["Portfolio Listing (app/portfolio/page.tsx)"]:::appCode
        PortfolioCopy["Portfolio Listing Copy (app/portfolio/page copy.tsx)"]:::appCode
        PortfolioDynamic["Portfolio Detail (app/portfolio/[slug]/page.tsx)"]:::appCode
        NotFound["Portfolio Not Found (app/portfolio/[slug]/not-found.tsx)"]:::appCode
        Dashboard["Admin Dashboard (app/dashboard/page.tsx)"]:::appCode
        AppComponents["App Components (app/components/)"]:::appCode
        GenericUI["Generic UI Components (components/ui/)"]:::appCode
        Widgets["Form & Widgets (components/*.tsx)"]:::appCode
    end

    %% API Layer
    subgraph "API Layer"
        direction TB
        PortfoliosList["Portfolios CRUD List/Create\n(app/api/portfolios/route.ts)"]:::appCode
        PortfoliosItem["Portfolios CRUD RUD\n(app/api/portfolios/[id]/route.ts)"]:::appCode
        UploadHandler["Direct Upload Handler\n(app/api/upload/route.ts)"]:::appCode
        UploadthingCore["Uploadthing Core Logic\n(app/api/uploadthing/core.ts)"]:::appCode
        UploadthingEndpoint["Uploadthing Endpoint\n(app/api/uploadthing/route.ts)"]:::appCode
    end

    %% ORM & Utilities Layer
    subgraph "ORM & Utils Layer"
        direction TB
        DrizzleConfig["Drizzle Config (drizzle.config.ts)"]:::config
        DBInit["DB Init & Schema\n(lib/db/index.ts, lib/db/schema.ts)"]:::appCode
        PrismaSchema["Prisma Schema\n(prisma/schema.prisma)"]:::appCode
        APIUtil["API Abstraction\n(lib/api.ts)"]:::appCode
        UploadClient["Uploadthing SDK\n(lib/uploadthing.ts)"]:::appCode
        MiscUtils["Misc Utilities\n(lib/utils.ts, lib/category-config.ts,\nlib/tech-config.ts)"]:::appCode
        Configs["Next/TS & Build Configs\n(next.config.ts, tsconfig.json,\neslint.config.mjs, .eslintignore,\npostcss.config.mjs, .flowbite-react/)"]:::config
    end

    %% External Systems
    DB["SQL Database\n(PostgreSQL/MySQL)"]:::db
    Storage["Object Storage (S3)"]:::storage

    %% Data Flows
    NextApp -->|"fetch data via SSR"| PortfoliosList
    Landing -->|"server render"| DrizzleConfig
    PortfolioList -->|"fetch list via API"| PortfoliosList
    PortfolioDynamic -->|"fetch item via API"| PortfoliosItem
    Dashboard -->|"API calls"| PortfoliosList
    Widgets -->|"uses upload SDK"| UploadClient
    Widgets -->|"calls upload API"| UploadHandler

    PortfoliosList -->|"ORM query"| DBInit
    PortfoliosItem -->|"ORM query"| DBInit
    UploadHandler -->|"PUT to S3"| Storage
    UploadthingCore -->|"interfaces with SDK"| UploadClient
    UploadthingEndpoint -->|"returns file URL"| Widgets

    DBInit -->|"executes SQL"| DB
    PrismaSchema --> DBInit
    DrizzleConfig --> DBInit
    APIUtil -->|"used by Frontend Fetch"| NextApp

    %% Click Events
    click NextApp "https://github.com/hmad28/next-js-portfolio/tree/main/app/"
    click Layout "https://github.com/hmad28/next-js-portfolio/blob/main/app/layout.tsx"
    click Styles "https://github.com/hmad28/next-js-portfolio/blob/main/app/globals.css"
    click Landing "https://github.com/hmad28/next-js-portfolio/blob/main/app/page.tsx"
    click About "https://github.com/hmad28/next-js-portfolio/blob/main/app/about/page.tsx"
    click PortfolioList "https://github.com/hmad28/next-js-portfolio/blob/main/app/portfolio/page.tsx"
    click PortfolioCopy "https://github.com/hmad28/next-js-portfolio/blob/main/app/portfolio/page copy.tsx"
    click PortfolioDynamic "https://github.com/hmad28/next-js-portfolio/blob/main/app/portfolio/[slug]/page.tsx"
    click NotFound "https://github.com/hmad28/next-js-portfolio/blob/main/app/portfolio/[slug]/not-found.tsx"
    click Dashboard "https://github.com/hmad28/next-js-portfolio/blob/main/app/dashboard/page.tsx"
    click AppComponents "https://github.com/hmad28/next-js-portfolio/tree/main/app/components/"
    click GenericUI "https://github.com/hmad28/next-js-portfolio/tree/main/components/ui/"
    click Widgets "https://github.com/hmad28/next-js-portfolio/blob/main/components/portfolio-form.tsx"
    click Widgets "https://github.com/hmad28/next-js-portfolio/blob/main/components/rich-text-editor.tsx"
    click Widgets "https://github.com/hmad28/next-js-portfolio/blob/main/components/tag-selector.tsx"
    click Widgets "https://github.com/hmad28/next-js-portfolio/blob/main/components/image-upload.tsx"
    click Widgets "https://github.com/hmad28/next-js-portfolio/blob/main/components/custom-upload-button.tsx"
    click PortfoliosList "https://github.com/hmad28/next-js-portfolio/blob/main/app/api/portfolios/route.ts"
    click PortfoliosItem "https://github.com/hmad28/next-js-portfolio/blob/main/app/api/portfolios/[id]/route.ts"
    click UploadHandler "https://github.com/hmad28/next-js-portfolio/blob/main/app/api/upload/route.ts"
    click UploadthingCore "https://github.com/hmad28/next-js-portfolio/blob/main/app/api/uploadthing/core.ts"
    click UploadthingEndpoint "https://github.com/hmad28/next-js-portfolio/blob/main/app/api/uploadthing/route.ts"
    click APIUtil "https://github.com/hmad28/next-js-portfolio/blob/main/lib/api.ts"
    click DrizzleConfig "https://github.com/hmad28/next-js-portfolio/blob/main/drizzle.config.ts"
    click DBInit "https://github.com/hmad28/next-js-portfolio/blob/main/lib/db/index.ts"
    click DBInit "https://github.com/hmad28/next-js-portfolio/blob/main/lib/db/schema.ts"
    click PrismaSchema "https://github.com/hmad28/next-js-portfolio/blob/main/prisma/schema.prisma"
    click UploadClient "https://github.com/hmad28/next-js-portfolio/blob/main/lib/uploadthing.ts"
    click MiscUtils "https://github.com/hmad28/next-js-portfolio/blob/main/lib/utils.ts"
    click MiscUtils "https://github.com/hmad28/next-js-portfolio/blob/main/lib/category-config.ts"
    click MiscUtils "https://github.com/hmad28/next-js-portfolio/blob/main/lib/tech-config.ts"
    click Configs "https://github.com/hmad28/next-js-portfolio/blob/main/next.config.ts"
    click Configs "https://github.com/hmad28/next-js-portfolio/blob/main/tsconfig.json"
    click Configs "https://github.com/hmad28/next-js-portfolio/blob/main/eslint.config.mjs"
    click Configs "https://github.com/hmad28/next-js-portfolio/blob/main/.eslintignore"
    click Configs "https://github.com/hmad28/next-js-portfolio/blob/main/postcss.config.mjs"
    click Configs "https://github.com/hmad28/next-js-portfolio/tree/main/.flowbite-react/"

    %% Styles
    classDef appCode fill:#AEDFF7,stroke:#0366d6
    classDef db fill:#C6F6D5,stroke:#2F855A
    classDef storage fill:#FEEBC8,stroke:#DD6B20
    classDef cdn fill:#EDF2F7,stroke:#A0AEC0
    classDef external fill:#F8F8F8,stroke:#000000
    classDef config fill:#E9D8FD,stroke:#6B46C1
```
