# yangxinhan/myweb architecture

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

- Interactive diagram: https://gitdiagram.com/yangxinhan/myweb
- Repository: https://github.com/yangxinhan/myweb

## Overview

##### Project type and its purpose
- Full-stack web application (UI built with Next.js, static-export/SSR hybrid)
- Purpose: A personal portfolio/blog/solutions site with static content, MDX posts, dynamic data from GitHub, styled via Tailwind CSS

##### File structure for architectural clues
- Root configuration & infra
– Dockerfile + docker-compose.yml: multi-stage build, container definition
– nginx.conf: static assets & SSR proxy
– .github/workflows/deploy.yml: CI/CD pipeline on push
– crontab + fetch-updates.sh: periodic data-fetching (e.g., GitHub projects)
- Build output
– out/: static HTML, JS, CSS artifacts from `next export`
- Source code
– src/app/: Next.js App Router pages and layouts
– src/components/ui/: reusable React UI components
– src/data, src/lib, src/utils: data sources, MDX parsing, utility functions

##### README for additional insights
- Next.js App Router, static export & dev server
- next/font integration for Geist font
- Deployment target: Vercel (but overridden by Docker+Nginx here)

##### Main components & their interactions
a. Developer workstation
– Edits code, runs `npm run dev` → Next.js dev server
– Commits to GitHub repo
b. CI/CD (GitHub Actions)
– On push, runs build, lint, tests; builds Docker image; pushes to registry or deploys
c. Build stage (Docker multi-stage)
– Stage 1: `npm install` + `npm run build` → generates `.next` and `out/`
– Stage 2: Nginx container copies `out/` and proxies dynamic routes to Node (or purely serves static)
– crontab container executes `fetch-updates.sh` periodically to update JSON data
d. Runtime
– Nginx: serves `/static`, `/_next`, and proxies API/SSR requests to Node server
– Node.js: hosts Next.js server for any SSR/page-hooks, MDX rendering on the fly if needed
– External services: GitHub REST API (for project list), font CDN, analytics

##### Architectural patterns & principles
- Static Site Generation (SSG) + selective SSR via Next.js App Router
- Component-driven UI (atomic React components under src/components/ui)
- Containerization & immutable infrastructure (Docker + Nginx)
- CI/CD with GitOps (GitHub Actions drives build/deploy)
- Cron/data-fetch sidecar for periodic external updates

[ ] All major components labeled
[ ] External dependencies clearly shown
[ ] Build vs. runtime separated

## Diagram (Mermaid)

```mermaid
flowchart TD
  %% Development Layer
  subgraph "Development" 
    direction TB
    Dev["Developer Workstation"]:::dev
    Codebase["Code Repository"]:::dev
    Dev -->|edits code & runs dev server| Codebase
  end

  %% CI/CD Layer
  subgraph "CI/CD Pipeline" 
    direction TB
    GitHub["GitHub Repo"]:::cicd
    Actions["GitHub Actions"]:::cicd
    Codebase -->|push| GitHub
    GitHub -->|triggers| Actions
    Actions -->|build, lint, test| DockerBuild
  end

  %% Build Artifacts
  subgraph "Build" 
    direction TB
    DockerBuild["Docker Multi-Stage Build"]:::build
    Artifacts["Static Build Output (out/)"]:::artifacts
    DockerBuild -->|generates| Artifacts
  end

  %% Runtime Layer
  subgraph "Runtime"
    direction TB
    Nginx["Nginx Reverse Proxy"]:::runtime
    Node["Node.js Server"]:::runtime
    Cron["Cron/Data-Fetch Scheduler"]:::runtime
    Artifacts -->|serves static| Nginx
    Nginx -->|proxy SSR| Node
    Cron -->|fetches data| GitHubAPI
  end

  %% External Services
  subgraph "External Services"
    direction TB
    GitHubAPI["GitHub REST API"]:::external
    CDN["Font & Analytics CDN"]:::external
    Browser["User Browser"]:::external
    Browser -->|HTTP requests| Nginx
    Nginx -->|fetch fonts/analytics| CDN
    Node -->|calls| GitHubAPI
  end

  %% Source Code Structure
  subgraph "Source Code" 
    direction TB
    AppRouter["Next.js App Router (src/app/)"]:::source
    UIComps["UI Components (src/components/ui/)"]:::source
    MDX["MDX Pipeline (src/lib/mdx.ts, posts/*.mdx)"]:::source
    DataSrc["Data Sources (src/data/home-data.ts)"]:::source
    Utils["Utils (src/utils/cn.ts)"]:::source
    Configs["Config Files"]:::source
    Public["Public Assets (public/)"]:::source
    Package["Package Scripts (package.json)"]:::source

    Codebase --> AppRouter
    Codebase --> UIComps
    Codebase --> MDX
    Codebase --> DataSrc
    Codebase --> Utils
    Codebase --> Configs
    Codebase --> Public
    Codebase --> Package
  end

  %% Config & Orchestration
  subgraph "Infrastructure Config"
    direction TB
    Dockerfile["Dockerfile"]:::infra
    Compose["docker-compose.yml"]:::infra
    NginxConf["nginx.conf"]:::infra
    CIConfig[".github/workflows/deploy.yml"]:::infra
    CronFiles["crontab & fetch-updates.sh"]:::infra
    Codebase --> Dockerfile
    Codebase --> Compose
    Codebase --> NginxConf
    Codebase --> CIConfig
    Codebase --> CronFiles
  end

  %% Connections
  DockerBuild -->|uses| Dockerfile
  DockerBuild -->|uses| Compose
  Nginx -->|config| NginxConf
  Actions -->|uses| CIConfig
  Cron -->|script| CronFiles

  %% Click Events
  click Dockerfile "https://github.com/yangxinhan/myweb/tree/main/Dockerfile"
  click Compose "https://github.com/yangxinhan/myweb/blob/main/docker-compose.yml"
  click NginxConf "https://github.com/yangxinhan/myweb/blob/main/nginx.conf"
  click CIConfig "https://github.com/yangxinhan/myweb/blob/main/.github/workflows/deploy.yml"
  click CronFiles "https://github.com/yangxinhan/myweb/tree/main/crontab"
  click CronFiles "https://github.com/yangxinhan/myweb/blob/main/fetch-updates.sh"
  click Artifacts "https://github.com/yangxinhan/myweb/tree/main/out/"
  click AppRouter "https://github.com/yangxinhan/myweb/tree/main/src/app/"
  click UIComps "https://github.com/yangxinhan/myweb/tree/main/src/components/ui/"
  click MDX "https://github.com/yangxinhan/myweb/blob/main/src/lib/mdx.ts"
  click MDX "https://github.com/yangxinhan/myweb/blob/main/posts/example.mdx"
  click DataSrc "https://github.com/yangxinhan/myweb/blob/main/src/data/home-data.ts"
  click Utils "https://github.com/yangxinhan/myweb/blob/main/src/utils/cn.ts"
  click Configs "https://github.com/yangxinhan/myweb/blob/main/next.config.js"
  click Public "https://github.com/yangxinhan/myweb/tree/main/public/"
  click Package "https://github.com/yangxinhan/myweb/blob/main/package.json"

  %% Styles
  classDef dev fill:#e8f5e9,stroke:#2e7d32,color:#1b5e20;
  classDef cicd fill:#fff3e0,stroke:#ff8f00,color:#e65100;
  classDef build fill:#eceff1,stroke:#607d8b,color:#263238;
  classDef artifacts fill:#cfd8dc,stroke:#455a64,color:#263238;
  classDef runtime fill:#e3f2fd,stroke:#1976d2,color:#0d47a1;
  classDef external fill:#f3e5f5,stroke:#7b1fa2,color:#4a148c;
  classDef source fill:#f9fbe7,stroke:#afb42b,color:#827717;
  classDef infra fill:#fffde7,stroke:#f9a825,color:#f57f17;
```
