module-based-refactor

Reorganize a repository from flat structure to a module-based 5-layer architecture (src/tests/specs/docs/examples) while preserving git history. Use when restructuring a codebase into modules, migrating import paths, cleaning up hidden folders, consolidating duplicate directories, removing root-level artifacts, or archiving completed plan files. Capabilities: parallel agent spawn strategy, hidden-folder consolidation patterns, benchmark fixture separation, 4-phase atomic commit workflow.

5 stars

Best use case

module-based-refactor is best used when you need a repeatable AI agent workflow instead of a one-off prompt.

Reorganize a repository from flat structure to a module-based 5-layer architecture (src/tests/specs/docs/examples) while preserving git history. Use when restructuring a codebase into modules, migrating import paths, cleaning up hidden folders, consolidating duplicate directories, removing root-level artifacts, or archiving completed plan files. Capabilities: parallel agent spawn strategy, hidden-folder consolidation patterns, benchmark fixture separation, 4-phase atomic commit workflow.

Teams using module-based-refactor should expect a more consistent output, faster repeated execution, less prompt rewriting.

When to use this skill

  • You want a reusable workflow that can be run more than once with consistent structure.

When not to use this skill

  • You only need a quick one-off answer and do not need a reusable workflow.
  • You cannot install or maintain the underlying files, dependencies, or repository context.

Installation

Claude Code / Cursor / Codex

$curl -o ~/.claude/skills/module-based-refactor/SKILL.md --create-dirs "https://raw.githubusercontent.com/vamseeachanta/workspace-hub/main/.agents/skills/_internal/meta/module-based-refactor/SKILL.md"

Manual Installation

  1. Download SKILL.md from GitHub
  2. Place it in .claude/skills/module-based-refactor/SKILL.md inside your project
  3. Restart your AI agent — it will auto-discover the skill

How module-based-refactor Compares

Feature / Agentmodule-based-refactorStandard Approach
Platform SupportNot specifiedLimited / Varies
Context Awareness High Baseline
Installation ComplexityUnknownN/A

Frequently Asked Questions

What does this skill do?

Reorganize a repository from flat structure to a module-based 5-layer architecture (src/tests/specs/docs/examples) while preserving git history. Use when restructuring a codebase into modules, migrating import paths, cleaning up hidden folders, consolidating duplicate directories, removing root-level artifacts, or archiving completed plan files. Capabilities: parallel agent spawn strategy, hidden-folder consolidation patterns, benchmark fixture separation, 4-phase atomic commit workflow.

Where can I find the source code?

You can find the source code on GitHub using the link provided at the top of the page.

Related Guides

SKILL.md Source

# Module-Based Refactor Skill

Reorganize a repository from flat to a consistent module-based 5-layer
architecture while preserving git history. Handles cleanup of artifacts,
runtime data, and hidden folders.

See `references/patterns.md` for: full checklists, hidden-folder
consolidation patterns, cleanup categories table, benchmark reorganization,
complete session workflow, metrics tracking, and common issues/solutions.

## When to Use

- Reorganizing a flat repository to module-based layout
- Consolidating scattered modules into a unified hierarchy
- Migrating import paths while preserving git history
- Cleaning up root-level artifacts (logs, temp files, build artifacts)
- Consolidating duplicate directories (agents/, coordination/, memory/)
- Reviewing and removing obsolete hidden folders

## Pre-flight Checks

Run before starting any reorganization:

```bash
# Git tracking status
git ls-files | head -50
git ls-files --others --exclude-standard | grep -v "/"

# Duplicate directory detection
find . -type d -name "skills" -o -name "agents" 2>/dev/null

# Hidden folder inventory
ls -la .* 2>/dev/null | grep "^d"

# Stale artifacts at root
ls *.log *.tmp *.html *.sim 2>/dev/null
```

## Target Structure

```
src/<package>/modules/<module_name>/
tests/modules/<module_name>/
specs/modules/<module_name>/
docs/modules/<module_name>/
examples/modules/<module_name>/
```

## Process Steps

**Phase 1 — Analysis (parallel):** List directories, inventory root
artifacts, audit hidden folders.

**Phase 2 — Directory creation (sequential):**
```bash
mkdir -p src/<pkg>/modules tests/modules specs/modules docs/modules examples/modules
touch specs/modules/.gitkeep docs/modules/.gitkeep examples/modules/.gitkeep
```

**Phase 3 — Module moves (parallel per module):** Always use `git mv`.
```bash
git mv src/<pkg>/<module> src/<pkg>/modules/<module>
git mv tests/<module> tests/modules/<module>
```

**Phase 3.5 — Hidden folder consolidation (parallel per folder):**
See `references/patterns.md` §Hidden Folder Consolidation.

**Phase 4 — Import updates (parallel by file type):**
```bash
find . -name "*.py" -exec sed -i \
  's/from <pkg>\.<mod>/from <pkg>.modules.<mod>/g' {} \;
```

**Phase 5 — Cleanup (parallel):** Remove root artifacts, consolidate
agent dirs, update `.gitignore`.

**Phase 6 — Verification (parallel then sequential):**
```bash
uv run pytest tests/ -v
git log --follow --oneline -- src/<pkg>/modules/<module>/<file>.py
```

## Quick Start

```bash
# Pre-flight
git status && git ls-files --others --exclude-standard | wc -l

# Create module structure
mkdir -p src/<pkg>/modules tests/modules specs/modules docs/modules examples/modules

# Archive completed plan files
git mv specs/modules/<completed-plan>.md specs/archive/

# Verify after cleanup
uv run pytest tests/ -v && git status
```

## Atomic Commit Strategy

| Phase | Commit Message Pattern |
|-------|------------------------|
| 1 | `refactor: Reorganize to module-based 5-layer architecture` |
| 2 | `refactor: Consolidate <folders> into .Codex (N files)` |
| 3 | `chore: Delete legacy config and consolidate scripts` |
| 4 | `docs: Update README structure and skill documentation` |

## Related Skills

- `../context-management/SKILL.md` — Managing context during large refactors
- `coordination/session-start-routine/SKILL.md` — Session initialization

Related Skills

module-lookup

5
from vamseeachanta/workspace-hub

Query the digitalmodel module registry to discover modules by capability, standard, or maturity without reading source code.

wave-based-parallel-plan-execution

5
from vamseeachanta/workspace-hub

Orchestrate phase execution by discovering dependencies, grouping into waves, spawning subagents, and collecting results with optional wave filtering

batch-syntax-fix-with-regex-line-based-fallback

5
from vamseeachanta/workspace-hub

Fix repeated syntax errors across many files using regex, then fall back to line-based parsing when regex fails

interactive-Codex-to-file-based-fallback

5
from vamseeachanta/workspace-hub

Switch from tmux/interactive Codex to file-based Codex -p execution when interactive runs fail with upstream errors or analysis-only stalls, then verify landing from git/GitHub state.

discipline-refactor-verification-checklist

5
from vamseeachanta/workspace-hub

Sub-skill of discipline-refactor: Verification Checklist.

discipline-refactor-target-repository-structure

5
from vamseeachanta/workspace-hub

Sub-skill of discipline-refactor: Target Repository Structure.

discipline-refactor-standard-folders-module-structure

5
from vamseeachanta/workspace-hub

Sub-skill of discipline-refactor: Standard Folders → Module Structure (+1).

discipline-refactor-rollback

5
from vamseeachanta/workspace-hub

Sub-skill of discipline-refactor: Rollback.

discipline-refactor-phase-4-validation

5
from vamseeachanta/workspace-hub

Sub-skill of discipline-refactor: Phase 4: Validation.

discipline-refactor-phase-3-execution

5
from vamseeachanta/workspace-hub

Sub-skill of discipline-refactor: Phase 3: Execution.

discipline-refactor-phase-2-planning

5
from vamseeachanta/workspace-hub

Sub-skill of discipline-refactor: Phase 2: Planning.

discipline-refactor-phase-1-analysis

5
from vamseeachanta/workspace-hub

Sub-skill of discipline-refactor: Phase 1: Analysis.