Modular large file refactor

From fritzprix/libr-agent · View interactive version

Modular large file refactor is an AI agent skill from the GitHub repository fritzprix/libr-agent. Refactor oversized source files into smaller, coherent modules while reducing complexity and preserving behavior. Use when Claude needs to split a large component, hook, service, command handler, or Rust module; untangle mixed responsibilities; extract helpers or submodules; or reorganize code into

How to use this skill

Skill file

Modular Large File Refactor

Refactor one large file into a small set of focused modules without creating a mess of tiny shards. Optimize for lower cognitive load, stable public APIs, and obvious ownership boundaries.

Workflow

  1. Find the real target first. In this repository, start with the bundled scripts/find_large_files.sh helper instead of ad-hoc shell pipelines.
  2. Inspect the oversized file and list its responsibilities before touching code.
  3. Classify each block as one of: public API, orchestration, pure logic, state management, side effects, types, constants, or UI rendering.
  4. Choose the smallest useful module split that isolates responsibilities cleanly.
  5. Extract in safe order: constants/types first, pure helpers next, stateful logic after that, and orchestration last.
  6. Keep the original entrypoint stable unless the current public surface is the problem.
  7. Re-run the relevant validation after the split.

Built-in Large File Finder

Use the bundled script first:

bash scripts/find_large_files.sh

What it does well:

Use the script output to pick the biggest meaningful source file, then start the modular split.

Split Decision Rules

Extract a new module when the code has one clear responsibility.

Keep code together when separation would hide the story.

Extraction Order

1. Stabilize boundaries

2. Remove passive noise

3. Isolate pure logic

4. Isolate stateful logic

5. Simplify the entrypoint

Structural Targets

React and TypeScript

Rust

Cross-cutting rule

Complexity Reduction Moves

Anti-Patterns

Output Expectation

When you finish, describe the refactor in this shape:

  1. What responsibilities were identified in the original file
  2. Which modules were extracted and why
  3. Which public entrypoints stayed stable
  4. Which risky areas were checked after the split

Reference

Read references/splitting-patterns.md when you need concrete module patterns for React/TypeScript or Rust, or when the right split boundary is not obvious.

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.