Enhanced Documentation System
Complete guide to the new automatic documentation discovery and multi-language system
Enhanced Documentation System
Our documentation system has been completely redesigned to provide automatic directory discovery, multi-language support, and intelligent content management. This guide explains how to use the new system effectively.
🏗️ System Architecture
The new documentation system consists of three main services that work together:
1. DocumentationService
- Purpose: Handles all logic and automatic directory discovery
- Features: Scans directory structure, manages language switching, provides intelligent file loading
- Location:
apps/docs-angular/src/app/services/documentation.service.ts
2. NavigationService
- Purpose: Contains navigation structure and state management
- Features: Manual navigation overrides, breadcrumbs, path matching
- Location:
apps/docs-angular/src/app/services/navigation.service.ts
3. MarkdownService
- Purpose: Focuses purely on markdown parsing and content processing
- Features: Language-aware content loading, intelligent path resolution, enhanced parsing
- Location:
apps/docs-angular/src/app/services/markdown.service.ts
🌐 Multi-Language Support
Directory Structure
assets/docs/
├── english/ # English documentation
│ ├── getting-started/
│ ├── guide/
│ ├── apps/
│ └── libs/
├── spanish/ # Spanish documentation (future)
│ ├── getting-started/
│ └── ...
├── index.md # English homepage
└── index.es.md # Spanish homepage
File Naming Conventions
- Standard Files:
filename.md(placed in language directory) - Language-Specific:
filename.mdorfilename.es.md - Index Files:
index.mdandindex.es.mdin root
Language Detection Priority
- Directory-based: Files in
/english/or/spanish/directories - Extension-based: Files with
.mdor.es.mdextensions - Service state: Current language setting in DocumentationService
- Default: English (
en)
🔍 Automatic Directory Discovery
How It Works
- Directory Scanning: The system automatically scans the
assets/docs/directory structure - File Discovery: Identifies all
.mdfiles and their metadata - Structure Building: Creates a hierarchical structure of sections and files
- Navigation Sync: Merges discovered files with manual navigation overrides
Manual Override System
The NavigationService contains manual navigation structure that takes priority over discovered files:
readonly navigationStructure = signal<NavigationItem[]>([
{
text: '🚀 Getting Started',
order: 1,
items: [
{ text: 'Introduction', link: '/getting-started', order: 1 },
{ text: 'Project Overview', link: '/guide/project-overview', order: 2 }
]
}
// ... more sections
]);
Sync Process
- Check Natural Structure: Scan filesystem for available files
- Compare with Manual: Compare discovered structure with NavigationService
- Merge Intelligently: Add new files to navigation while preserving manual overrides
- Update Navigation: Automatically update navigation structure
🚀 Using the New System
Adding New Documentation
Create File: Add your
.mdfile in the appropriate language directory:assets/docs/english/guide/my-new-guide.mdRun Discovery: The system will automatically discover it on next scan
Manual Override (Optional): Add specific navigation entry in NavigationService if needed:
{ text: 'My New Guide', link: '/guide/my-new-guide', order: 3 }
Language-Specific Content
- English Version:
assets/docs/english/guide/feature.md - Spanish Version:
assets/docs/spanish/guide/feature.md - Language Extensions: Alternatively use
feature.mdandfeature.es.md
Switching Languages
// In a component
constructor() {
const docService = inject(DocumentationService);
// Switch to Spanish
docService.switchLanguage('es');
// Current language
const currentLang = docService.currentLanguage();
}
🛠️ Development Tools
Automatic Structure Scanner
Run the directory scanner to generate a manifest of all available files:
cd apps/docs-angular
node scripts/scan-docs-structure.js
This generates src/assets/docs-manifest.json with complete structure information.
Development Commands
# Clear documentation cache
docService.clearCache();
# Check if content exists
const exists = await docService.contentExists('/guide/feature', 'en');
# Get cache statistics
const stats = docService.getCacheStats();
# Refresh structure
await docService.refreshStructure();
📊 Advanced Features
Intelligent Path Resolution
The system tries multiple path patterns to find files:
/assets/docs/english/guide/feature.md(primary English path)/assets/docs/spanish/guide/feature.md(Spanish localized path)/assets/docs/guide/feature.md(legacy fallback)/assets/docs/feature.md(root fallback)
Content Caching
- Language-aware caching: Separate cache entries for different languages
- Intelligent invalidation: Cache is cleared when structure changes
- Development support: Manual cache clearing for development
Fallback Content
When files are not found, the system provides localized fallback content:
- English: Standard "content coming soon" message
- Spanish: Translated fallback content
- Metadata preservation: Maintains path and language information
🔄 Migration Guide
From Old System
Move Files: Move documentation files to language directories:
mkdir -p assets/docs/english mv assets/docs/*.md assets/docs/english/Update References: Update any hardcoded file references in components
Test Navigation: Verify all navigation links work with new structure
Clean Up: Remove old routing entries that are now handled dynamically
Best Practices
- Consistent Structure: Keep similar directory structures across languages
- Meaningful Names: Use descriptive directory and file names
- Manual Overrides: Use NavigationService overrides for custom ordering
- Regular Scanning: Run the structure scanner after adding new files
🚨 Troubleshooting
Common Issues
- File Not Found: Check path resolution order and file naming
- Navigation Missing: Verify NavigationService includes the section
- Language Not Working: Check language detection priority
- Cache Issues: Clear cache during development
Debugging Tools
// Check documentation statistics
const stats = docService.documentationStats();
// Verify file existence
const exists = await docService.contentExists(path, language);
// Check navigation item
const navItem = navService.getNavigationItem(path);
// Review cache contents
const cacheStats = markdownService.getCacheStats();
🎯 Benefits
For Developers
- Automatic Discovery: No manual route configuration for new files
- Type Safety: Strong typing throughout the system
- Development Tools: Built-in debugging and cache management
- Separation of Concerns: Clear responsibility boundaries
For Content Creators
- Simple File Addition: Just add
.mdfiles in the right directory - Multi-Language Ready: Easy to add translations
- Flexible Structure: Supports both automatic and manual organization
- Rich Metadata: Frontmatter support for enhanced content
For Users
- Fast Performance: Intelligent caching and loading
- Responsive Navigation: Real-time path tracking
- Language Switching: Seamless language transitions
- Consistent Experience: Unified interface across all content
📈 Future Enhancements
- Real-time File Watching: Automatic updates when files change
- Content Validation: Automatic link checking and validation
- Search Integration: Enhanced search with language awareness
- Build-time Optimization: Pre-generate manifest during build process
This enhanced system provides a robust foundation for documentation management while maintaining flexibility for future growth and localization needs.