Migrate layered module splitting

From lamg/migrate · View interactive version

Migrate layered module splitting is an AI agent skill from the GitHub repository lamg/migrate. Use when an F# source file or module mixes stacked responsibility layers whose dependency direction should be made explicit through files, modules, and a stable facade.

How to use this skill

Skill file

Migrate Layered Module Splitting

Core principle

A module split should make the reasoning structure of the program explicit.

Do not split files because they are large. Split them when they contain several different levels of knowledge: primitives, metadata, planning, execution, orchestration, or public API composition. A good split lets the reader understand each layer as a smaller problem with a precise obligation, then understand the top layer as composition of those obligations.

Layering is useful when it reduces the number of facts that must be held in mind at once. Lower layers should solve stable, narrower problems. Higher layers should express policy, workflow, and composition. The dependency direction should follow the direction of reasoning: higher layers may use lower layers, but lower layers must not know the stories told above them.

What counts as a layer

A layer is not merely a group of functions with similar names. A layer owns a distinct kind of knowledge.

Good layer boundaries often separate:

Weak boundaries usually separate:

When to apply

Design rule

Splitting procedure

  1. Identify the public story the original file tells.
  2. Identify the kinds of knowledge mixed into that file.
  3. Order those responsibilities from most primitive to most orchestration-oriented.
  4. Check that dependencies can flow upward without cycles.
  5. Create a directory named after the original area or module.
  6. Create one source file per layer, ordered from lower to higher responsibility.
  7. Add a top-level facade file or module that preserves the public surface when needed.
  8. Update the .fsproj compile order to match the layer order.
  9. Add a README.md that records the responsibilities and dependency direction.
  10. Re-read the top layer and verify that it now describes composition instead of implementation mechanics.

File layout guidance

Prefer names that identify the responsibility, not the extraction event.

Good layer names include:

Avoid names that describe only mechanics or chronology:

An idiomatic split often looks like this:

Area/
  README.md
  Types.fs
  Metadata.fs
  Planning.fs
  Execution.fs
  Operations.fs
Area.fs

The lowest file should compile first. The public facade should compile after the internal layers it exposes or composes.

README requirements

Write the README.md in English and include:

The README is part of the design. It should let a future maintainer place new code without rediscovering the architecture.

F# project requirements

When not to apply

Relation to function design

Use migrate-layered-function-design first when the problem is only inside one function.

Use this skill when the same lower-level obligations have become a file-level responsibility with its own vocabulary, dependency direction, and compile-order consequences.

Checklist

Validation

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.