Introducing a new way to review your PRs.

Read the announcement

spartan-ng / spartan

Cutting-edge tools powering Angular full-stack development.

View on GitHub

18 documents · Updated Nov 23, 2026

docs / documentation-application

Spartan documentation application

The Spartan documentation application is an Angular site served and rendered by Analog and Nitro. It presents Spartan reference content as browsable pages with examples, code, API notes, and live UI surfaces. The app also exposes small server APIs that support the site, while build-time tools turn library and example sources into data that the pages can consume.

Application shell

The application shell gives every route the same site frame. It keeps the header and footer outside the route outlet, so documentation, component, block, color, and stack pages share navigation and global presentation. The browser starts the Angular app in apps/…/main.ts, while the server uses apps/…/main.server.ts to render the same App component before client hydration.

The shell provides:

  • Top-level links for Docs, Components, Blocks, Colors, and Stack.
  • A responsive navigation menu for small screens.
  • Documentation search through the header search dialog.
  • Dark mode, theme, layout, and logo controls.
  • Links to the Spartan GitHub repository and community Discord.

References: apps/…/app.ts• L1-31 apps/…/main.ts• L1-10 apps/…/main.server.ts• L1-26 apps/…/header.ts• L19-129

Documentation page frame

The documentation route uses a shared page frame that places the current page between a section sidebar and an optional right-side page index. This frame lets users move between content groups while keeping links to headings in the current page close to the reading area. The /documentation route establishes the docs metadata and renders this frame through apps/…/documentation.page.ts.

The left navigation groups the site into these areas:

  • Getting Started, which covers introduction, changelog, and credits.
  • UI, which covers setup, styles, themes, tools, and related guidance.
  • Components, which links to individual component reference pages.
  • Utilities, Forms, and Stack, which lead to other reference areas.

The frame also supports previous and next links at the bottom of pages. The right page index reads visible section headings and can add API headings for component pages. See content rendering and navigation for the detailed content and navigation model.

References: apps/…/documentation.page.ts• L1-20 apps/…/page.ts• L1-31 apps/…/navigation-items.ts• L97-151 apps/…/page-nav.ts• L68-160

Reference content lifecycle

Reference pages combine authored Angular page content with generated data. A page supplies the explanation and chooses the examples to show. Build steps then generate API descriptions, code snippets, manual-install content, and preview metadata from the Spartan libraries and documentation examples. The build and serve targets run these data steps before the app is built or served, so the site remains aligned with the library source.

The main content types are:

Content typeUser-facing role
Documentation pagesExplain setup, use, and project guidance.
Component pagesCombine a live preview, example source, install guidance, and Brain and Helm API sections.
Block pagesPresent larger UI compositions through responsive preview surfaces.
Generated dataSupplies API facts, snippets, install text, and runnable project metadata.

For a component page, the route loader fetches the data slices for one component. Shared services then make those slices available to the page and its child presentation controls. A missing optional slice means that the page has no data of that kind. A failed non-404 request remains an error rather than silently producing incomplete content.

References: apps/…/project.json• L8-22 apps/…/project.json• L35-50 apps/…/component-docs-loader.ts• L7-30 apps/…/component-docs.ts• L12-33 apps/…/api-docs.service.ts• L7-40

Interactive presentation surfaces

The application turns reference material into a try-before-you-copy experience. Pages can place a preview beside its source code, let the reader switch between preview and code, copy code to the clipboard, and open runnable examples in StackBlitz. Larger blocks use a separate preview route inside an iframe so the documentation page can show a full UI composition without mixing it with the page layout.

The interactive surfaces include:

  • Preview and code tabs: Keep the rendered example and its source in one reference unit.
  • Code display: Formats Markdown code, highlights common languages, and offers copy support.
  • Style-aware previews: Apply the selected Spartan style to preview content.
  • Block viewers: Switch between desktop, tablet, and phone widths and open a preview in a new tab.
  • StackBlitz projects: Assemble a small Angular project from generated Spartan files and the selected example, then open it in a new browser tab.
  • AI links: Offer the current page to supported AI chat tools.

This flow shows how a component example moves from page content to an external runnable project.

flowchart LR
    A[Component page] --> B[Example source]
    B --> C[Preview and code surface]
    B --> D{Runnable example?}
    D -- No --> E[Code and copy only]
    D -- Yes --> F[Generated project data]
    F --> G[Assembled Angular project]
    G --> H[StackBlitz]

The external project is intentionally a generated example project rather than a copy of the documentation app. This keeps the user-facing example small and gives it the library files, dependencies, and style data needed to run on its own.

References: apps/…/code.ts• L61-215 apps/…/tabs.ts• L11-72 apps/…/block-viewer.ts• L13-95 apps/…/block-preview.ts• L1-31 apps/…/open-in-stackblitz-button.ts• L10-89 apps/…/stackblitz-project-builder.service.ts• L105-192

Rendering and delivery model

The app uses Analog's file-based routes and Nitro's server runtime to support both direct page delivery and browser navigation. Angular renders pages on the server, then the browser hydrates the result. Static documentation and preview routes are selected for prerendering, while Nitro serves generated data as server assets and handles API requests.

The delivery path is:

  1. A route maps to an Angular page component.
  2. Analog renders the page on the server when the route is requested or prerendered.
  3. Nitro serves generated data files used by page loaders and interactive controls.
  4. The browser hydrates the server HTML and takes over route and control behavior.

The application explicitly lists core documentation routes for prerendering. It also discovers component pages under the components route tree and removes file-group markers from their public URLs. This gives known docs pages and generated component pages the same static delivery path without exposing route-group names.

References: apps/…/app.config.ts• L1-22 apps/…/app.config.server.ts• L1-10 apps/…/prerender-routes.ts• L9-53 apps/…/vite.config.ts• L89-156

Server support

The Nitro server supports application features that need data outside the browser bundle. The current API surface includes a GitHub repository summary for the header and a tRPC endpoint for notes. tRPC gives the Angular client a typed route to the server router, while the notes router stores and retrieves note records through the database layer. These APIs are support systems for the documentation application rather than the source of its reference content.

The server boundary is organized as follows:

BoundaryPurpose
/api/github-infoSupplies repository name, description, URL, star count, and fetch time.
/api/trpcExposes the application tRPC router.
note routerCreates, lists, and removes notes.
PostgreSQL databaseStores note title, content, ID, and creation time.

The GitHub route uses a development response and caches production repository data for one day. The tRPC context is currently empty and its note procedures are public. See server APIs and notes persistence for the API and data flow.

References: apps/…/github-info.ts• L1-45 apps/…/[trpc].ts• L1-8 apps/…/trpc-client.ts• L1-15 apps/…/index.ts• L1-8 apps/…/notes.ts• L6-28 apps/…/db.ts• L1-17

Search and discovery

Documentation search gives users a direct path to pages and page sections. The header opens a command-style search dialog that sends the query to the Algolia spartan-ng index. Results can point to a page or a heading anchor, and the dialog removes internal preview routes and missing pages from the results shown to users.

Search results use page hierarchy and content snippets to distinguish a page from a section inside that page. The dialog keeps results in a small in-memory cache for the current browser session, which avoids repeating the same remote search while the user explores the docs.

References: apps/…/docs-dialog.ts• L1-78 apps/…/docs-dialog.ts• L206-315 apps/…/header.ts• L79-108

Change checklist

When these files or sections are changed, remember to consider these:

  • Route additions or moves must be reflected in the prerender route rules and the shared navigation model. A route can work in browser navigation while still being absent from static output or the sidebar.
  • Changes to generated data names or shapes must stay aligned across the generators, Nitro server assets, component page loaders, and the shared docs services.
  • Changes to component headings must preserve the IDs used by the right page index and by search result anchor URLs.
  • Changes to runnable example imports must stay compatible with the generated StackBlitz project and its bundled sibling files.
  • Changes to the GitHub response shape must stay aligned with the header's star-count display and its development fallback.
  • Changes to the notes router input or output shape must stay aligned with the tRPC client type and the database note model.

Important failure modes

TriggerConsequenceGuard
A generated component data slice is missing or has an unexpected shapeThe component page can lose API, snippet, or install content.Keep generator output, loader URLs, and shared service types aligned. Treat only an expected 404 as an empty optional slice.
A component page heading has no stable IDThe right page index and search anchor can point to an empty or wrong location.Use explicit heading IDs and keep the page navigation heading rules in mind.
A runnable example imports an unbundled sibling file or docs-app-only moduleStackBlitz opens an incomplete project or the open action fails.Keep relative example files in the generated sibling map and mark non-self-contained examples as non-runnable.
The GitHub API is unavailable or returns an errorThe header cannot refresh repository stars.Use the development fallback and the one-day cache. Handle the route as an external dependency.
The database URL is empty or the notes database is unavailableNote list, create, or remove operations fail.Provide a working DATABASE_URL for environments that use notes.
A route is omitted from static route discoveryA direct statically served URL can be absent even though the Angular route exists.Update the static route list or place component pages under the discovered component route tree.

Key files

FileWhy to read it
apps/…/app.tsDefines the global header, route outlet, and footer shell.
apps/…/documentation.page.tsDefines the documentation entry route and its page-frame entry point.
apps/…/navigation-items.tsDefines the top-level and grouped navigation relationships.
apps/…/page.tsShows how documentation content is placed between the side and page navigation surfaces.
apps/…/page-nav.tsShows how same-page and generated API links are formed.
apps/…/component-docs-loader.tsShows the data contract used to load one component's reference content.
apps/…/code.tsShows the common code reading, copy, and runnable-example surface.
apps/…/stackblitz-project-builder.service.tsShows the boundary between a docs example and an external runnable project.
apps/…/vite.config.tsShows the Analog, Nitro, prerender, and generated-data delivery settings.
apps/…/[trpc].tsShows how the tRPC router enters the Nitro server.
apps/…/notes.tsShows the application note operations exposed to the client.
apps/…/db.tsShows the persisted note record represented by the notes API.
docs/documentation-content-rendering-and-navigation.mdChild page for the detailed content rendering and navigation model.
docs/documentation-server-apis-and-notes.mdChild page for server endpoints and note persistence.
docs/mcp-server.mdRelated page for the MCP server documentation surface.