La Famille / Field notes
Architecture & Component Map
This document maps the major components residing in the internal/ directory
and records the micro-improvements identified during the component audit.
It consolidates the earlier component-mapping reports.
Part 1: Component Identification
Here is the architectural map of the major components located in the internal/ directory, detailing their primary responsibilities:
internal/generator: Orchestrates the core site build process. It manages output path claims (preventing collisions), builds sites in a temporary staging directory, and performs atomic directory swaps.internal/render: Handles HTML template parsing and execution. Utilizessync.RWMutexfor safe concurrent caching and loading of layouts.internal/transform: Walks the Markdown AST (via Goldmark) to process links, rewrite local relative.mdpaths to final URLs, and track site-wide backlinks.internal/asset: Manages static asset syncing. Safely copies assets to the output directory while respecting.gitignorerules and preventing path traversal bounds violations.internal/search: Builds minified JSON search indices by stripping Markdown/HTML noise and extracting clean text snippets and headings.internal/taxonomy: Processes frontmatter tags, body hashtags, and categories to generate corresponding taxonomy index pages and grouped listings.internal/graph: Compiles structural site data to construct the Knowledge Graph explorer payload (JSON), mapping page relationships and backlinks.internal/ragexport: Generates RAG-optimized export bundles, assembling the site’s content into clean Markdown for consumption by LLMs.internal/config: Responsible for configuration parsing (YAML), structural defaults, and strict validation (e.g., verifyingOutputDirsafely isolates from source inputs).internal/content: Reads local files to parse YAML frontmatter and separate it from the raw Markdown body, resolving canonical key spellings and coercing data types.internal/stub: Provides fallback generation mechanisms, dynamically creating stub placeholder pages for internal links targeting missing files.internal/page: Defines the data models (e.g.,Pagestruct) and view variables passed into HTML templates during the render phase.internal/sitedata: Generates aggregate site-wide metadata artifacts (likemeta.jsonor sitemaps) into the output directory.internal/markdown: Configures the Goldmark Markdown engine, seamlessly registering extensions like GFM and Typographer for standardized rendering.internal/git: Executes local git subprocesses to analyze branch status and check for uncommitted working tree changes.internal/github: Manages GitHub API interactions, allowing the system to list open Pull Requests and execute automated sync/merge policies.internal/watcher: Provides local development capabilities by bindingfsnotifyfor debounced file watching and running an SSE server for live-reload updates.
Part 2: Micro-Improvements
Based on the audit, here are the high-ROI localized micro-improvements to enhance memory efficiency, safety, and performance:
- Struct Field Alignment (
internal/config/config.go): In theConfigstruct, boolean fields (likeWatchModeandCheckAssetHealth) are interspersed with larger fields (likePort). This alignment creates unnecessary padding holes. By reordering the struct to group the larger fields before the 1-byte booleans, you can pack them tightly and save bytes per struct instance. - Slice Pre-allocation (
internal/asset/copy.go): InParseIgnoreRules,strings.Split(contents, "\n")produces a statically sized slice of lines. However, therulesslice is dynamically appended to without pre-allocation. Initializing it withrules := make([]IgnoreRule, 0, len(lines))avoids unnecessary slice capacity expansions and memory copying. - Enhanced Error Wrapping (
internal/asset/copy.go): Within the asset copying routine, failing operations likeos.Chtimessimply returnerr. Wrapping these calls withfmt.Errorf("failed to sync asset: %w", err)provides crucial context, ensuring logs clearly indicate exactly which file caused the sync to halt. - Optimize HTML Live-reload Injection (
internal/render/render.go): When dynamically injecting the SSE livereload script into rendered pages during WatchMode, usestrings.LastIndexto locate the</body>tag. Then, append the script block utilizing a pre-allocatedstrings.Builder(withsb.Grow()), which prevents the heavy allocation footprint of standardstrings.Replaceor byte slice operations on large HTML documents. - Slice Pre-allocation (
internal/search/search.go): InExtractHeadings,strings.Split(string(rest), "\n")produces a known count of lines. Theheadingsslice is appended to dynamically. Since the maximum number of headings cannot exceed the number of lines, initialising it withmake([]string, 0, len(lines)/4)or similar capacity estimation could save multiple reallocations during extraction. - Map-based Taxonomy Uniqueness (
internal/taxonomy/taxonomy.go): When collecting unique taxonomy items (like tags or categories) during the generation phase, the current implementation iterates to ensure uniqueness before appending. Relying entirely on map sets and converting them to slices once at the end reduces potential linear search debt when combining taxonomy paths.