# devashish2006/speakhier architecture

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

- Interactive diagram: https://gitdiagram.com/devashish2006/speakhier
- Repository: https://github.com/devashish2006/speakhier

## Overview

##### Project type and purpose
- This is a full-stack Web application built with Next.js (App Router) that serves React pages and also exposes a small API (`app/api/set-admin/route.js`).
- It includes server-side rendering (SSR), client-side React components, middleware for request handling, and static assets under `/public`.

##### File structure
- Top-level:
– `app/` – Next.js App Router directory that contains pages (server & client components), API handlers, shared layout, globals.css.
– Config files – `next.config.ts`, `tsconfig.json`, `postcss.config.mjs`, `eslint.config.mjs`, `middleware.ts`.
- Within `app/`:
– `InterviewAgent/` – a self-contained page and React component (TSX).
– `api/set-admin/route.js` – a serverless function to elevate a user to admin.
– `sign-in/` and `unauthorized/` – auth-related routes and pages.
– `layout.tsx` and `globals.css` – shared page chrome, styles.

##### README for extra context
- Bootstrapped with `create-next-app`.
- Uses next/font for optimized font loading.
- No built-in database is present—API routes likely call external services (e.g., a database or auth provider).

##### Main components
a. Client (Browser) – desktop/mobile users running React components in the browser.
b. Next.js Server – Node.js environment (hosted on Vercel or similar) responsible for:
- Routing & Middleware – `middleware.ts` intercepts requests (e.g., auth checks).
- Page rendering – server components vs. client components (`app/page.tsx`, `app/debug/page.tsx`, `app/InterviewAgent/page.tsx`).
- API routes – `app/api/set-admin/route.js`.
- Static asset serving – any file under `/public` plus CSS from `globals.css`.
c. External Services –
- Authentication provider (e.g., NextAuth or custom) used by the sign-in flow.
- Database or data store used by the API route `set-admin`.
- Font CDN (served by next/font).

##### Relationships & data flow
- Browser → HTTP request → Next.js Server (via Vercel CDN/Edge)
- Middleware inspects and potentially reroutes to `/unauthorized` or `/sign-in`.
- Router dispatches to:
– Page handlers: perform SSR or SSG, return HTML + JS bundle.
– API handlers: perform business logic (e.g., update user role), return JSON.
- Server then responds with rendered HTML or JSON, and the browser hydrates the React app.
- Static assets (CSS, fonts, images) served directly from `/public` or Vercel’s asset CDN.
- Next/font fetches fonts from Vercel’s font service at build time or runtime.

##### Architectural patterns & design principles
- File-based routing – one folder = one route.
- Serverless functions – each API route is its own lambda.
- Server vs. Client components – leveraging Next.js App Router.
- Shared layout / global styles – separation of concerns between layout and page content.

##### Technologies, frameworks & libraries
- Next.js (App Router)
- React (with Server & Client Components)
- TypeScript / JavaScript
- PostCSS (via `postcss.config.mjs`)
- ESLint (via `eslint.config.mjs`)
- Vercel Platform (for deployment & edge middleware)
- next/font (for font optimization)

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Layers
    subgraph "Client Layer"
        Browser["Client: Browser / React"]:::client
    end

    subgraph "Edge/Middleware Layer"
        Middleware["middleware.ts"]:::middleware
    end

    subgraph "Next.js Application Layer"
        subgraph "Layout & Styles"
            Layout["layout.tsx"]:::layout
            Styles["globals.css"]:::styles
        end

        subgraph "Pages (SSR/SSG)"
            Home["Home Page (page.tsx)"]:::page
            Debug["Debug Page (debug/page.tsx)"]:::page
            InterviewAgentPage["InterviewAgent Page (InterviewAgent/page.tsx)"]:::page
            InterviewAgentComp["InterviewAgent Component (InterviewAgent.tsx)"]:::component
            SignIn["Sign-In Page (sign-in/page.tsx)"]:::page
            Unauthorized["Unauthorized Page (unauthorized/page.tsx)"]:::page
        end

        subgraph "API Routes"
            SetAdmin["/api/set-admin (route.js)"]:::api
        end

        subgraph "Public Assets"
            Public["public/"]:::assets
        end

        subgraph "Configuration"
            NextConfig["next.config.ts"]:::config
            TSConfig["tsconfig.json"]:::config
            PostCSS["postcss.config.mjs"]:::config
            ESLint["eslint.config.mjs"]:::config
        end
    end

    subgraph "External Services"
        Auth["Auth Provider"]:::external
        DB["Database / Data Store"]:::external
        CDN["Vercel CDN / Asset CDN"]:::external
        FontService["Font CDN / next/font"]:::external
    end

    %% Data Flow
    Browser -->|"HTTP Request"| Middleware
    Middleware -->|"Route Check"| Home
    Middleware -->|"Route Check"| Debug
    Middleware -->|"Route Check"| InterviewAgentPage
    Middleware -->|"Route Check"| SignIn
    Middleware -->|"Route Check"| Unauthorized
    Middleware -->|"Route Check"| SetAdmin

    Home -->|"Render via layout"| Layout
    Debug -->|"Render via layout"| Layout
    InterviewAgentPage -->|"Render & hydrate component"| InterviewAgentComp
    InterviewAgentPage -->|"Render via layout"| Layout
    SignIn -->|"Auth flow"| Auth
    Unauthorized -->|"Page Response"| Browser

    SetAdmin -->|"POST JSON"| DB

    Browser -->|"GET assets"| Public
    Browser -->|"GET assets"| CDN
    Layout -->|"Includes fonts"| FontService

    %% Click Events
    click Middleware "https://github.com/devashish2006/speakhier/blob/main/middleware.ts"
    click Layout "https://github.com/devashish2006/speakhier/blob/main/app/layout.tsx"
    click Styles "https://github.com/devashish2006/speakhier/blob/main/app/globals.css"
    click Home "https://github.com/devashish2006/speakhier/blob/main/app/page.tsx"
    click Debug "https://github.com/devashish2006/speakhier/blob/main/app/debug/page.tsx"
    click InterviewAgentPage "https://github.com/devashish2006/speakhier/blob/main/app/InterviewAgent/page.tsx"
    click InterviewAgentComp "https://github.com/devashish2006/speakhier/blob/main/app/InterviewAgent/InterviewAgent.tsx"
    click SignIn "https://github.com/devashish2006/speakhier/blob/main/app/sign-in/[[...sign-in]]/page.tsx"
    click Unauthorized "https://github.com/devashish2006/speakhier/blob/main/app/unauthorized/page.tsx"
    click SetAdmin "https://github.com/devashish2006/speakhier/blob/main/app/api/set-admin/route.js"
    click Public "https://github.com/devashish2006/speakhier/tree/main/public/"
    click NextConfig "https://github.com/devashish2006/speakhier/blob/main/next.config.ts"
    click TSConfig "https://github.com/devashish2006/speakhier/blob/main/tsconfig.json"
    click PostCSS "https://github.com/devashish2006/speakhier/blob/main/postcss.config.mjs"
    click ESLint "https://github.com/devashish2006/speakhier/blob/main/eslint.config.mjs"

    %% Styles
    classDef client fill:#AEDFF7,stroke:#0366d6,color:#0366d6,stroke-width:1px;
    classDef middleware fill:#FBE7C6,stroke:#E69A00,color:#E69A00,stroke-width:1px;
    classDef layout fill:#D5F5E3,stroke:#27AE60,color:#27AE60,stroke-width:1px;
    classDef styles fill:#E8DAEF,stroke:#8E44AD,color:#8E44AD,stroke-width:1px;
    classDef page fill:#FDEBD0,stroke:#D35400,color:#D35400,stroke-width:1px;
    classDef component fill:#D6EAF8,stroke:#2980B9,color:#2980B9,stroke-width:1px;
    classDef api fill:#FADBD8,stroke:#C0392B,color:#C0392B,stroke-width:1px;
    classDef assets fill:#E9F7EF,stroke:#239B56,color:#239B56,stroke-width:1px;
    classDef config fill:#F4F6F7,stroke:#7F8C8D,color:#7F8C8D,stroke-width:1px;
    classDef external fill:#FEF9E7,stroke:#B7950B,color:#B7950B,stroke-width:1px;
```
