Overview
The generation layer is the central orchestrator ofmint-tsdocs. It traverses the API model and constructs the semantic structure of each documentation page using TSDoc AST nodes. The layer has been refactored to use modular components for navigation management and caching.
Primary Component:
src/documenters/MarkdownDocumenter.tsRecent Architecture Changes: The generation layer now delegates navigation to
NavigationManager and integrates caching through CacheManager for performance optimization.Key Responsibilities
File Management
Deletes old output and writes new MDX files
API Traversal
Recursively iterates through packages and API items
AST Construction
Builds TSDoc AST representing document structure
Navigation Management
Delegates to
NavigationManager for docs.json updatesCaching Integration
Coordinates with
CacheManager for optimizationCore Generation Flow
1
Delete Old Output
_deleteOldOutputFiles() cleans the output directory2
Traverse API Model
Recursively iterate through the API hierarchy:
- Packages
- Namespaces
- Classes, Interfaces, Types
- Functions, Variables
3
Generate Each Page
For each API item, call
_writeApiItemPage():- Build frontmatter (YAML)
- Construct TSDoc AST
- Pass to emitter
- Write MDX file
- Add to navigation list
4
Update Navigation
NavigationManager.generateNavigation() merges new pages into docs.json5
Cache Statistics
CacheManager.printStats() reports cache hit rates and performanceModular Architecture
Architecture Evolution: The generation layer has been refactored to separate concerns and improve maintainability.
Navigation Management Extraction
Navigation Management Extraction
Caching Integration
Caching Integration
Performance Optimization: Coordinates with caching layer for improved performance:Performance Improvements:
- 30-50% faster type analysis
- 20-40% faster API resolution
- Significant speedup for large codebases
Performance Monitoring
Performance Monitoring
Built-in Cache Statistics: Track cache effectiveness for optimization:Metrics Tracked:
- Cache hit rates
- Type analysis cache performance
- API resolution cache performance
AST Construction (Not Markdown!)
Key Insight: The documenter builds a TSDoc AST (Abstract Syntax Tree), not Markdown strings. This separates content structure from presentation format.
Why Use an AST?
Separation of Concerns
Separation of Concerns
- What a document contains (generation layer)
- How it looks (emission layer)
Maintainability
Maintainability
To change MDX output for a specific element:
- Modify only the emitter’s handling for that node type
- No need to touch document generation logic
Extensibility
Extensibility
Can define custom
DocNode types for unique concepts:DocTablefor tabular dataDocHeadingfor section titlesDocExpandablefor Mintlify expandables
Page Generation Example
Let’s trace how a class page is generated:- 1. Entry Point
- 2. Create Page Structure
- 3. Build Members Table
- 4. Generate Frontmatter
- 5. Emit to MDX
MarkdownDocumenter receives this as an ApiClass item.Key Methods
_writeApiItemPage()
_writeApiItemPage()
The Main Page GeneratorResponsibilities:
- Determine page type (class, interface, function, etc.)
- Build appropriate AST structure
- Generate frontmatter
- Invoke emitter
- Write file
- Add to navigation
_writeClassTables()
_writeClassTables()
Class Members DocumentationCreates three tables:
- Constructors - Class constructors
- Properties - Class properties
- Methods - Class methods
DocTable with:- Header row defining columns
- Data rows for each member
- Cells containing name, modifiers, type, description
<table> or Mintlify components._writeInterfaceTables()
_writeInterfaceTables()
Interface Members DocumentationSimilar to class tables, but for interfaces:
- Properties table
- Methods table
- Call signatures table (if any)
- Optional properties (
prop?:) - Readonly modifiers
- Generic type parameters
_writeParameterTables()
_writeParameterTables()
Function ParametersFor functions and methods:
- Creates parameter table
- Shows name, type, description
- Indicates optional vs required
- Links to type definitions
<ParamField> components.generateNavigation()
generateNavigation()
Frontmatter Generation
Each MDX file starts with YAML frontmatter:File Organization
Generated files follow a consistent naming pattern:| API Item | Generated File |
|---|---|
Package my-package | my-package.mdx |
Class MyClass | my-package.myclass.mdx |
Interface IConfig | my-package.iconfig.mdx |
Function helper() | my-package.helper.mdx |
Type Status | my-package.status.mdx |
Performance Considerations
Significant Performance Improvements: The new caching layer provides substantial performance gains for large codebases.
Intelligent Caching
Intelligent Caching
Type Analysis Cache: 30-50% performance improvement
- Caches expensive TypeScript type parsing operations
- LRU eviction with configurable size (default: 1000 items)
- Automatic integration with
ObjectTypeAnalyzer
- Caches API model cross-reference resolution
- Reduces redundant symbol lookups
- Configurable size (default: 500 items)
Performance Monitoring
Performance Monitoring
Built-in Performance Tracking:
- Operation-level execution time measurement
- Detailed statistics for optimization
- Error-aware timing (includes failed operations)
Incremental Generation
Incremental Generation
Future Enhancement: Currently, all files are regenerated each time. Potential optimizations:
- Track file timestamps and API changes
- Only regenerate changed API items
- Cache unchanged AST structures
- Implement dependency tracking
Memory Usage
Memory Usage
Current Optimizations:
- Sequential processing to control memory usage
- LRU cache eviction to limit memory growth
- Efficient AST construction
- Monitor cache hit rates vs. memory usage
- Adjust cache sizes based on available memory
- Consider streaming approaches for massive projects
Parallel Processing
Parallel Processing
Potential Future Optimization:
- Generate pages in parallel (currently sequential)
- Use worker threads for large packages
- Batch file writes for I/O optimization
- Thread-safe cache implementations

