# thaiphan/sitecore-nextjs architecture

> Architecture diagram of the GitHub repository thaiphan/sitecore-nextjs, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-02). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/thaiphan/sitecore-nextjs
- Repository: https://github.com/thaiphan/sitecore-nextjs

## Overview

This is a Next.js-first Sitecore rendering example. Normal page requests fetch Sitecore layout data, then the shared app provides Sitecore context and renders the route through a layout and mapped placeholder components. A separate Experience Editor path accepts rendering-host requests, forwards preview data to the preview page, and returns rendered HTML. The graph focuses on source-backed runtime behavior; the README documents the remote-rendering-host setup, while several framework-level connections are not explicit in sampled source.

Main entry points: [`src/pages/_app.tsx`](https://github.com/thaiphan/sitecore-nextjs/blob/main/src/pages/_app.tsx) (App context), [`src/services/sitecore.ts`](https://github.com/thaiphan/sitecore-nextjs/blob/main/src/services/sitecore.ts) (Route data fetcher), [`src/pages/index.tsx`](https://github.com/thaiphan/sitecore-nextjs/blob/main/src/pages/index.tsx) (Home route), [`src/pages/[...slug].tsx`](https://github.com/thaiphan/sitecore-nextjs/blob/main/src/pages/%5B...slug%5D.tsx) (Dynamic route)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_content["Sitecore content"]
  node_sitecore["Sitecore Layout API"]
  node_route_data["Route data fetcher<br/>[sitecore.ts]"]
end

subgraph group_render["Page rendering"]
  node_app["App context<br/>[_app.tsx]"]
  node_layout["Default layout<br/>[DefaultLayout.tsx]"]
  node_placeholder["JSS placeholder<br/>[DefaultLayout.tsx]"]
  node_content_block["Content block<br/>[ContentBlock.tsx]"]
  node_seo["Page SEO<br/>[_app.tsx]"]
end

subgraph group_preview["Experience Editor preview"]
  node_preview_api["Preview API proxy<br/>[preview.ts]"]
  node_preview_page["Preview page<br/>[preview.tsx]"]
end

subgraph group_routes["Next.js routes"]
  node_home["Home route<br/>[index.tsx]"]
  node_dynamic["Dynamic route<br/>[&#91;...slug&#93;.tsx]"]
  node_not_found["404 route<br/>[404.tsx]"]
end

node_visitor(("Site visitor"))
node_editor(("Sitecore editor"))
node_render_host["Sitecore rendering host"]

node_visitor -->|"requests"| node_home
node_visitor -->|"requests"| node_dynamic
node_home -->|"fetches route"| node_route_data
node_dynamic -->|"fetches route"| node_route_data
node_not_found -->|"fetches route"| node_route_data
node_route_data -->|"requests layout"| node_sitecore
node_home -.->|"provides props"| node_app
node_dynamic -.->|"provides props"| node_app
node_app -->|"renders"| node_layout
node_app -->|"sets metadata"| node_seo
node_layout -->|"renders"| node_placeholder
node_app -->|"registers component"| node_content_block
node_placeholder -.->|"dispatches component"| node_content_block
node_editor -->|"requests preview"| node_render_host
node_render_host -->|"posts rendering data"| node_preview_api
node_preview_api -->|"forwards preview data"| node_preview_page
node_preview_page -->|"returns HTML"| node_render_host

click node_route_data "https://github.com/thaiphan/sitecore-nextjs/blob/main/src/services/sitecore.ts"
click node_home "https://github.com/thaiphan/sitecore-nextjs/blob/main/src/pages/index.tsx"
click node_dynamic "https://github.com/thaiphan/sitecore-nextjs/blob/main/src/pages/%5B...slug%5D.tsx"
click node_not_found "https://github.com/thaiphan/sitecore-nextjs/blob/main/src/pages/404.tsx"
click node_preview_api "https://github.com/thaiphan/sitecore-nextjs/blob/main/src/pages/api/preview.ts"
click node_preview_page "https://github.com/thaiphan/sitecore-nextjs/blob/main/src/pages/preview.tsx"
click node_app "https://github.com/thaiphan/sitecore-nextjs/blob/main/src/pages/_app.tsx"
click node_layout "https://github.com/thaiphan/sitecore-nextjs/blob/main/src/components/templates/DefaultLayout/DefaultLayout.tsx"
click node_placeholder "https://github.com/thaiphan/sitecore-nextjs/blob/main/src/components/templates/DefaultLayout/DefaultLayout.tsx"
click node_content_block "https://github.com/thaiphan/sitecore-nextjs/blob/main/src/components/organisms/ContentBlock/ContentBlock.tsx"
click node_seo "https://github.com/thaiphan/sitecore-nextjs/blob/main/src/pages/_app.tsx"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_sitecore,node_route_data toneBlue
class node_app,node_layout,node_placeholder,node_content_block,node_seo toneAmber
class node_preview_api,node_preview_page toneMint
class node_home,node_dynamic,node_not_found toneRose
class node_visitor,node_editor,node_render_host toneIndigo
```

## Components

### Sitecore content

- **Sitecore Layout API**
- [Route data fetcher](https://github.com/thaiphan/sitecore-nextjs/blob/main/src/services/sitecore.ts): `src/services/sitecore.ts`

### Page rendering

- [App context](https://github.com/thaiphan/sitecore-nextjs/blob/main/src/pages/_app.tsx): `src/pages/_app.tsx`
- [Default layout](https://github.com/thaiphan/sitecore-nextjs/blob/main/src/components/templates/DefaultLayout/DefaultLayout.tsx): `src/components/templates/DefaultLayout/DefaultLayout.tsx`
- [JSS placeholder](https://github.com/thaiphan/sitecore-nextjs/blob/main/src/components/templates/DefaultLayout/DefaultLayout.tsx): `src/components/templates/DefaultLayout/DefaultLayout.tsx`
- [Content block](https://github.com/thaiphan/sitecore-nextjs/blob/main/src/components/organisms/ContentBlock/ContentBlock.tsx): `src/components/organisms/ContentBlock/ContentBlock.tsx`
- [Page SEO](https://github.com/thaiphan/sitecore-nextjs/blob/main/src/pages/_app.tsx): `src/pages/_app.tsx`

### Experience Editor preview

- [Preview API proxy](https://github.com/thaiphan/sitecore-nextjs/blob/main/src/pages/api/preview.ts): `src/pages/api/preview.ts`
- [Preview page](https://github.com/thaiphan/sitecore-nextjs/blob/main/src/pages/preview.tsx): `src/pages/preview.tsx`

### Next.js routes

- [Home route](https://github.com/thaiphan/sitecore-nextjs/blob/main/src/pages/index.tsx): `src/pages/index.tsx`
- [Dynamic route](https://github.com/thaiphan/sitecore-nextjs/blob/main/src/pages/%5B...slug%5D.tsx): `src/pages/[...slug].tsx`
- [404 route](https://github.com/thaiphan/sitecore-nextjs/blob/main/src/pages/404.tsx): `src/pages/404.tsx`

### Other components

- **Site visitor**
- **Sitecore editor**
- **Sitecore rendering host**

## Connections

- Site visitor → Home route: requests
- Site visitor → Dynamic route: requests
- Home route → Route data fetcher: fetches route (evidence: `src/pages/index.tsx`)
- Dynamic route → Route data fetcher: fetches route (evidence: `src/pages/[...slug].tsx`)
- 404 route → Route data fetcher: fetches route (evidence: `src/pages/404.tsx`)
- Route data fetcher → Sitecore Layout API: requests layout (evidence: `src/services/sitecore.ts`)
- Home route → App context: provides props
- Dynamic route → App context: provides props
- App context → Default layout: renders (evidence: `src/pages/_app.tsx`)
- App context → Page SEO: sets metadata (evidence: `src/pages/_app.tsx`)
- Default layout → JSS placeholder: renders (evidence: `src/components/templates/DefaultLayout/DefaultLayout.tsx`)
- App context → Content block: registers component (evidence: `src/pages/_app.tsx`)
- JSS placeholder → Content block: dispatches component
- Sitecore editor → Sitecore rendering host: requests preview (evidence: `README.md`)
- Sitecore rendering host → Preview API proxy: posts rendering data (evidence: `README.md`)
- Preview API proxy → Preview page: forwards preview data (evidence: `src/pages/api/preview.ts`)
- Preview page → Sitecore rendering host: returns HTML
