# thienguen/website architecture

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

- Interactive diagram: https://gitdiagram.com/thienguen/website
- Repository: https://github.com/thienguen/website

## Overview

##### Project Type and Purpose
- This is a full-stack, server-rendered Next.js 13 portfolio/guestbook application.
- It combines React UI (app router + server components), serverless API routes, a relational database (Prisma + PlanetScale), and third-party services (OAuth providers, Lanyard API).

##### Main Architectural Components
a. Client Layer
- Web browser running React/Next.js client components (hydrated UI, hooks, kbar, useSound).
b. Next.js Application (Server & Serverless)
- App Router: server components for pages under /src/app/* (render at request time or static).
- API Routes: under /src/app/api/* (e.g. /auth, /guestbooks, /delete) implemented as serverless functions.
- Middleware: authentication checks, redirects.
- NextAuth Layer: in /src/lib/nextauth – sets up session providers (GitHub, Google), JWT/cookie management.
- Prisma Client: in /src/lib/prisma.ts – ORM connecting to PlanetScale via DATABASE_URL.
c. Database Layer
- PlanetScale MySQL instance managed via Prisma schema in /prisma/schema.prisma.
- Stores user sessions, guestbook entries, any future blog content.
d. External Services
- OAuth Providers: GitHub OAuth, Google OAuth for user sign-in.
- Lanyard API: fetches real-time Discord presence.
- Vercel Platform: hosts the Next.js app with CDN, serverless functions, environment management.

##### Relationships and Data Flows
- Browser → Next.js App Router: requests pages (SSR/SSG) and receives HTML + JSON for hydration.
- Browser → API Routes: fetch/POST requests for guestbook entries, deletions, auth callback flows.
- Next.js Server → Prisma → PlanetScale: run queries/mutations for persistent data.
- Next.js Server → OAuth Providers & Lanyard API: perform REST calls for authentication and presence data.
- Next.js App → Public CDN: load static assets (images, CSS, sounds).

##### Architectural Patterns & Design Principles
- Server-Side Rendering (SSR) & Static Generation (SSG) via Next.js App Router.
- Component-driven UI: reusable React components in /src/components and /src/ui.
- Separation of concerns:
- UI layer (components + styles).
- Data access layer (Prisma in lib).
- Auth layer (NextAuth providers in lib/nextauth).
- API layer (serverless routes).
- Environment-driven configuration for secrets & URLs via .env.
- CDN + edge-network for static assets (public folder).

##### Elements
- Clear component labels (e.g., “Next.js App Router”, “Guestbook API Route”, “Prisma Client”).
- Notation of environment/config file for secrets (e.g., .env).

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Client Layer
    subgraph "Client Layer"
        Browser["Web Browser"]:::client
        Static["Static Assets (Public)"]:::static
    end

    %% Next.js Application Layer
    subgraph "Next.js Application"
        subgraph "Frontend (React/UI)"
            AppRouter["Next.js App Router"]:::frontend
            Middleware["Middleware"]:::middleware
            NextAuth["NextAuth Layer"]:::auth
            subgraph "UI Components"
                UI["React UI Components"]:::ui
                GuestbookUI["Guestbook UI Components"]:::ui
                DashboardUI["Dashboard UI Components"]:::ui
                NavbarUI["Navbar Components"]:::ui
            end
            subgraph "Custom Hooks"
                Hooks["Client-Side Hooks"]:::hooks
                LanyardHook["Lanyard API Hook"]:::hooks
            end
        end
        subgraph "API Layer (Serverless)"
            AuthAPI["Authentication API Route"]:::api
            GuestbookAPI["Guestbook API Route"]:::api
            DeleteAPI["Delete Entry API Route"]:::api
        end
        PrismaClient["Prisma Client"]:::dbclient
    end

    %% Persistence Layer
    subgraph "Database Layer"
        DB["PlanetScale MySQL"]:::database
    end

    %% External Services
    subgraph "External Services"
        OAuth["OAuth Providers (GitHub, Google)"]:::external
        Lanyard["Lanyard API"]:::external
        Vercel["Vercel Platform"]:::external
    end

    %% Data Flows
    Browser -->|"HTTPS/HTML+JSON"| Middleware
    Middleware -->|"SSR/SSG"| AppRouter
    Browser -->|"HTTPS/JSON"| AuthAPI
    Browser -->|"HTTPS/JSON"| GuestbookAPI
    Browser -->|"HTTPS/JSON"| DeleteAPI
    Browser -->|"CDN"| Static

    AppRouter -->|"uses NextAuth"| NextAuth
    NextAuth -->|"OAuth/REST"| OAuth
    AppRouter -->|"fetch presence"| Lanyard
    LanyardHook -->|"REST/JSON"| Lanyard

    AuthAPI -->|"SQL Queries"| PrismaClient
    GuestbookAPI -->|"SQL Queries"| PrismaClient
    DeleteAPI -->|"SQL Queries"| PrismaClient
    AppRouter -->|"SQL Queries"| PrismaClient
    PrismaClient -->|"TCP/SQL"| DB

    Vercel -->|"Hosts & CDN"| AppRouter
    Vercel -->|"Hosts & CDN"| AuthAPI
    Vercel -->|"Hosts & CDN"| GuestbookAPI
    Vercel -->|"Hosts & CDN"| DeleteAPI
    Vercel -->|"Hosts & CDN"| Static

    %% Click Events
    click Static "https://github.com/thienguen/website/tree/main/public/"
    click AppRouter "https://github.com/thienguen/website/tree/main/src/app/"
    click AuthAPI "https://github.com/thienguen/website/blob/main/src/app/api/auth/[...nextauth]/route.ts"
    click GuestbookAPI "https://github.com/thienguen/website/blob/main/src/app/api/guestbooks/route.ts"
    click DeleteAPI "https://github.com/thienguen/website/blob/main/src/app/api/delete/route.ts"
    click Middleware "https://github.com/thienguen/website/blob/main/src/middleware.ts"
    click NextAuth "https://github.com/thienguen/website/tree/main/src/lib/nextauth/"
    click PrismaClient "https://github.com/thienguen/website/blob/main/src/lib/prisma.ts"
    click DB "https://github.com/thienguen/website/blob/main/prisma/schema.prisma"
    click LanyardHook "https://github.com/thienguen/website/blob/main/src/hooks/lanyard/usePresence.ts"
    click UI "https://github.com/thienguen/website/tree/main/src/components/ui/"
    click GuestbookUI "https://github.com/thienguen/website/tree/main/src/components/guestbook/"
    click DashboardUI "https://github.com/thienguen/website/tree/main/src/components/dashboard/"
    click NavbarUI "https://github.com/thienguen/website/tree/main/src/components/navbar/"
    click Hooks "https://github.com/thienguen/website/tree/main/src/hooks/"

    %% Styles
    classDef client fill:#D0E8FF,stroke:#004080
    classDef static fill:#CFE2F3,stroke:#073763
    classDef frontend fill:#E2F0D9,stroke:#4F772D
    classDef middleware fill:#FFF2CC,stroke:#7F6000
    classDef auth fill:#D9EAD3,stroke:#27632A
    classDef api fill:#B6D7A8,stroke:#38761D
    classDef dbclient fill:#F9CB9C,stroke:#B45F06
    classDef database fill:#F4CCCC,stroke:#CC0000,stroke-width:2px
    classDef external fill:#E7E6E6,stroke:#666666
    classDef ui fill:#FCE5CD,stroke:#CC5500
    classDef hooks fill:#EAD1DC,stroke:#98004D
```
