# Technologies & Architecture This document provides an overview of the technologies used in the Node.js website and explains key architectural decisions. ## Table of Contents - [Core Technologies](#core-technologies) - [Frontend Framework](#frontend-framework) - [Why Next.js?](#why-nextjs) - [Styling System](#styling-system) - [PostCSS Plugins](#postcss-plugins) - [Content Management](#content-management) - [Content Processing Plugins](#content-processing-plugins) - [Search](#search) - [UI Components](#ui-components) - [Why Radix UI?](#why-radix-ui) - [Internationalization](#internationalization) - [Development Tools](#development-tools) - [Repository Structure](#repository-structure) - [Architecture Decisions](#architecture-decisions) - [Static Build Support](#static-build-support) - [Custom Page Rendering](#custom-page-rendering) - [`[...path].tsx` - Dynamic Route Handler](#pathts---dynamic-route-handler) - [`next.dynamic.mjs` - Page Generation](#nextdynamicmjs---page-generation) - [`next.data.mjs` - Build-time Data](#nextdatamjs---build-time-data) - [Internationalization Strategy](#internationalization-strategy) - [Why Not Next.js Built-in i18n?](#why-not-nextjs-built-in-i18n) - [Locale Detection and Routing](#locale-detection-and-routing) - [Content Structure](#content-structure) - [Layouts System](#layouts-system) - [Content Processing Pipeline](#content-processing-pipeline) - [Rewrite and Redirect System](#rewrite-and-redirect-system) - [`next.rewrites.mjs`](#nextrewritesmjs) - [`redirects.json`](#redirectsjson) - [Configuration Files](#configuration-files) - [`site.json`](#sitejson) - [Development Environment](#development-environment) - [VSCode Configuration](#vscode-configuration) - [Build and Deployment](#build-and-deployment) - [Multiple Build Targets](#multiple-build-targets) - [Vercel Integration](#vercel-integration) - [Package Management](#package-management) - [Multi-package Workspace](#multi-package-workspace) - [Publishing Process](#publishing-process) - [Performance Optimizations](#performance-optimizations) - [Static Generation](#static-generation) - [Bundle Optimization](#bundle-optimization) - [Image Optimization](#image-optimization) - [Testing Infrastructure](#testing-infrastructure) - [Visual Regression Testing](#visual-regression-testing) - [End-to-End Testing](#end-to-end-testing) ## Core Technologies ### Frontend Framework The Node.js Website is built with [React](https://react.dev/) and [Next.js](https://nextjs.org/): - **React**: UI rendering engine for component-based development - **Next.js**: Full-stack framework providing SSG, routing, and build optimization #### Why Next.js? We chose Next.js because it is: - Versatile and hackable for custom requirements - Stable with strong community maintenance - Well-suited as a long-term framework choice - Capable of supporting static builds (a requirement from the Node.js Technical Steering Committee) ### Styling System - **[PostCSS](https://postcss.org/)**: CSS preprocessing with plugin-based architecture - **[Tailwind CSS](https://tailwindcss.com/)**: Utility-first CSS framework and design system foundation - **CSS Modules**: Scoped styling for components #### PostCSS Plugins - `postcss-calc`: Resolves `calc()` expressions at build time - `@tailwindcss/postcss`: Enables Tailwind integration ### Content Management - **[MDX](https://mdxjs.com/)**: Markdown with JSX component support - **[Remark](https://github.com/remarkjs/remark)**: Markdown processing plugins - **[Rehype](https://github.com/rehypejs/rehype)**: HTML processing plugins #### Content Processing Plugins - `remark-gfm`: GitHub Flavored Markdown support - `remark-headings`: Generates metadata for table of contents - `rehype-autolink-headings`: Automatic anchor links for headings - `rehype-slug`: Automatic ID generation for headings ### Search - **[Orama](https://orama.com/)**: Local full-text search engine used for site search - Prebuilt Learn and API documentation indexes are fetched client-side and merged into a single local search database - Search remains self-contained in the site deployment without depending on Orama Cloud at runtime ### UI Components - **[Radix UI](https://www.radix-ui.com/)**: Accessible, unstyled component primitives - **[Hero Icons](https://heroicons.com/)**: SVG icon library - **[Shiki](https://github.com/shikijs/shiki)**: Syntax highlighting for code blocks #### Why Radix UI? - Minimalistic, component-focused approach - Built-in WAI-ARIA and accessibility features - Allows focus on design without accessibility implementation overhead - Modular package structure ### Internationalization - **[`next-intl`](https://next-intl-docs.vercel.app)**: i18n library with Next.js integration - **[ICU Message Syntax](https://next-intl.dev/docs/usage/messages)**: Translation message format ### Development Tools - **[Storybook](https://storybook.js.org/)**: Component development and visual testing - **[Chromatic](https://www.chromatic.com/)**: Automated visual regression testing - **[Husky](https://typicode.github.io/husky/)**: Git hooks for code quality ## Repository Structure ``` nodejs.org/ ├── apps/ │ └── site/ # Main website application │ ├── components/ # Website-specific React components │ ├── layouts/ # Page layout templates │ ├── pages/ # Content pages (Markdown/MDX) │ │ ├── en/ # English content (source) │ │ └── {locale}/ # Translated content │ ├── public/ # Static assets │ │ └── static/ # Images, documents, etc. │ ├── hooks/ # React hooks │ ├── providers/ # React context providers │ ├── types/ # TypeScript definitions │ ├── next-data/ # Build-time data fetching │ ├── scripts/ # Utility scripts │ ├── snippets/ # Code snippets for download page │ └── tests/ # Test files │ └── e2e/ # End-to-end tests └── packages/ ├── ui-components/ # Reusable UI components │ ├── styles/ # Global stylesheets │ └── .storybook/ # Storybook configuration ├── i18n/ # Internationalization │ ├── locales/ # Translation files │ └── config.json # Locale configuration ├── rehype-shiki/ # Syntax highlighting plugin ... ``` ## Architecture Decisions ### Static Build Support The website supports fully static builds to ensure independence from third-party services: - Content can be served without external dependencies - Maintains availability even if hosting providers change ### Custom Page Rendering The website uses a custom rendering system instead of Next.js default routing: #### `[...path].tsx` - Dynamic Route Handler - Catches all routes and renders them through a custom system - Enables dynamic page generation from Markdown files - Supports incremental static generation (ISG) #### `next.dynamic.mjs` - Page Generation This file handles: - Discovering all source pages in `apps/site/pages/en` - Identifying translated pages - Generating localized paths for untranslated content - Creating fallback pages that show English content with translated menus and UI elements #### `next.data.mjs` - Build-time Data Responsible for: - Node.js release data fetching - Blog post metadata generation - RSS feed creation - Build-time indexing ### Internationalization Strategy #### Why Not Next.js Built-in i18n? We use a custom i18n solution because: - Need comprehensive locale and page listing capabilities - Use subfolder content structure (`/pages/en/`, `/pages/fr/`) vs. extension-based (`file.en.md`) - Maintain consistency with previous website structure - Ensure long-term maintainability #### Locale Detection and Routing - `next.middleware.js`: Handles browser locale detection and redirects - Falls back to `/en` for unsupported locales - Provides seamless user experience across languages ### Content Structure #### Layouts System ```typescript // Each page specifies its layout in frontmatter --- title: Page Title layout: layout-name --- // Layouts wrap content and provide structure const Layout: FC<{ children: ReactNode }> = ({ children }) => (