Skip to content

Mind Maps Generation Module

Status: Canonical Reference
Scope: Mind map generation tools in tools/mindmaps/
Last Updated: December 28, 2025 20:39:00
Created: December 10, 2025 14:57:12

This module generates interactive mind maps from NeetCode ontology and problem metadata.

Overview

The mind maps module provides: - 9 different mind map types visualizing different aspects of the problem space - Markdown output compatible with VS Code markmap extension - HTML output for GitHub Pages deployment - Configurable GitHub repository links

Module Structure

tools/mindmaps/
β”œβ”€β”€ core/                     # Core module (mind map generation logic)
β”‚   β”œβ”€β”€ __init__.py           # Module exports
β”‚   β”œβ”€β”€ config.py             # Configuration, constants, paths
β”‚   β”œβ”€β”€ toml_parser.py        # TOML parsing utilities
β”‚   β”œβ”€β”€ data.py               # ProblemData class
β”‚   β”œβ”€β”€ loader.py             # OntologyData and data loading
β”‚   β”œβ”€β”€ helpers.py            # Helper functions (frontmatter, formatting)
β”‚   β”œβ”€β”€ html.py               # HTML generation logic
β”‚   β”œβ”€β”€ templates.py          # HTML/CSS templates
β”‚   └── generators/           # Mind map generator functions
β”‚       β”œβ”€β”€ __init__.py
β”‚       β”œβ”€β”€ pattern.py        # Pattern hierarchy generator
β”‚       β”œβ”€β”€ family.py         # Family derivation generator
β”‚       β”œβ”€β”€ algorithm.py      # Algorithm/data structure usage
β”‚       β”œβ”€β”€ company.py        # Company coverage
β”‚       β”œβ”€β”€ roadmap.py        # Learning roadmaps
β”‚       β”œβ”€β”€ relations.py      # Problem relations network
β”‚       β”œβ”€β”€ variants.py       # Solution variants
β”‚       └── difficulty.py     # Difficulty Γ— Topics matrix
β”œβ”€β”€ ai-markmap-agent/         # AI-powered mindmap agent
β”œβ”€β”€ ai_mindmap/               # AI mindmap module
β”œβ”€β”€ hooks/                    # Git hooks
β”œβ”€β”€ prompts/                  # AI prompts
β”œβ”€β”€ shared/                   # Shared utilities
β”œβ”€β”€ tests/                    # Tests
β”œβ”€β”€ generate_mindmaps.py      # Rule-based generator (entry)
β”œβ”€β”€ generate_mindmaps_ai.py   # AI generator (entry)
└── html_meta_description_generator.py  # SEO meta generator

Core Components

Configuration (config.py)

Manages configuration for mind map generation: - GitHub repository URL and branch - Output directories - Mind map type definitions - Difficulty icons

Key Functions: - load_config() - Load configuration from file/env/defaults - get_config() - Get singleton config instance

TOML Parser (toml_parser.py)

Simple TOML parser for ontology files: - Handles arrays of tables [[array]] - Supports nested tables [table] - Parses strings, arrays, booleans, integers

Key Functions: - parse_toml_simple(content) - Parse TOML content - parse_toml_value(value) - Parse individual TOML values

Data Structures (data.py)

ProblemData - Represents a problem with metadata: - Properties: display_name, difficulty_icon - Methods: solution_link(), markdown_link(), leetcode_link()

Data Loading (loader.py)

OntologyData - Container for all ontology data: - API kernels, patterns, algorithms, data structures - Topics, difficulties, companies, roadmaps

Functions: - load_ontology() - Load all ontology files - load_problems() - Load problem metadata from TOML files

Helpers (helpers.py)

Utility functions: - markmap_frontmatter(title, color_freeze_level) - Generate YAML frontmatter - format_problem_entry(prob, show_complexity) - Format problem entry

HTML Generation (html.py)

HTML output generation: - generate_html_mindmap(title, markdown, use_autoloader) - Generate HTML file - markdown_to_html_content(markdown) - Extract content without frontmatter - setup_pages_directory(pages_dir) - Create directory structure

Templates (templates.py)

HTML templates and CSS: - HTML_TEMPLATE_MANUAL - Manual markmap initialization - HTML_TEMPLATE_AUTOLOADER - Using markmap-autoloader - INDEX_HTML_TEMPLATE - Index page template - STYLE_CSS - CSS stylesheet - CARD_TEMPLATE - Mind map card template

Generators (generators/)

Each generator function takes (ontology: OntologyData, problems: dict[str, ProblemData]) and returns a markdown string.

Available Generators:

  1. pattern.py - generate_pattern_hierarchy()
  2. API Kernel β†’ Patterns β†’ Problems hierarchy
  3. Shows how kernels are instantiated as patterns and used in problems

  4. family.py - generate_family_derivation()

  5. Base templates and derived variants
  6. Shows problem families with base/variant relationships

  7. algorithm.py - generate_algorithm_usage(), generate_data_structure()

  8. Algorithms/Data structures β†’ Problems mapping
  9. Shows which algorithms/data structures are used in which problems

  10. company.py - generate_company_coverage()

  11. Companies β†’ Problems mapping
  12. Shows problems frequently asked by companies

  13. roadmap.py - generate_roadmap_paths()

  14. Learning roadmap structures
  15. Shows curated problem sequences for different learning goals

  16. relations.py - generate_problem_relations()

  17. Related problems network
  18. Shows how problems are connected to each other

  19. variants.py - generate_solution_variants()

  20. Problems with multiple solution approaches
  21. Shows different solution strategies for the same problem

  22. difficulty.py - generate_difficulty_topics()

  23. Difficulty Γ— Topics matrix
  24. Shows topics organized by difficulty level

Usage Examples

Basic Usage

from mindmaps.core import (
    load_ontology,
    load_problems,
    GENERATORS,
)

# Load data
ontology = load_ontology()
problems = load_problems()

# Generate a specific mind map
content = GENERATORS["pattern_hierarchy"](ontology, problems)
print(content)

Generate HTML

from mindmaps.core import generate_html_mindmap

markdown = "# Test Map\n\n## Section"
html = generate_html_mindmap("Test Title", markdown, use_autoloader=False)

Custom Configuration

from mindmaps.core import get_config, MindmapsConfig
import os

# Override via environment variables
os.environ["GITHUB_REPO_URL"] = "https://github.com/user/repo"
os.environ["GITHUB_BRANCH"] = "main"

config = get_config()
print(config.github_repo_url)

Mind Map Types

Type Description Generator
pattern_hierarchy API Kernels β†’ Patterns β†’ Problems pattern.py
family_derivation Base templates β†’ Variants family.py
algorithm_usage Algorithms β†’ Problems algorithm.py
data_structure Data Structures β†’ Problems algorithm.py
company_coverage Companies β†’ Problems company.py
roadmap_paths Learning Roadmaps roadmap.py
problem_relations Related Problems Network relations.py
solution_variants Multiple Solutions variants.py
difficulty_topics Difficulty Γ— Topics Matrix difficulty.py

Configuration File

Create tools/mindmaps/generate_mindmaps.toml:

[github]
repo_url = "https://github.com/user/repo"
branch = "main"

[links]
use_github_links = true

Output Format

Markdown Output

Each mind map is a Markdown file with YAML frontmatter:

---
title: Pattern Hierarchy - API Kernels β†’ Patterns β†’ Problems
markmap:
  colorFreezeLevel: 2
  maxWidth: 400
---

# Pattern Hierarchy

## API Kernel Name
*Description*

### Pattern Name
*Pattern description*

- 🟑 [LeetCode 3 - Problem Name](link)

HTML Output

HTML files include: - Full markmap library integration - Custom toolbar (Fit View, Expand All, Collapse All) - Responsive design - GitHub Pages ready

Testing

The module is tested in .dev/tests/test_generate_mindmaps.py:

python -m pytest .dev/tests/test_generate_mindmaps.py -v

Test coverage includes: - TOML parsing - Data loading - All 9 generator functions - HTML generation - Configuration loading - Edge cases

Development

Adding a New Generator

  1. Create a new file in core/generators/ (e.g., custom.py)
  2. Implement generator function:
    def generate_custom(ontology: OntologyData, problems: dict[str, ProblemData]) -> str:
        lines = [markmap_frontmatter("Custom Map"), "# Custom Map", ""]
        # ... generation logic ...
        return "\n".join(lines)
    
  3. Add to core/generators/__init__.py:
    from .custom import generate_custom
    GENERATORS["custom"] = generate_custom
    
  4. Add to MINDMAP_TYPES in core/config.py
  5. Add tests in .dev/tests/test_generate_mindmaps.py

Module Size Guidelines

  • Each file should be < 100 lines (except templates)
  • Each generator function should be < 80 lines
  • Keep functions focused and single-purpose

See Also