codewiki
Integrations

Site Generation & Frontend Integration Overview

Overview

The Site Generation & Frontend Integration subsystem is responsible for transforming DeepDoc's AI-generated documentation plan into a fully functional, navigable documentation website. It automates the scaffolding, configuration, and integration of the Fumadocs frontend, ensuring that all generated documentation, navigation, assets, and interactive features (like search and chatbot) are consistently built and deployed.

This component is central to the DeepDoc architecture, bridging the gap between backend documentation planning and the user-facing site. It handles legacy migration, configures site theming and branding, and integrates advanced features such as OpenAPI rendering and chatbot Q&A.

For a high-level view of how this fits into the overall system, see DeepDoc Architecture & System Overview. For details on the document planning pipeline, see Pipeline & Generation Engine. For the chunking and summarization logic that powers search and chatbot, see Documentation Chunking and Summarization.


Files Covered

File PathRoleKey Symbols (Functions/Classes)Responsibility
deepdoc/site/fumadocs_builder_v2.pySite generation & scaffoldingbuild_fumadocs_from_plan, _ensure_app_scaffold, _build_page_tree_from_plan, _write_page_tree, _write_static_assets, _cleanup_legacy_artifacts, _rename_legacy_intro_to_index, _ensure_landing_page, _mdx_components_tsx, _app_layout_tsx, _global_css, _docs_layout_tsx, _docs_page_tsx, _api_layout_tsx, _api_page_tsx, _chatbot_ask_page_tsx, _mermaid_component_tsx, _openapi_ts, _chatbot_config_ts, _chatbot_toggle_tsx, _chatbot_panel_tsxOrchestrates the build of the Fumadocs-based site from a documentation plan, handles navigation, assets, config, and feature integration.
deepdoc/_legacy_types.pyLegacy plan compatibilityDocPage, DocPlan, RepoScanProvides data structures for backward compatibility with v1 plans.
deepdoc/chatbot/chunker.pyChunking for search/chatbotbuild_code_chunks, build_artifact_chunks, discover_artifact_filesPrepares documentation/code chunks for search and chatbot features.

Architecture & Design

The site generation system is designed as a layered builder that takes a documentation plan and produces a ready-to-serve Fumadocs/Next.js site. It handles:

  • Legacy migration: Converts old Markdown/MDX and navigation to the new structure.
  • Frontend scaffolding: Generates all required config, assets, and React components.
  • Feature integration: Adds OpenAPI, chatbot, and search features as needed.
  • Theming and branding: Injects custom colors, logos, and layout options from config.

The builder is modular: each step (scaffold, page tree, assets, config, layouts) is handled by a dedicated function, making it easy to extend or customize.

This builder is the single source of truth for the generated documentation site's structure, navigation, and feature integration.


Key Components

build_fumadocs_from_plan()

File: deepdoc/site/fumadocs_builder_v2.py:24
What it does:
Main entry point. Builds the Fumadocs site from a documentation plan (DocPlan). Handles migration, navigation, assets, and feature integration.

Signature:

def build_fumadocs_from_plan(
    repo_root: Path,
    output_dir: Path,
    cfg: dict[str, Any],
    plan: DocPlan,
    has_openapi: bool = False,
) -> None:

How it's used:

Key steps (all in deepdoc/site/fumadocs_builder_v2.py):

  • _rename_md_to_mdx(): Converts .md files to .mdx.
  • _rename_legacy_intro_to_index(): Migrates legacy intro pages.
  • _ensure_mdx_frontmatter(): Ensures all MDX files have frontmatter.
  • _ensure_landing_page(): Creates/updates the landing page.
  • _build_page_tree_from_plan(): Builds the navigation tree.
  • _ensure_app_scaffold(): Generates the Next.js/Fumadocs app scaffold.
  • _write_page_tree(): Writes the navigation structure.
  • _write_static_assets(): Adds logos and favicon.
  • _cleanup_legacy_artifacts(): Removes obsolete files.

Example usage:

from deepdoc.site.fumadocs_builder_v2 import build_fumadocs_from_plan
build_fumadocs_from_plan(repo_root, output_dir, cfg, plan, has_openapi=True)

_ensure_app_scaffold()

File: deepdoc/site/fumadocs_builder_v2.py:64
What it does:
Writes or updates all files needed for a working Fumadocs/Next.js app, including package.json, tsconfig.json, configs, layouts, and React components.

Key outputs:

  • [path-not-found], [path-not-found], [path-not-found], etc.
  • [path-not-found], [path-not-found]
  • [path-not-found] (chatbot), [path-not-found] (search API)
  • [path-not-found] (navigation tree)

Configuration options:

  • Project name, repo URL, colors, OpenAPI integration, chatbot config.

_build_page_tree_from_plan()

File: deepdoc/site/fumadocs_builder_v2.py:127
What it does:
Builds a navigation tree for Fumadocs from the documentation plan, handling special cases for overview and API reference pages.

Returns:
A dict representing the navigation structure, written to [path-not-found].


_write_static_assets()

File: deepdoc/site/fumadocs_builder_v2.py:353
What it does:
Creates placeholder logo and favicon assets in site/public/.


_rename_legacy_intro_to_index()

File: deepdoc/site/fumadocs_builder_v2.py:396
What it does:
Migrates legacy intro/overview files to the Fumadocs index.mdx convention.


_ensure_landing_page()

File: deepdoc/site/fumadocs_builder_v2.py:443
What it does:
Ensures a landing page exists, generating a cards-based overview if needed.


_mdx_components_tsx()

File: deepdoc/site/fumadocs_builder_v2.py:677
What it does:
Generates the MDX components registry, wiring up Fumadocs UI, custom components (Mermaid, APIPage), and feature toggles.


_app_layout_tsx()

File: deepdoc/site/fumadocs_builder_v2.py:705
What it does:
Defines the root React layout, branding, and global providers.


_global_css()

File: deepdoc/site/fumadocs_builder_v2.py:749
What it does:
Injects Tailwind, Fumadocs, and custom CSS, including theme colors from config.


_openapi_ts()

File: deepdoc/site/fumadocs_builder_v2.py:1951
What it does:
Integrates OpenAPI schemas for API reference pages.


_chatbot_config_ts()

File: deepdoc/site/fumadocs_builder_v2.py:2028
What it does:
Configures chatbot integration, using NEXT_PUBLIC_DEEPDOC_CHATBOT_BASE_URL or a backend URL from config.


_chatbot_toggle_tsx() and _chatbot_panel_tsx()

File: deepdoc/site/fumadocs_builder_v2.py:2042, deepdoc/site/fumadocs_builder_v2.py:2117
What they do:
Provide the chatbot UI toggle and panel, conditionally rendered based on config.


Configuration

The following environment variables and config keys affect site generation and frontend integration:

Variable / Config KeyRequiredDefault / ExampleDescription
GITHUB_PAGESNo(unset)If set to 'true', enables GitHub Pages export mode in Next.js.
GITHUB_REPOSITORYNo(unset)Used to infer repo name for GitHub Pages base path.
NEXT_PUBLIC_DEEPDOC_CHATBOT_BASE_URLNo(unset)If set, overrides the chatbot API base URL for the frontend.
cfg["project_name"]Norepo nameUsed for branding and site title.
cfg["site"]["repo_url"]No(empty)Adds a GitHub link to the site navigation.
cfg["site"]["colors"]No{primary, light, dark}Sets theme colors for branding.
cfg["chatbot"]["enabled"]NoFalseEnables/disables chatbot UI.
cfg["chatbot"]["apiBaseUrl"]No(see backend config)Sets the backend API for chatbot queries.
All three environment variables must be set before starting if you want full GitHub Pages and chatbot support.

How Other Components Use This

  • CLI and automation: The CLI (see CLI Commands & Tooling) invokes build_fumadocs_from_plan() to generate/update the site.
  • Webhook triggers: Site builds can be triggered by webhooks (see Webhook Integrations).
  • Chunking & search: The Documentation Chunking and Summarization system prepares content for search/chatbot, which is surfaced via the generated site.
  • Anthropic/LLM integration: Content generation and Q&A features rely on the site being correctly scaffolded (see Anthropic Integration).
  • Frontend features: The generated site exposes search, API reference, and chatbot features, all wired up via the builder.

Edge Cases & Failure Modes

  • Legacy file migration: If both introduction.mdx and index.mdx exist, only index.mdx is kept. Old files are unlinked after migration.
  • Missing frontmatter: _ensure_mdx_frontmatter() injects minimal frontmatter if missing, but may infer a generic title if none is found.
  • Partial config: If required config keys (e.g., colors, repo URL) are missing, defaults are used, which may result in generic branding.
  • Chatbot API misconfiguration: If NEXT_PUBLIC_DEEPDOC_CHATBOT_BASE_URL is set incorrectly, the chatbot UI may fail to connect.
  • OpenAPI integration: If no OpenAPI schema is found, API reference pages are omitted.
  • File system errors: All file writes use Path.mkdir(parents=True, exist_ok=True) and check for existence, but permission errors or disk issues will cause failures.
  • Legacy artifacts: _cleanup_legacy_artifacts() attempts to remove obsolete files, but may leave directories if not empty.
  • MD/MDX conversion: If a .md file cannot be read or parsed, it is skipped, which may result in missing pages.

Running the builder in a partially migrated or misconfigured repo may result in a broken or incomplete documentation site.


Diagrams

Component Diagram

Site Generation Flow


Quick Reference

SymbolFile PathSignature / ArgsWhat It Does
build_fumadocs_from_plandeepdoc/site/fumadocs_builder_v2.py:24(repo_root, output_dir, cfg, plan, has_openapi=False)Main entry: builds the Fumadocs site from a doc plan.
_ensure_app_scaffolddeepdoc/site/fumadocs_builder_v2.py:64(repo_root, project_name, repo_url, docs_dir_relative, cfg, has_openapi)Writes/updates all app scaffold files.
_build_page_tree_from_plandeepdoc/site/fumadocs_builder_v2.py:127(repo_root, plan, output_dir, project_name, has_openapi)Builds the navigation tree for the site.
_write_page_treedeepdoc/site/fumadocs_builder_v2.py:338(repo_root, page_tree)Writes the navigation tree to TypeScript.
_write_static_assetsdeepdoc/site/fumadocs_builder_v2.py:353(repo_root)Writes logo and favicon assets.
_cleanup_legacy_artifactsdeepdoc/site/fumadocs_builder_v2.py:376(repo_root)Removes obsolete files from previous site builders.
_rename_legacy_intro_to_indexdeepdoc/site/fumadocs_builder_v2.py:396(output_dir)Migrates intro/overview files to index.mdx.
_ensure_landing_pagedeepdoc/site/fumadocs_builder_v2.py:443(output_dir, project_name, plan)Ensures a landing page exists.
_ensure_mdx_frontmatterdeepdoc/site/fumadocs_builder_v2.py:491(output_dir)Adds frontmatter to MDX files if missing.
_mdx_components_tsxdeepdoc/site/fumadocs_builder_v2.py:677(has_openapi)Generates MDX component registry.
_app_layout_tsxdeepdoc/site/fumadocs_builder_v2.py:705(project_name)Generates root React layout.
_global_cssdeepdoc/site/fumadocs_builder_v2.py:749(cfg)Generates global CSS with theming.
_openapi_tsdeepdoc/site/fumadocs_builder_v2.py:1951()Integrates OpenAPI schemas.
_chatbot_config_tsdeepdoc/site/fumadocs_builder_v2.py:2028(repo_root, cfg)Configures chatbot integration.
_chatbot_toggle_tsxdeepdoc/site/fumadocs_builder_v2.py:2042()Generates chatbot toggle UI.
_chatbot_panel_tsxdeepdoc/site/fumadocs_builder_v2.py:2117()Generates chatbot panel UI.

See Also

For implementation details on the document planning and chunking pipeline, see Pipeline & Generation Engine and Documentation Chunking and Summarization.


component_summary

TODO: This section (component_summary) needs to be filled in with details from the source files listed above.

Ask the codebase

Open a dedicated answer page with grounded citations.

Ask from any docs page and keep reading without losing context.