Skip to content

API Documentation Specification

Cartographer maintains comprehensive JSDoc/TSDoc coverage across all public APIs, providing the foundation for auto-generated API reference documentation. This specification outlines how to generate, integrate, and maintain API documentation using TypeDoc’s Markdown plugin within the Atlas (Starlight) documentation site.

Status: Active implementation guide


  1. Single Source of Truth: Documentation lives in code comments, stays in sync with implementation
  2. Searchable API Reference: Developers can quickly find function signatures, parameters, return types, and examples
  3. Type Safety: TSDoc comments are validated during development (TypeScript catches documentation errors)
  4. Maintainability: Update code → update comment → regenerate docs (automated)
  5. Professional Appearance: Auto-generated documentation looks polished and consistent
  6. Integrated Experience: API docs live alongside user guides in the same site

Architecture: TypeDoc Markdown + Starlight

Section titled “Architecture: TypeDoc Markdown + Starlight”

Generate API documentation as Markdown files using TypeDoc’s Markdown plugin, placing them directly in Starlight’s content directory.

Flow:

TypeScript Source Files
TypeDoc generates
Markdown files
Placed in atlas/src/content/docs/reference/api/
Starlight builds complete site
Deploy to GitHub Pages

TypeDoc with Markdown Plugin:

  • ✅ Best-in-class TypeScript support (understands generics, type unions, etc.)
  • ✅ Generates clean Markdown files
  • ✅ Perfect integration with Starlight
  • ✅ Excellent type inference from source code
  • ✅ Native content format for Starlight

Starlight Integration:

  • ✅ API docs use same theme as user guides
  • ✅ Unified navigation and search
  • ✅ Consistent branding across all documentation
  • ✅ Single deployment process
  • ✅ No iframe or context switching

Terminal window
pnpm add -D typedoc typedoc-plugin-markdown

typedoc.json:

{
"$schema": "https://typedoc.org/schema.json",
"entryPoints": ["src/index.ts"],
"out": "atlas/src/content/docs/reference/api",
"plugin": ["typedoc-plugin-markdown"],
"readme": "none",
"excludePrivate": true,
"excludeInternal": true,
"excludeExternals": true,
"hideGenerator": true,
"sanitizeComments": true,
"sort": ["source-order"],
"kindSortOrder": [
"Function",
"Class",
"Interface",
"TypeAlias",
"Variable"
]
}

package.json:

{
"scripts": {
"docs:api": "typedoc",
"prebuild:atlas": "pnpm docs:api"
}
}

TypeDoc will generate:

atlas/src/content/docs/reference/api/
├── index.md # API overview
├── modules.md # All modules
├── functions/
│ ├── filterByTag.md
│ ├── sortByDate.md
│ └── ...
├── interfaces/
│ ├── CatalogSchema.md
│ ├── Library.md
│ └── ...
└── types/
├── CatalogItem.md
└── ...

atlas/src/content/docs/reference/index.mdx:

---
title: API Reference
description: Complete API documentation for Cartographer
---
Welcome to the Cartographer API reference. This section documents all public APIs, including functions, interfaces, and types.
## Quick Links
- [Functions](/reference/api/functions/) - All query and utility functions
- [Interfaces](/reference/api/interfaces/) - Configuration and data interfaces
- [Types](/reference/api/types/) - Type definitions
## Getting Started
New to the API? Start with our [Developer Guide](/developers/) to understand the architecture before diving into specific APIs.

atlas/astro.config.mjs:

starlight({
sidebar: [
// ... other sections
{
label: 'Reference',
link: '/reference/',
items: [
{ label: 'API Overview', link: '/reference/' },
{
label: 'API Documentation',
autogenerate: { directory: 'reference/api' }
},
],
},
],
})

atlas-deploy.yml:

- name: Generate API documentation
run: pnpm docs:api
- name: Build Atlas
run: pnpm --filter atlas build
# Generated API docs
atlas/src/content/docs/reference/api/

The API docs are generated on build, so they shouldn’t be committed.


TypeDoc Markdown output may need frontmatter adjustments. Create a post-processing script:

scripts/process-api-docs.js:

import fs from 'fs';
import path from 'path';
import { glob } from 'glob';
const apiDocsDir = 'atlas/src/content/docs/reference/api';
// Find all generated markdown files
const files = glob.sync(`${apiDocsDir}/**/*.md`);
files.forEach(file => {
let content = fs.readFileSync(file, 'utf-8');
// Add Starlight frontmatter if missing
if (!content.startsWith('---')) {
const title = path.basename(file, '.md');
const frontmatter = `---
title: ${title}
description: API documentation for ${title}
---
`;
content = frontmatter + content;
fs.writeFileSync(file, content);
}
});
console.log(`Processed ${files.length} API documentation files`);

Update package.json:

{
"scripts": {
"docs:api": "typedoc && node scripts/process-api-docs.js"
}
}

If you need more control over Markdown output, you can customize the plugin options:

typedoc.json:

{
"plugin": ["typedoc-plugin-markdown"],
"entryDocument": "index.md",
"hidePageHeader": true,
"hideBreadcrumbs": false,
"outputFileStrategy": "members",
"flattenOutputFiles": false,
"useCodeBlocks": true
}

API docs regenerate automatically:

  1. Developer updates code and TSDoc comments
  2. Commits and pushes to GitHub
  3. GitHub Actions runs pnpm docs:api
  4. TypeDoc regenerates Markdown files
  5. Starlight builds complete site
  6. Deploys to GitHub Pages
Terminal window
# Regenerate API docs
pnpm docs:api
# View locally
pnpm --filter atlas dev

Before releasing updated API docs:

  • All public exports have TSDoc comments
  • All @param tags documented
  • All @returns tags documented
  • Complex functions have @example tags
  • No incomplete or @todo documentation
  • TypeScript compiles cleanly: pnpm run build
  • API docs generate without errors: pnpm docs:api
  • Local preview looks correct: pnpm --filter atlas dev

Good:

/**
* Filters catalog items by tag.
*
* @param items - Array of catalog items to filter
* @param tag - Tag to filter by
* @returns Filtered array containing only items with the specified tag
*
* @example
* ```typescript
* const items = getCatalogItems();
* const filtered = filterByTag(items, 'important');
* ```
*/
export function filterByTag(items: CatalogItem[], tag: string): CatalogItem[] {
return items.filter(item => item.tags?.includes(tag));
}

Bad:

// Filters items
export function filterByTag(items: CatalogItem[], tag: string): CatalogItem[] {
return items.filter(item => item.tags?.includes(tag));
}

Structure source code to generate logical API documentation sections:

src/
├── index.ts # Main exports
├── query/
│ ├── filters.ts # Filter functions
│ ├── sorts.ts # Sort functions
│ └── groups.ts # Group functions
├── types/
│ └── index.ts # Type definitions
└── utils/
└── index.ts # Utility functions

TypeDoc will organize docs by these modules.

In your guides, link to specific API documentation:

To filter items by tag, use the [`filterByTag`](/reference/api/functions/filterByTag) function.

In API docs, link back to guides:

/**
* For usage examples, see the [Filtering Guide](/guides/filtering).
*/

Check:

  • TypeScript compiles: pnpm run build
  • typedoc.json is valid JSON
  • Entry points exist and are correct
  • All dependencies installed: pnpm install

Solution: Use the post-processing script (see Customizing TypeDoc Output section)

Check:

  • Files are in atlas/src/content/docs/reference/api/
  • Sidebar config references the correct paths
  • Files have valid frontmatter (YAML)
  • Rebuild Starlight: pnpm --filter atlas build

Solution: Starlight’s built-in search (Pagefind) automatically indexes all pages. Ensure API docs are building correctly and search will include them.

Common fixes:

  • TypeDoc uses GitHub-flavored Markdown - ensure Starlight processes it correctly
  • Code blocks may need language identifiers
  • Use post-processing script to adjust formatting if needed

For supporting multiple plugin versions:

  • Generate API docs per version
  • Store in versioned directories: /reference/api/v1/, /reference/api/v2/
  • Add version switcher in Starlight config
  • Create custom TypeDoc templates for better Markdown output
  • Add custom CSS for API-specific styling in Starlight
  • Implement enhanced syntax highlighting for code examples
  • Embed live code examples using Storybook
  • Link from API docs to relevant Storybook stories
  • Add “Try it” buttons that open examples


Official Documentation:

Examples:


Document Version: 2.0
Status: Active implementation guide
Last Updated: 2026-01-21