Skip to main content

MOFF - Markdown Organization and Format Framework. A CLI tool for validating documentation structure.

Project description

MOFF CLI

Markdown Organization and Format Framework

A command-line tool for validating and maintaining clean, organized documentation. Designed to work seamlessly with Large Language Models (LLMs) in modern IDEs like Cursor, VSCode, and Zed.

Python Version License: MIT

๐ŸŽฏ Purpose

MOFF helps maintain consistent documentation structure across projects by:

  • Validating markdown files against configurable rules
  • Enforcing location constraints for different document types
  • Checking frontmatter schemas and required fields
  • Ensuring headers follow specified patterns and order
  • Providing visual feedback through tree visualization

Perfect for projects where documentation quality and consistency matter, especially when working with AI assistants that parse markdown documentation.

โœจ Features

  • ๐Ÿ“ Smart Root Detection: Automatically finds documentation root via project_*.md files
  • ๐Ÿ” Comprehensive Validation: Check frontmatter, headers, and file locations
  • ๐ŸŒณ Tree Visualization: See your documentation structure with error highlighting
  • โš™๏ธ Configurable Rules: Define custom prefixes, patterns, and validation rules
  • ๐Ÿ’พ Result Persistence: Save validation results for CI/CD integration
  • ๐ŸŽจ Rich Terminal Output: Beautiful, colored output using Rich library

๐Ÿ“ฆ Installation

Using pip

pip install moff-cli

Using uv (recommended)

uv add moff-cli

๐Ÿš€ Quick Start

  1. Check your documentation (creates settings.json automatically if not present):
moff check
  1. Visualize documentation structure:
moff tree

๐Ÿ“– Usage

Commands Overview

moff --help                    # Show help information
moff --version                 # Show version

moff check                     # Run validation checks
moff check --save             # Run checks and save results to moff_results.txt
moff check --path ./docs      # Check specific directory

moff tree                      # Display documentation tree
moff tree --errors-only       # Show only files with errors
moff tree --no-check          # Skip validation (faster)

Example: Setting Up a Project

  1. Create a project file (project_myapp.md):
---
project: myapp
---

# Overview

This is my application's main documentation.

## Requirements

- Python 3.12+
- Rich library
  1. Create feature documentation (features/feature_auth.md):
---
project: myapp
feature: authentication
linked_features: ["users", "sessions"]
---

# Overview

Authentication system for the application.

## Requirements

- Secure password hashing
- JWT token support
- Session management
  1. Validate your documentation (this will create settings.json if it doesn't exist):
moff check

Example Output

Check Command

Collecting documentation files...
Root directory: /Users/you/project/docs

โœ“ All checks passed!

No validation issues found.

Or with errors:

Validation Summary:
  Total issues: 2
  Errors: 2

Issues found:

features/feature_broken.md:
  error [feature] headers.missing: Missing required header level=2 text='Requirements' (line 10)

tech_database.md:
  error [tech] location.subdirs_only: File must be in a subdirectory, not in root

Tree Command

๐Ÿ“ docs (documentation root)
โ”œโ”€โ”€ ๐Ÿ“ features
โ”‚   โ”œโ”€โ”€ โšก feature_auth.md โœ“
โ”‚   โ””โ”€โ”€ โšก feature_users.md โœ“
โ”œโ”€โ”€ ๐Ÿ“ technical
โ”‚   โ””โ”€โ”€ ๐Ÿ”ง tech_database.md โœ“
โ””โ”€โ”€ ๐Ÿ“‹ project_myapp.md โœ“

Summary:
  Total markdown files: 4
  Files with errors: 0
  Files with warnings: 0

โœ“ All files passed validation!

๐Ÿ Programmatic Usage

When installed via pip, moff-cli can also be used as a Python library. Import it as moff_cli:

Basic Validation

from pathlib import Path
from moff_cli import Settings, Collector, Checker

# Load settings and collect documentation
settings = Settings()
collector = Collector(settings, start_path=Path.cwd())
collected_data = collector.collect()

# Run validation
checker = Checker(settings)
diagnostics = checker.check(collected_data)

# Process results
if not diagnostics:
    print("โœ“ All documentation is valid!")
else:
    for diag in diagnostics:
        print(f"{diag.path}: {diag.message}")

Custom Configuration

from moff_cli import (
    Settings,
    PrefixConfig,
    LocationConstraint,
    HeaderRule,
    HeaderMatch
)

# Create custom settings
settings = Settings()

# Add a custom prefix for API documentation
settings.prefixes["api"] = PrefixConfig(
    filename_pattern="api_*.md",
    location=LocationConstraint.SUBDIRS_ONLY,
    frontmatter_required={
        "endpoint": "string",
        "method": "string",
        "version": "string"
    },
    headers_required=[
        HeaderRule(level=1, text="Endpoint"),
        HeaderRule(level=2, text="Request"),
        HeaderRule(level=2, text="Response"),
    ]
)

# Save custom settings
settings.save_to_file(Path("settings.json"))

Tree Visualization

from moff_cli import Settings, Collector, Checker, TreeVisualizer
from rich.console import Console

console = Console()
settings = Settings()

# Collect and check
collector = Collector(settings)
collected_data = collector.collect()
checker = Checker(settings)
diagnostics = checker.check(collected_data)

# Display tree with error highlighting
visualizer = TreeVisualizer(settings, console)
visualizer.show_tree(collected_data, diagnostics)

CI/CD Integration

from pathlib import Path
from moff_cli import Settings, Collector, Checker, Severity

def validate_docs(project_path: Path) -> bool:
    """Validate documentation for CI/CD pipeline."""
    settings = Settings()
    collector = Collector(settings, start_path=project_path)
    checker = Checker(settings)

    # Collect and check
    collected = collector.collect()
    if collected.get("error"):
        print(f"ERROR: {collected['error']}")
        return False

    diagnostics = checker.check(collected)

    # Filter to only errors (ignore warnings)
    errors = [d for d in diagnostics if d.severity == Severity.ERROR]

    if errors:
        print(f"Validation failed with {len(errors)} errors")
        for error in errors:
            print(f"  โœ— {error.path}: {error.message}")
        return False

    return True

# Use in CI/CD
if not validate_docs(Path(".")):
    exit(1)

Available Classes and Functions

  • Settings: Configuration management
  • Collector: File discovery and parsing
  • Checker: Validation engine
  • TreeVisualizer: Tree visualization
  • Diagnostic: Validation issue representation
  • Severity: Error, Warning, Info levels
  • LocationConstraint: ROOT_ONLY, SUBDIRS_ONLY, ANY
  • HeaderOrder: STRICT, IN_ORDER, ANY
  • HeaderMatch: EXACT, REGEX

โš™๏ธ Configuration

MOFF uses settings.json for configuration. The default configuration supports three document prefixes:

Default Prefixes

Prefix Pattern Location Purpose
project project_*.md Root only Main project documentation
feature feature_*.md Any Feature specifications
tech tech_*.md Subdirs only Technical implementation details

Custom Configuration Example

{
  "version": 1,
  "root": {
    "detect": {
      "method": "project_file",
      "pattern": "project_*.md"
    },
    "override_path": null,
    "ignore": [
      "**/.git/**",
      "**/.venv/**",
      "**/node_modules/**",
      "**/archive/**"
    ]
  },
  "prefixes": {
    "api": {
      "filename": {
        "pattern": "api_*.md"
      },
      "location": "subdirs_only",
      "frontmatter": {
        "required": {
          "project": "string",
          "endpoint": "string",
          "method": "string"
        },
        "optional": {
          "deprecated": "boolean"
        }
      },
      "headers": {
        "required": [
          {
            "level": 1,
            "text": "Endpoint",
            "match": "exact"
          },
          {
            "level": 2,
            "text": "Request",
            "match": "exact"
          },
          {
            "level": 2,
            "text": "Response",
            "match": "exact"
          }
        ],
        "optional": [],
        "order": "in-order"
      }
    }
  }
}

Configuration Options

Root Detection

  • detect.method: Currently supports "project_file"
  • detect.pattern: Glob pattern for root detection (default: "project_*.md")
  • override_path: Bypass auto-detection with explicit path
  • ignore: List of glob patterns to exclude

Location Constraints

  • "root_only": File must be in root directory
  • "subdirs_only": File must be in a subdirectory
  • "any": File can be anywhere

Frontmatter Types

  • "string": Text values
  • "number": Numeric values (int or float)
  • "boolean": True/false values
  • "list": Array values
  • "object": Dictionary/object values

Header Order

  • "strict": Headers must appear in exact order
  • "in-order": Headers must be in order but others can appear between
  • "any": No order enforcement

๐Ÿ“ License

This project is licensed under the MIT License - see the LICENSE file for details.

๐Ÿ™ Acknowledgments

  • Built with Rich for beautiful terminal output
  • Uses markdown-to-data for parsing
  • Inspired by the need for better documentation tooling in AI-assisted development

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

moff_cli-0.1.0.tar.gz (63.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

moff_cli-0.1.0-py3-none-any.whl (23.7 kB view details)

Uploaded Python 3

File details

Details for the file moff_cli-0.1.0.tar.gz.

File metadata

  • Download URL: moff_cli-0.1.0.tar.gz
  • Upload date:
  • Size: 63.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.7.20

File hashes

Hashes for moff_cli-0.1.0.tar.gz
Algorithm Hash digest
SHA256 b871a741c7c254d2cb48ad74c3de79446b32cf711007f3760755d8e5c8b070c7
MD5 cd8200d4a92dc350b5ee2e71955961e7
BLAKE2b-256 a3bf368490ad7a1ad9733f49c081c04c5551ce25a14eac48f4f967b0043ee340

See more details on using hashes here.

File details

Details for the file moff_cli-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: moff_cli-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 23.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.7.20

File hashes

Hashes for moff_cli-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 63a437ca840b8dc5cfa5612b5886bdfe526995fb4dcfeb8c711c8283eeb00b64
MD5 bf31a76b485c386fcafe7c5c979c68a2
BLAKE2b-256 7a41c0c96c8e5f66be42841ce1779b2edc31b6042a2092e166f7764c7f91e839

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page