# Fabric Pattern Loader Code: Path and Implementation in the Fabric Repository

> Locate Fabric pattern loader code at internal/tools/patterns_loader.go in the danielmiessler/fabric repo. Discover its implementation for parsing, validating, and registering pattern definitions.

- Repository: [Daniel Miessler 🛡️/fabric](https://github.com/danielmiessler/fabric)
- Tags: how-to-guide
- Published: 2026-02-28

---

**The Fabric pattern loader code is located at [`internal/tools/patterns_loader.go`](https://github.com/danielmiessler/fabric/blob/main/internal/tools/patterns_loader.go) in the danielmiessler/fabric repository, where it handles parsing, validating, and registering pattern definitions for the AI augmentation framework.**

Understanding the Fabric pattern loader code is essential for developers looking to extend or debug the Fabric system's pattern management capabilities. This component serves as the backbone for loading custom AI patterns from the filesystem, ensuring they meet the required schema before making them available to the CLI tools. Whether you are contributing new patterns or integrating Fabric into your workflow, knowing where this loader resides and how it functions will help you navigate the codebase effectively.

## Locating the Fabric Pattern Loader Code

The primary implementation of the pattern loader resides in a single Go source file within the repository's internal tools directory.

You can find the exact path here:

```

internal/tools/patterns_loader.go

```

View the source directly on GitHub at [danielmiessler/fabric/internal/tools/patterns_loader.go](https://github.com/danielmiessler/fabric/blob/main/internal/tools/patterns_loader.go). This file contains the core logic that defines how Fabric discovers, reads, and initializes pattern definitions from the local filesystem.

## Core Functionality of the Pattern Loader

The Fabric pattern loader code performs three critical operations: parsing pattern definition files, validating their structure against expected schemas, and registering them for use within the Fabric CLI ecosystem.

### Pattern Loading Process

When invoked, the loader scans designated directories (typically `./patterns` or the system patterns directory) for JSON definition files. It constructs a loader instance that manages the lifecycle of these pattern objects, reading each file into memory and preparing it for validation.

### Validation and Registration

After loading, the code validates that each pattern contains required fields such as name, description, and system prompts. Once validation passes, the loader registers the pattern with the Fabric runtime, making it available for selection via the `--pattern` flag in CLI commands.

## Usage Examples

While the Fabric pattern loader code is typically invoked internally by the CLI, you can interact with it programmatically if building custom tooling around Fabric.

Here is a minimal example demonstrating how the loader interface works:

```go
// Example: load patterns from a directory
loader := patterns.NewLoader()
err := loader.LoadFromDir("./patterns")
if err != nil {
    log.Fatalf("failed to load patterns: %v", err)
}

```

In production usage, you typically run the loader via the Fabric CLI rather than direct Go code. The CLI entry point in [`cmd/fabric/main.go`](https://github.com/danielmiessler/fabric/blob/main/cmd/fabric/main.go) wires up this loader automatically when you execute pattern-related commands.

## Related Files and Entry Points

Understanding the Fabric pattern loader code requires familiarity with several related components in the repository:

- **[`internal/tools/patterns_loader.go`](https://github.com/danielmiessler/fabric/blob/main/internal/tools/patterns_loader.go)** — Core loader logic for patterns; parses, validates, and registers them.
- **[`cmd/fabric/main.go`](https://github.com/danielmiessler/fabric/blob/main/cmd/fabric/main.go)** — CLI entry point that wires up the pattern loader among other commands.
- **`data/strategies/*.json`** — Example pattern definition files that the loader processes during runtime.

These files work together to provide the complete pattern management functionality that Fabric users interact with through the command line interface.

## Summary

- The Fabric pattern loader code is located at [`internal/tools/patterns_loader.go`](https://github.com/danielmiessler/fabric/blob/main/internal/tools/patterns_loader.go) in the danielmiessler/fabric repository.
- It handles parsing JSON pattern definitions, validating their structure, and registering them for CLI use.
- The loader is typically invoked through the Fabric CLI entry point at [`cmd/fabric/main.go`](https://github.com/danielmiessler/fabric/blob/main/cmd/fabric/main.go), though it can be used programmatically.
- Pattern definitions are stored as JSON files, often found in directories like `data/strategies/` or user-defined pattern folders.

## Frequently Asked Questions

### Where is the Fabric pattern loader code located?

The Fabric pattern loader code resides in the file [`internal/tools/patterns_loader.go`](https://github.com/danielmiessler/fabric/blob/main/internal/tools/patterns_loader.go) within the danielmiessler/fabric repository. This path contains the complete implementation for loading, validating, and registering pattern definitions used by the Fabric CLI.

### What does the pattern loader do in Fabric?

The pattern loader parses JSON pattern definition files from the filesystem, validates that they contain required fields like name and system prompts, and registers them with the Fabric runtime. This makes custom AI patterns available for selection via the `--pattern` flag when running Fabric commands.

### How do I use the Fabric pattern loader in my own code?

You can instantiate the loader programmatically by calling `patterns.NewLoader()` and then invoking `LoadFromDir()` with your patterns directory path. However, most users interact with the loader indirectly through the Fabric CLI, which automatically handles pattern loading when executing commands.

### What file formats does the Fabric pattern loader support?

The Fabric pattern loader primarily supports JSON files containing pattern definitions. These files typically include metadata such as pattern name, description, and system prompts, and are commonly stored in directories like `data/strategies/` or user-specified pattern folders.