# preactjs/preact-www architecture

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

- Interactive diagram: https://gitdiagram.com/preactjs/preact-www
- Repository: https://github.com/preactjs/preact-www

## Overview

##### Project type and purpose
- This is a documentation website for Preact (preactjs.com).
- It’s essentially a static-site generator (SSG) with a Preact-based client, a Vite build pipeline, markdown pre-compilation plugins, and a few serverless lambdas for dynamic data (e.g. GitHub repo info, release notes).
- Its primary use case is to transform the multi-language markdown in `content/` into a fully pre-rendered site, deploy it (Netlify), and hydrate it in the browser for search, routing, and interactivity.

##### File structure
- Top-level:
- `content/` – multi-locale markdown source
- `src/` – the Preact application (components, controllers, assets, lambdas)
- `plugins/` – markdown and routing middleware
- build & config files (`package.json`, `vite.config.js`)
- deployment configs (`netlify.js` in `plugins/`, PWA headers, redirects)
- Patterns & architectural hints:
- SSG pipeline: markdown → precompile plugin → JSON/JSX → Vite rollup → static HTML + bundled JS
- Client-side hydration: Preact components in `src/components` + routers in `src/routes.jsx`
- Serverless functions in `src/lambda` for dynamic data

##### README for additional insights
- Confirms: repo auto-deploys master to preactjs.com, invites contributions, runtime is purely static with a few lambdas.

##### Essential details without over-splitting
- But separate build vs. deploy vs. runtime
- Two serverless functions as a distinct “Dynamic Data” tier
- Client hydration and SPA fallback logic

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Layer 1: Content & Plugins
    subgraph "Content & Plugins"
        direction TB
        Content["Markdown Source"]:::content
        subgraph "Pre-compile Plugins"
            direction TB
            MDParser["Markdown Parser"]:::plugin
            Emoji["GitHub Emoji Plugin"]:::plugin
            RSS["RSS Feed Plugin"]:::plugin
            Routing["HTML Routing Middleware"]:::plugin
            SPAFallback["SPA Fallback Middleware"]:::plugin
            NetlifyPlugin["Netlify Config Plugin"]:::plugin
        end
    end

    %% Layer 2: Build Pipeline
    subgraph "Build Pipeline"
        direction TB
        ViteRollup["Vite + Rollup"]:::build
    end

    %% Layer 3: Output Artifacts
    subgraph "Output Artifacts"
        direction TB
        HTML["Static HTML/CSS/JS Bundles\n(index.html)"]:::deploy
        Headers["_headers"]:::deploy
        Redirects["_redirects"]:::deploy
    end

    %% Layer 4: Deploy & CDN
    subgraph "Deployment"
        direction TB
        Netlify["Netlify"]:::deploy
        CDN["CDN/Edge Cache"]:::deploy
    end

    %% Serverless Lambdas
    subgraph "Serverless Functions"
        direction TB
        RepoLambda["Netlify Function: repo.js"]:::build
        ReleaseLambda["Netlify Function: release.js"]:::build
    end

    %% Layer 5: Browser & Runtime
    subgraph "Browser Runtime"
        direction TB
        Browser["Browser"]:::client
        subgraph "Client Application"
            direction TB
            Entry["Entry Point (src/index.jsx)"]:::client
            Routes["Routes Definition (src/components/routes.jsx)"]:::client
            Components["UI Components (src/components/)"]:::client
        end
        subgraph "Runtime Helpers"
            direction TB
            GitHubAPI["GitHub API Wrapper"]:::client
            PrerenderData["Prerender Data Utility"]:::client
            Analytics["Analytics Integration"]:::client
        end
        ExternalGitHub["GitHub API"]:::external
        ExternalAnalytics["Analytics Service"]:::external
    end

    %% Connections: Build Stage
    Content -->|feeds markdown| MDParser
    MDParser --> Emoji
    Emoji --> RSS
    RSS --> Routing
    Routing --> SPAFallback
    SPAFallback --> NetlifyPlugin
    NetlifyPlugin -->|configures| ViteRollup

    %% Build to Artifacts
    ViteRollup -->|generates| HTML
    ViteRollup -->|generates| Headers
    ViteRollup -->|generates| Redirects

    %% Deploy
    HTML --> Netlify
    Headers --> Netlify
    Redirects --> Netlify
    RepoLambda --> Netlify
    ReleaseLambda --> Netlify
    Netlify --> CDN

    %% Runtime
    CDN --> Browser
    Browser --> Entry
    Entry --> Routes
    Routes --> Components
    Browser -->|"calls"| RepoLambda
    Browser -->|"calls"| ReleaseLambda
    RepoLambda -->|fetches| ExternalGitHub
    ReleaseLambda -->|fetches| ExternalGitHub
    Browser -->|sends| Analytics
    Analytics --> ExternalAnalytics

    %% Click Events
    click Content "https://github.com/preactjs/preact-www/tree/master/content/"
    click MDParser "https://github.com/preactjs/preact-www/blob/master/plugins/precompile-markdown/index.js"
    click Emoji "https://github.com/preactjs/preact-www/blob/master/plugins/precompile-markdown/gh-emoji/index.js"
    click RSS "https://github.com/preactjs/preact-www/blob/master/plugins/rss-feed.js"
    click Routing "https://github.com/preactjs/preact-www/blob/master/plugins/html-routing-middleware.js"
    click SPAFallback "https://github.com/preactjs/preact-www/blob/master/plugins/spa-fallback-middleware.js"
    click NetlifyPlugin "https://github.com/preactjs/preact-www/blob/master/plugins/netlify.js"
    click ViteRollup "https://github.com/preactjs/preact-www/blob/master/vite.config.js"
    click ViteRollup "https://github.com/preactjs/preact-www/blob/master/package.json"
    click HTML "https://github.com/preactjs/preact-www/blob/master/index.html"
    click Headers "https://github.com/preactjs/preact-www/tree/master/src/assets/_headers"
    click Redirects "https://github.com/preactjs/preact-www/tree/master/src/assets/_redirects"
    click RepoLambda "https://github.com/preactjs/preact-www/blob/master/src/lambda/repo.js"
    click ReleaseLambda "https://github.com/preactjs/preact-www/blob/master/src/lambda/release.js"
    click Entry "https://github.com/preactjs/preact-www/blob/master/src/index.jsx"
    click Routes "https://github.com/preactjs/preact-www/blob/master/src/components/routes.jsx"
    click Components "https://github.com/preactjs/preact-www/tree/master/src/components/"
    click GitHubAPI "https://github.com/preactjs/preact-www/blob/master/src/lib/github.js"
    click PrerenderData "https://github.com/preactjs/preact-www/blob/master/src/lib/prerender-data.jsx"
    click Analytics "https://github.com/preactjs/preact-www/blob/master/src/analytics.js"

    %% Styles
    classDef content fill:#D0E8FF,stroke:#4A90E2,color:#000
    classDef plugin fill:#FFE3B3,stroke:#F5A623,color:#000
    classDef build fill:#FFF4D0,stroke:#F8E71C,color:#000
    classDef deploy fill:#DFF4D0,stroke:#7ED321,color:#000
    classDef client fill:#F0E0FF,stroke:#9013FE,color:#000
    classDef external fill:#E5E5E5,stroke:#9B9B9B,color:#000
```
