Architecture Overview
Ptero is built on a modular architecture that integrates deeply with SvelteKit while maintaining flexibility and extensibility. This guide explains how the pieces fit together.
System Architecture
βββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Your SvelteKit App β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β β
β ββββββββββββββββββ βββββββββββββββββββββββββββ β
β β ptero- ββββββ UI components β β
β β core β β (added via CLI) β β
β β β β β β
β β - Content β β - Layout primitives β β
β β - Navigation β β - UI elements β β
β β - Search β β - Styles β β
β β - Versioning β β β β
β ββββββββββββββββββ βββββββββββββββββββββββββββ β
β β β β
β ββββββββββββ¬ββββββββββββ β
β β β
β βββββββββΌβββββββββ β
β β MDsveX β β
β β + Shiki β β
β βββββββββ¬βββββββββ β
β β β
β βββββββββΌβββββββββ β
β β Markdown β β
β β Content β β
β ββββββββββββββββββ β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββCore Packages
Bundled Core
Ptero ships its content/navigation/search logic inside the app (no separate ptero-core install). It provides the fundamental functionality for documentation sites:
Content Management:
- Parses Markdown files with frontmatter validation
- Loads and processes documentation content
- Handles versioned content directories
- Provides content APIs for SvelteKit routes
Navigation:
- Generates sidebar navigation from content structure
- Creates breadcrumb trails
- Provides prev/next page navigation
- Supports custom navigation configuration
Search:
- Builds search indices at compile time
- Provides search API for client-side querying
- Supports version-scoped search
- Uses Fuse.js for fuzzy matching
Versioning:
- Manages multiple documentation versions
- Handles version aliases (latest, next, etc.)
- Routes version-specific content requests
UI Components
Use ptero add <component> to pull prebuilt components into your app (shadcn-style). You can also bring your own layouts and styles; Ptero core is UI-agnostic.
ptero-cli
The CLI package provides tooling for setup and management:
ptero init- Initialize Ptero in existing projectsptero version create- Create new documentation versionsptero search build- Build search indices- Template scaffolding
Content Processing Pipeline
1. File Discovery
When SvelteKit builds or runs in dev mode, Ptero scans the src/content/docs directory:
src/content/docs/
βββ intro/
β βββ getting-started.md
βββ guides/
βββ configuration.md2. Frontmatter Parsing
Each fileβs frontmatter is validated using Zod schemas:
import { z } from 'zod';
const FrontmatterSchema = z.object({
title: z.string(),
description: z.string().optional(),
section: z.string(),
order: z.number().optional(),
hidden: z.boolean().optional()
});3. MDsveX Processing
Markdown content is processed by MDsveX:
- Parses Markdown to HTML
- Processes Svelte components
- Applies syntax highlighting with Shiki
- Generates component output
4. Route Generation
SvelteKitβs dynamic routing serves processed content:
/docs/[version]/[...slug]
β
/docs/latest/guides/configuration
β
Loads: src/content/docs/guides/configuration.mdData Flow
Page Load Sequence
User navigates to
/docs/latest/guides/configurationSvelteKit calls
+page.server.tsload functionexport async function load({ params }) { const doc = await loadDoc(params.version, params.slug); return { doc }; }loadDocretrieves content from core- Checks version validity
- Finds corresponding file
- Returns parsed frontmatter + component
Page renders with DocsLayout
- Sidebar shows navigation
- Content area displays MDsveX component
- TOC extracts headings
Client-side hydration enables
- Instant navigation between pages
- Search functionality
- Theme switching
Routing Strategy
Ptero uses SvelteKitβs file-based routing with dynamic segments:
src/routes/
βββ docs/
βββ [version]/
βββ +layout.svelte # Applies DocsLayout
βββ +layout.server.ts # Loads sidebar/config
βββ +page.svelte # Version index page
βββ [...slug]/
βββ +page.svelte # Doc page component
βββ +page.server.ts # Loads doc contentVersion Parameter
The [version] parameter supports:
- Explicit versions:
v1.0,v2.0 - Aliases:
latest,next - Resolution to actual version folders
Slug Catch-All
The [...slug] parameter captures the full page path:
guides/configurationβ['guides', 'configuration']intro/installationβ['intro', 'installation']
Search Implementation
Index Building
Search indices are built at compile time:
- Scan all documentation files
- Extract searchable content
- Title
- Description
- Headings
- Body text (stripped of Markdown)
- Create Fuse.js index with weights
{ keys: [ { name: 'title', weight: 3 }, { name: 'description', weight: 2 }, { name: 'content', weight: 1 } ]; } - Serialize index to JSON
Client-Side Search
The search component uses the pre-built index:
import Fuse from 'fuse.js';
import searchIndex from '$lib/search-index.json';
const fuse = new Fuse(searchIndex.docs, {
keys: ['title', 'description', 'content'],
threshold: 0.3
});
const results = fuse.search(query);Theme System
CSS Variables
The theme uses CSS custom properties for customization:
:root {
--color-primary: #3b82f6;
--color-background: #ffffff;
--color-text: #1f2937;
--font-family-sans: system-ui, sans-serif;
--font-family-mono: 'Fira Code', monospace;
}
.dark {
--color-background: #0f172a;
--color-text: #f1f5f9;
}Component Slots
Components provide slots for customization:
<DocsLayout>
<svelte:fragment slot="header">
<!-- Custom header content -->
</svelte:fragment>
<svelte:fragment slot="sidebar-top">
<!-- Custom sidebar header -->
</svelte:fragment>
{@render children()}
</DocsLayout>Build Process
Development Mode
pnpm dev
β
1. Vite starts dev server
2. SvelteKit processes routes
3. MDsveX preprocesses .md files
4. Content APIs load on-demand
5. HMR updates on file changesProduction Build
pnpm build
β
1. SvelteKit builds routes
2. MDsveX processes all .md files
3. Search index is generated
4. Static assets are optimized
5. Client code is minified
6. Output to /build directoryPerformance Optimizations
Code Splitting
Each page is code-split automatically:
- Only load content for current page
- Lazy load images and heavy components
- Preload links on hover
Static Generation
Static content is pre-rendered:
- Sidebar navigation computed at build time
- Search index built once
- Markdown processed during build
Client-Side Caching
Loaded content is cached:
- SvelteKit caches loaded pages
- Search index loaded once
- Navigation state preserved
Extension Points
Ptero provides several ways to extend functionality:
Custom Components
Create and use custom Svelte components in docs
Custom Themes
Create themes by implementing the layout interface
Plugins (Planned)
Future plugin system for extending core functionality
MDsveX Plugins
Use remark/rehype plugins for advanced Markdown processing
Next Steps
- Learn about Content Authoring
- Understand Project Structure
- Explore Configuration Reference