# yaodebian/human-hormones architecture

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

- Interactive diagram: https://gitdiagram.com/yaodebian/human-hormones
- Repository: https://github.com/yaodebian/human-hormones

## Overview

##### Project Type and Purpose
- This is a full-stack (front-end heavy) Next.js 13 application using the App Router for server-side rendering (SSR), static-site generation (SSG), and client hydration.
- Its primary function is to serve localized educational content about hormones (cortisol, dopamine, etc.) in multiple languages.

##### Top-Level Architecture Components
a. Client (Browser / Mobile)
b. CDN / Edge Layer (e.g., Vercel)
c. Next.js Application Server
- App Router (app/[locale]/… pages)
- Route Handlers & Layouts
- Server Components (data-fetching, SSR/SSG)
- Client Components (interactive UI bits)
d. Internationalization Module (lib/i18n)
e. React Component Library
- UI primitives (components/ui)
- Common design blocks (components/common)
- Page-specific containers (components/pages, components/home)
f. Static Assets
- Images (public/images/…)
- CSS (tailwind.config.ts, globals.css)
- Fonts (via next/font)
- UI-design prototypes (UI-design/…)
g. Build & Config
- next.config.ts, postcss.config.mjs, tsconfig.json
- ESLint config, package.json, pnpm-lock.yaml

##### Component Relationships and Data Flow
- The Browser issues HTTP requests → routed through CDN/Edge → forwarded to Next.js Server.
- Next.js App Router matches `/{locale}/{page}` → loads server layout (app/[locale]/layout.tsx) → resolves translations from lib/i18n using language-store → fetches or generates page props → renders Server Components.
- On the client, React hydrates interactive components (language-switcher, sheet, button) pulled from components/ui.
- Static assets (images, CSS) are served directly by the CDN.
- Tailwind CSS and next/font optimize styles and fonts at build time.

##### Architectural Patterns and Design Principles
- “Component-based” front-end: clear separation between UI primitives, common patterns, and page containers.
- i18n context/provider pattern: language-store + language-context for dynamic locale injection.
- App Router’s file-based routing for SSR/SSG hybrid pages.
- Static assets and UI-design prototypes decoupled from runtime code.

- Clear labels (e.g., “Next.js App Router,” “lib/i18n translation store”).
- Notes for “Server Components” vs. “Client Components” boundary.

## Diagram (Mermaid)

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

    subgraph "CDN / Edge Layer"
        CDN(("Vercel CDN / Edge")):::external
    end

    subgraph "Next.js Server"  
        direction TB

        Routing["App Router<br/>(app/[locale])"]:::server
        Layouts["Layouts & Server Components<br/>(app/[locale]/layout.tsx)"]:::server
        subgraph "Page Server Components"
            direction TB
            HomePage["home page<br/>(app/[locale]/page.tsx)"]:::server
            CortisolPage["cortisol page<br/>(app/[locale]/cortisol/page.tsx)"]:::server
            DopaminePage["dopamine page<br/>(app/[locale]/dopamine/page.tsx)"]:::server
            EndorphinPage["endorphin page<br/>(app/[locale]/endorphin/page.tsx)"]:::server
            OxytocinPage["oxytocin page<br/>(app/[locale]/oxytocin/page.tsx)"]:::server
            SerotoninPage["serotonin page<br/>(app/[locale]/serotonin/page.tsx)"]:::server
            ResourcesPage["resources page<br/>(app/[locale]/resources/page.tsx)"]:::server
        end

        subgraph "i18n Module"
            direction TB
            I18nModule["lib/i18n"]:::server
            LanguageContext["language-context.tsx"]:::server
            LanguageStore["language-store.ts"]:::server
            TranslationStore[(Translation Stores)]:::static
        end

        subgraph "Component Library"
            direction TB
            subgraph "UI Primitives"
                direction TB
                Button["button.tsx"]:::client
                Container["container.tsx"]:::client
                Input["input.tsx"]:::client
                LanguageSwitcher["language-switcher.tsx"]:::client
                Select["select.tsx"]:::client
                Sheet["sheet.tsx"]:::client
            end
            subgraph "Common Design Blocks"
                CommonBlocks["components/common"]:::client
            end
            subgraph "Page Containers"
                PageContainers["components/pages"]:::client
                HomeContainers["components/home"]:::client
            end
        end

        subgraph "Styles & Fonts Pipeline"
            direction TB
            Tailwind["Tailwind CSS<br/>(tailwind.config.ts)"]:::build
            PostCSS["postcss.config.mjs"]:::build
            NextFont["next/font"]:::build
        end
    end

    subgraph "Static Asset Store"
        direction TB
        Images[(Images<br/>public/images/hormones)]:::static
        GlobalsCSS["globals.css"]:::static
    end

    subgraph "External Services"
        FontsCDN(("Fonts CDN")):::external
        Analytics(("Google Analytics")):::external
    end

    %% Connections
    Browser -->|HTTP GET| CDN
    CDN -->|Forward Request| Routing
    Routing -->|load layout| Layouts
    Layouts -->|render pages| HomePage
    Layouts --> CortisolPage
    Layouts --> DopaminePage
    Layouts --> EndorphinPage
    Layouts --> OxytocinPage
    Layouts --> SerotoninPage
    Layouts --> ResourcesPage

    Routing -->|detect locale| I18nModule
    I18nModule --> LanguageContext
    LanguageContext --> LanguageStore
    I18nModule --> TranslationStore

    HomePage -->|uses| Button
    HomePage --> Container
    HomePage --> LanguageSwitcher
    HomePage --> CommonBlocks
    CortisolPage -->|uses| CommonBlocks

    PageContainers -->|use primitives| UIPrimitives
    HomeContainers --> UIPrimitives

    Tailwind -.-> GlobalsCSS
    NextFont -.-> FontsCDN

    Browser -->|hydrate interactive| Button
    Browser --> Container
    Browser --> Sheet

    Browser -->|fetch static assets| Images
    Browser -->|load styles| GlobalsCSS

    Analytics -.-> Browser

    %% Click Events
    click Routing "https://github.com/yaodebian/human-hormones/tree/main/app/[locale]"
    click Layouts "https://github.com/yaodebian/human-hormones/blob/main/app/[locale]/layout.tsx"
    click HomePage "https://github.com/yaodebian/human-hormones/blob/main/app/[locale]/page.tsx"
    click CortisolPage "https://github.com/yaodebian/human-hormones/blob/main/app/[locale]/cortisol/page.tsx"
    click DopaminePage "https://github.com/yaodebian/human-hormones/blob/main/app/[locale]/dopamine/page.tsx"
    click EndorphinPage "https://github.com/yaodebian/human-hormones/blob/main/app/[locale]/endorphin/page.tsx"
    click OxytocinPage "https://github.com/yaodebian/human-hormones/blob/main/app/[locale]/oxytocin/page.tsx"
    click SerotoninPage "https://github.com/yaodebian/human-hormones/blob/main/app/[locale]/serotonin/page.tsx"
    click ResourcesPage "https://github.com/yaodebian/human-hormones/blob/main/app/[locale]/resources/page.tsx"
    click LanguageModule "https://github.com/yaodebian/human-hormones/tree/main/lib/i18n"
    click LanguageContext "https://github.com/yaodebian/human-hormones/blob/main/lib/i18n/language-context.tsx"
    click LanguageStore "https://github.com/yaodebian/human-hormones/blob/main/lib/store/language-store.ts"
    click TranslationStore "https://github.com/yaodebian/human-hormones/tree/main/lib/i18n/locales"
    click Button "https://github.com/yaodebian/human-hormones/blob/main/components/ui/button.tsx"
    click Container "https://github.com/yaodebian/human-hormones/blob/main/components/ui/container.tsx"
    click Input "https://github.com/yaodebian/human-hormones/blob/main/components/ui/input.tsx"
    click LanguageSwitcher "https://github.com/yaodebian/human-hormones/blob/main/components/ui/language-switcher.tsx"
    click Select "https://github.com/yaodebian/human-hormones/blob/main/components/ui/select.tsx"
    click Sheet "https://github.com/yaodebian/human-hormones/blob/main/components/ui/sheet.tsx"
    click CommonBlocks "https://github.com/yaodebian/human-hormones/tree/main/components/common"
    click PageContainers "https://github.com/yaodebian/human-hormones/tree/main/components/pages"
    click HomeContainers "https://github.com/yaodebian/human-hormones/tree/main/components/home"
    click Images "https://github.com/yaodebian/human-hormones/tree/main/public/images/hormones"
    click GlobalsCSS "https://github.com/yaodebian/human-hormones/blob/main/app/globals.css"
    click Tailwind "https://github.com/yaodebian/human-hormones/blob/main/tailwind.config.ts"
    click PostCSS "https://github.com/yaodebian/human-hormones/blob/main/postcss.config.mjs"
    click NextFont "https://github.com/yaodebian/human-hormones/tree/main/next/font"
    click NextConfig "https://github.com/yaodebian/human-hormones/blob/main/next.config.ts"
    click TSConfig "https://github.com/yaodebian/human-hormones/blob/main/tsconfig.json"
    click Eslint "https://github.com/yaodebian/human-hormones/blob/main/eslint.config.mjs"
    click PackageJSON "https://github.com/yaodebian/human-hormones/blob/main/package.json"
    click Lockfile "https://github.com/yaodebian/human-hormones/blob/main/pnpm-lock.yaml"
    click UIDesign "https://github.com/yaodebian/human-hormones/tree/main/UI-design"

    %% Styles
    classDef client fill:#D6E9F8,stroke:#3B83BD,color:#03396C
    classDef server fill:#E8F0FE,stroke:#5C87E0,color:#1A237E
    classDef build fill:#FFF4E5,stroke:#FFC107,color:#E65100,stroke-dasharray: 5 5
    classDef static fill:#E8F5E9,stroke:#43A047,color:#1B5E20
    classDef external fill:#F3E5F5,stroke:#9C27B0,color:#4A148C,stroke-dasharray: 2 2
    class Browser client
    class CDN external
    class Routing,Layouts,HomePage,CortisolPage,DopaminePage,EndorphinPage,OxytocinPage,SerotoninPage,ResourcesPage,I18nModule,LanguageContext,LanguageStore server
    class TranslationStore,Images,GlobalsCSS static
    class Tailwind,PostCSS,NextFont build
    class FontsCDN,Analytics external
```
