# Where Are Fabric's Built‑in Patterns Stored? A Deep Dive into the Source Code

> Discover where Fabric's built-in patterns are stored in the source code. A deep dive into the data patterns directory and its system md files reveals all.

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

---

**Fabric’s built‑in patterns are stored in the `data/patterns/` directory of the repository, with each pattern containing a [`system.md`](https://github.com/danielmiessler/fabric/blob/main/system.md) file and optionally a [`user.md`](https://github.com/danielmiessler/fabric/blob/main/user.md) file.**

Understanding the storage architecture of the danielmiessler/fabric repository is essential for developers who want to customize AI workflows or contribute new templates. Fabric maintains a strict separation between its default **built‑in patterns** and user-defined customizations, with the core definitions living in version-controlled source files rather than ephemeral configuration.

## The Core Storage Location: `data/patterns/`

All default patterns originate from the **`data/patterns/`** directory at the repository root. This folder contains subdirectories where each folder name represents an available pattern (e.g., `analyze_paper`, `create_command`, `extract_alpha`).

Every pattern directory follows a strict file convention:

- **[`system.md`](https://github.com/danielmiessler/fabric/blob/main/system.md)** – Required. Contains the system prompt that defines the AI's role and instructions.
- **[`user.md`](https://github.com/danielmiessler/fabric/blob/main/user.md)** – Optional. Provides a template for user input formatting.

When you clone the repository, these files exist as plain Markdown at paths like [`data/patterns/analyze_paper/system.md`](https://github.com/danielmiessler/fabric/blob/main/data/patterns/analyze_paper/system.md). They serve as the immutable source of truth for Fabric's default capabilities.

## How Fabric Loads Built‑in Patterns at Runtime

Fabric does not execute patterns directly from the repository directory. Instead, it maintains a local **patterns database** that syncs with the source files during initialization.

### The Patterns Database and User Config Directory

When Fabric initializes, it creates a **`PatternsEntity`** (defined in [`internal/plugins/db/fsdb/patterns.go`](https://github.com/danielmiessler/fabric/blob/main/internal/plugins/db/fsdb/patterns.go)) that points to a user-specific configuration directory, typically located at `~/.config/fabric/patterns`.

If this directory is empty on first run, Fabric triggers a setup process to populate it with the built‑in set. The database abstraction allows the CLI to treat built‑in and custom patterns uniformly through the `fsdb.PatternsEntity` interface.

### The PatternsLoader Implementation

The synchronization logic resides in **[`internal/tools/patterns_loader.go`](https://github.com/danielmiessler/fabric/blob/main/internal/tools/patterns_loader.go)**. This component handles two critical operations:

1. **Clone or locate** the upstream repository (or use the local working copy).
2. **Copy** the contents of `data/patterns/` into the user's config directory.

This design ensures users always have a local copy of the built‑in patterns to modify or reference, while the original source remains pristine in the repository.

## Listing and Retrieving Patterns Programmatically

You can interact with the pattern storage both through the Go API and the command line.

### Using the Go API

In [`internal/plugins/db/fsdb/patterns.go`](https://github.com/danielmiessler/fabric/blob/main/internal/plugins/db/fsdb/patterns.go), the `PatternsEntity` provides methods to enumerate and fetch patterns:

```go
// Load the patterns entity (created in core/plugin_registry.go)
patterns := core.Db.Patterns // *fsdb.PatternsEntity

// List all available pattern names (built‑in + custom)
names, err := patterns.GetNames()
if err != nil { log.Fatal(err) }
fmt.Println("Available patterns:")
for _, n := range names {
    fmt.Println("- " + n)
}

// Retrieve a specific built‑in pattern
p, err := patterns.Get("analyze_paper")
if err != nil { log.Fatal(err) }
fmt.Println("System prompt:", p.SystemPrompt) // content of data/patterns/analyze_paper/system.md

```

### Using the CLI

The `--listpatterns` flag, implemented in [`internal/cli/listing.go`](https://github.com/danielmiessler/fabric/blob/main/internal/cli/listing.go) and declared in [`internal/cli/flags.go`](https://github.com/danielmiessler/fabric/blob/main/internal/cli/flags.go), queries the same database:

```bash

# Using the CLI to list built‑in patterns

fabric --listpatterns

# Output:

#   analyze_paper

#   create_command

#   extract_alpha

#   … (all pattern directories under data/patterns)

```

## Custom Patterns vs. Built‑in Patterns

While the **`data/patterns/`** directory holds the immutable defaults, Fabric supports user extensions through a separate **`CUSTOM_PATTERNS_DIRECTORY`** environment variable. 

The `PatternsEntity` aggregates both sources, meaning `patterns.GetNames()` returns a unified list. However, when Fabric initializes an empty configuration, it only seeds the local directory with contents from `data/patterns/`. Custom patterns added later exist entirely outside the repository structure, preventing merge conflicts during updates.

## Summary

- **Source location**: Built‑in patterns live in `data/patterns/` within the danielmiessler/fabric repository.
- **File structure**: Each pattern requires [`system.md`](https://github.com/danielmiessler/fabric/blob/main/system.md) and optionally includes [`user.md`](https://github.com/danielmiessler/fabric/blob/main/user.md).
- **Runtime storage**: Patterns are copied to `~/.config/fabric/patterns` via the `PatternsLoader` in [`internal/tools/patterns_loader.go`](https://github.com/danielmiessler/fabric/blob/main/internal/tools/patterns_loader.go).
- **API access**: The `fsdb.PatternsEntity` class in [`internal/plugins/db/fsdb/patterns.go`](https://github.com/danielmiessler/fabric/blob/main/internal/plugins/db/fsdb/patterns.go) provides `GetNames()` and `Get()` methods for retrieval.
- **CLI access**: Use `fabric --listpatterns` to enumerate available patterns.

## Frequently Asked Questions

### Where are Fabric patterns stored on my local machine?

After initialization, Fabric stores copies of built‑in patterns in your user configuration directory, typically at `~/.config/fabric/patterns` on Linux/macOS systems. This local copy is created by the `PatternsLoader` when you first run the application, cloning or copying from the repository's `data/patterns/` source.

### What files make up a Fabric pattern?

Every Fabric pattern consists of at least one required file: **[`system.md`](https://github.com/danielmiessler/fabric/blob/main/system.md)**, which contains the system prompt defining the AI's behavior. Patterns may also include an optional **[`user.md`](https://github.com/danielmiessler/fabric/blob/main/user.md)** file that serves as a template for structuring user input. These files reside in a directory named after the pattern itself.

### How do I list all available patterns in Fabric?

You can enumerate patterns using the CLI flag `--listpatterns` (defined in [`internal/cli/flags.go`](https://github.com/danielmiessler/fabric/blob/main/internal/cli/flags.go) and implemented in [`internal/cli/listing.go`](https://github.com/danielmiessler/fabric/blob/main/internal/cli/listing.go)), which queries the `fsdb.PatternsEntity`. Alternatively, use the Go API method `patterns.GetNames()` to retrieve a slice of all pattern names available in the current database.

### Can I modify the built‑in patterns directly in the repository?

While you can edit files in `data/patterns/` within the repository, these changes only affect new installations or initial setups. Fabric copies these files to your user config directory on first run, and subsequent executions read from that local copy. To modify pattern behavior permanently for your environment, edit the files in `~/.config/fabric/patterns/` or create custom patterns in a separate directory referenced by `CUSTOM_PATTERNS_DIRECTORY`.