SmartGen Docs Architecture
SmartGen Docs is designed with a modular and extensible architecture, focusing on converting Markdown content into a static, navigable documentation website. Understanding its core components and their interactions is key to customizing and extending the platform. This document outlines the main architectural elements of SmartGen Docs.
Core Components
The SmartGen Docs system is primarily composed of the following Python modules, each responsible for a specific part of the documentation generation pipeline:
1. cli.py (Command-Line Interface)
- Purpose: Provides the entry point for user interaction through the terminal. It defines commands such as
init,build,serve,scaffold,autodoc, andrender-changelog. - Functionality: Parses command-line arguments, dispatches tasks to the appropriate core components, and handles user feedback.
- Key Interaction: Acts as the orchestrator, invoking other modules based on user commands.
2. core.py (Builder and Development Server)
- Purpose: Contains the
Builderclass, responsible for the entire site generation process, and theDevServerfor local development with live reloading. BuilderFunctionality:- Loads
smartgen.ymlconfiguration. - Recursively processes the navigation structure defined in
smartgen.yml. - Reads Markdown files from the
docs/directory. - Converts Markdown to HTML using
MarkdownConverter. - Renders HTML content into Jinja2 templates (
page.html,page_premium.html). - Resolves internal links and static asset paths using
PathResolver. - Outputs the final static HTML files to the
site/directory.
- Loads
DevServerFunctionality: Starts a local web server, monitors changes in Markdown files andsmartgen.yml, and triggers live reloads in the browser during development.- Key Interaction: Integrates
MarkdownConverter,PathResolver, andThemeEngineto produce the final website.
3. converter.py (Markdown to HTML Conversion)
- Purpose: Handles the conversion of Markdown text into HTML.
- Functionality: Utilizes the
markdown2library with various extensions (e.g., fenced code blocks, tables, header IDs, TOC) to accurately parse and render Markdown syntax into HTML fragments. - Key Interaction: Used by the
Builderto transform raw Markdown content into web-ready HTML.
4. path_resolver.py (Path and URL Resolution)
- Purpose: Manages the resolution of relative and absolute paths within the generated documentation, ensuring correct linking across pages and to static assets.
- Functionality: Provides methods to calculate page depth, normalize paths, and generate correct relative URLs for navigation links, breadcrumbs, and static files, regardless of the current page's location.
- Key Interaction: Crucial for maintaining proper navigation and asset loading, especially in nested directory structures.
5. theme_engine.py (Templating and Theming)
- Purpose: Manages the application of themes and rendering of HTML pages using Jinja2 templates.
- Functionality: Loads Jinja2 templates (e.g.,
base.html,page.html) and injects converted Markdown content, navigation data, and configuration settings into them. Supports different themes (e.g.,default,premium). - Key Interaction: Works closely with the
Builderto wrap the generated HTML content within the chosen theme's layout.
6. scaffold.py (Project Scaffolding)
- Purpose: Automates the creation of initial project structure and placeholder Markdown files based on the
smartgen.ymlnavigation. - Functionality: Reads the
navsection ofsmartgen.ymland creates corresponding directories and.mdfiles if they don't already exist, populating them with basic boilerplate content. - Key Interaction: Primarily used during the
smartgen-docs initandsmartgen-docs scaffoldcommands to ensure a consistent project setup.
7. autodoc.py (API Documentation Generation)
- Purpose: Generates API reference documentation directly from Python module docstrings.
- Functionality: Inspects Python modules, classes, and functions to extract docstrings and signatures, then formats this information into Markdown files suitable for inclusion in the documentation.
- Key Interaction: Invoked by the
smartgen-docs autodoccommand to keep API documentation synchronized with the codebase.
8. changelog_renderer.py (Changelog Generation)
- Purpose: Renders a structured
changelog.jsonfile into a human-readable Markdown changelog. - Functionality: Reads a JSON file containing release information and formats it into a Markdown file, typically
docs/docs/changelog.md. - Key Interaction: Used by the
smartgen-docs render-changelogcommand to automate changelog updates.
Data Flow and Processing
The typical workflow in SmartGen Docs follows this sequence:
- Configuration Loading: The
Builderincore.pyloadssmartgen.ymlto understand site-wide settings and navigation. - Markdown Reading: For each page defined in the navigation, the
Builderreads the corresponding.mdfile from thedocs/directory. - Markdown Conversion: The
MarkdownConverterinconverter.pytransforms the Markdown content into HTML. - Template Rendering: The HTML content, along with navigation data and configuration, is passed to the
ThemeEngine(using Jinja2 templates fromtheme_engine.py) to render the full HTML page. - Path Resolution: During template rendering,
PathResolverensures all internal links, image paths, and static asset URLs are correctly resolved relative to the output HTML file. - Site Output: The final HTML pages, along with copied static assets (CSS, JS, images), are written to the
site/directory, ready for deployment.
This architecture ensures a clear separation of concerns, making SmartGen Docs robust, maintainable, and easy to extend for future enhancements.