Architecture¶
This document outlines how SpecSync coordinates data between a repository and an external workspace.
System Design¶
SpecSync is a command-line tool that orchestrates synchronization operations. It uses the local filesystem as the transport layer and respects Git workflows by keeping synced specs inside the repository.
The tool is built on a modular Python codebase located under src/specsync:
CLI layer (
specsync.cli): Parses user input and wiring for commands.Configuration (
specsync.config): Aggregates settings from flags, environment variables, andpyproject.toml.Synchronization core (
specsync.sync): Implements pulling and pushing logic, file diffing, and conflict handling.Frontmatter utilities (
specsync.frontmatter): Parses YAML metadata and filters eligible files.
Component Overview¶
Key Components¶
CLI Layer (
specsync.cli): Entry point, command parsing, and orchestrationConfiguration (
specsync.config): Merges settings from CLI flags, environment variables, andpyproject.tomlSync Engine (
specsync.sync): Core logic for bidirectional synchronizationFrontmatter Parser (
specsync.frontmatter): YAML metadata extraction and validationFile Selector (
specsync.selector): Applies filtering rules based on frontmatterFile System (
specsync.fs): Low-level file operations and Git integrationInteractive Prompts (
specsync.prompt): Conflict resolution and user interactionData Models (
specsync.models): Type-safe data structures for specs and configuration
Data Flow¶
The CLI determines intent (
pull,push, etc.) and requests configuration.Configuration is merged from command-line args, environment variables, and project defaults.
The sync engine scans the workspace and repository directories.
Frontmatter is parsed to select files with
expose: trueand matchingprojectfilters.Selected files are copied in the requested direction with conflict handling.
File Sync Algorithm¶
Scanning: Gather candidate files from both the workspace and repository directories.
Filtering: Apply frontmatter rules (exposure and project matching).
Diffing: Compare timestamps and file hashes to detect changes.
Conflict Resolution: When both sides changed, prompt the user unless
--forceis supplied.Apply Changes: Mirror files to the destination while preserving directory structure.
Frontmatter Filtering Logic¶
SpecSync reads YAML frontmatter located at the top of each Markdown file. The following rules apply:
Files missing
expose: trueare ignored whenrequire_exposeis enabled.When
match_projectis enabled, files must include aprojectkey matching the configured project name.Additional metadata is preserved and can be leveraged by other tooling but does not impact synchronization decisions.
Future iterations may extend the filter to support tag-based selection and more granular include/exclude patterns.