Get the FREE Ultimate OpenClaw Setup Guide →

ln-721-frontend-restructure

npx machina-cli add skill levnikolaevich/claude-code-skills/ln-721-frontend-restructure --openclaw
Files (1)
SKILL.md
8.0 KB

Paths: File paths (shared/, references/, ../ln-*) are relative to skills repo root. If not found at CWD, locate this SKILL.md directory and go up one level for repo root.

ln-721-frontend-restructure

Type: L3 Worker Category: 7XX Project Bootstrap Parent: ln-720-structure-migrator

Frontend structure worker with two modes: SCAFFOLD (generate minimal React project from template) or RESTRUCTURE (migrate monolith to component-based architecture).


Mode Selection

ModeWhenInputOutput
SCAFFOLDCREATE pipeline — no existing frontendTarget stack config from ln-720Minimal React + Vite project (~7 files)
RESTRUCTURETRANSFORM pipeline — existing frontend foundMonolithic React sourceComponent-based architecture

Purpose & Scope

AspectDescription
InputTarget stack config (SCAFFOLD) or monolithic React source (RESTRUCTURE)
OutputMinimal project (SCAFFOLD) or component-based architecture (RESTRUCTURE)
FrameworkReact + TypeScript + Vite

Scope boundaries:

  • SCAFFOLD: generates minimal starter files, no business logic
  • RESTRUCTURE: restructures existing code, does not add new functionality
  • Works with React + TypeScript projects
  • Applies transformation rules from reference files

Workflow

SCAFFOLD Mode (CREATE pipeline)

PhaseNameActionsOutput
S1GenerateCreate minimal React + Vite + TypeScript project files~7 starter files
S2VerifyCheck file structure, validate configsValid project skeleton

RESTRUCTURE Mode (TRANSFORM pipeline)

PhaseNameActionsOutput
1AnalyzeScan source, detect component types, measure complexityFile inventory, complexity metrics
2PlanApply split thresholds, calculate file moves, detect conflictsMigration plan
3ExecuteCreate folders, extract content, update importsRestructured files
4VerifyRun build, check imports, validate structureBuild success report

SCAFFOLD Mode Phases

Phase S1: Generate Starter Files

Create minimal React + Vite + TypeScript project.

FilePurpose
package.jsonDependencies: react, react-dom, typescript, vite, @vitejs/plugin-react
vite.config.tsVite config with React plugin, port, proxy settings
tsconfig.jsonStrict TypeScript config with path aliases
index.htmlEntry HTML with root div
src/main.tsxReact entry point with StrictMode
src/App.tsxRoot App component with router placeholder
src/index.cssBase styles (reset, variables, layout)

Phase S2: Verify Scaffold

CheckMethodExpected
All files createdFile existence check7 files present
package.json validJSON parseNo syntax errors
tsconfig.json validJSON parseNo syntax errors
No hardcoded valuesContent scanProject name from config, not hardcoded

RESTRUCTURE Mode Phases

Phase 1: Analyze

Scan current frontend structure and classify components.

StepActionReference
1.1Scan all .tsx and .ts files in source
1.2Measure file complexity (lines, hooks, types)transformation_rules.md
1.3Classify components by categorycomponent_patterns.md
1.4Build import dependency graphimport_strategy.md

Output: Component inventory with classifications and metrics.


Phase 2: Plan

Generate migration plan based on analysis.

StepActionReference
2.1Apply split thresholds to identify files to restructuretransformation_rules.md
2.2Calculate target paths for each filereact_folder_structure.md
2.3Identify import updates neededimport_strategy.md
2.4Detect potential conflicts (name collisions, circular deps)

Output: Migration plan with Before/After mapping.


Phase 3: Execute

Apply transformations in correct order.

StepActionNotes
3.1Create directory structureAll target folders
3.2Extract types to types.tsTypes have no dependencies
3.3Extract constants to constants.tsConstants depend only on types
3.4Extract hooks to hooks.tsHooks depend on types, constants
3.5Extract sub-componentsComponents use all above
3.6Create barrel exports (index.ts)For clean imports
3.7Update all import pathsFix references

Order is critical: Execute in sequence to avoid broken imports.


Phase 4: Verify

Validate restructured project.

CheckCommandExpected
TypeScript compilationnpx tsc --noEmitNo errors
Buildnpm run buildSuccess
No orphan filesManual checkSource location empty
Imports resolveBuild successNo module not found errors

Transformation Summary

TransformationBefore StateAfter State
Component SplitSingle file >300 linesFeature folder with co-located files
Type ExtractionInline interfacesSeparate types.ts
Constant ExtractionInline magic valuesSeparate constants.ts
Hook ExtractionInline useState/useEffectSeparate hooks.ts or shared hooks
UI Component MoveScattered in featuresCentralized in components/ui/
Layout Component MoveMixed with featuresCentralized in components/layout/

Critical Rules

  • Mode Awareness: SCAFFOLD creates from template; RESTRUCTURE transforms existing — never mix
  • Single Responsibility: Handle only frontend structure, no backend changes
  • Idempotent: Can re-run without duplicate files or corruption
  • Build Verification: Must verify build passes after changes (RESTRUCTURE: npm run build)
  • Preserve Functionality: No behavioral changes, only structural (RESTRUCTURE mode)
  • Backup Strategy: Do not delete source files until verification passes (RESTRUCTURE mode)
  • Import Consistency: Use path aliases for shared, relative for co-located

Definition of Done

SCAFFOLD mode:

  • All 7 starter files generated
  • package.json and tsconfig.json valid
  • No hardcoded project names (uses config values)

RESTRUCTURE mode:

  • All source files analyzed and classified
  • Migration plan generated with Before/After mapping
  • Directory structure created per template
  • All extractions completed (types, constants, hooks, components)
  • Import paths updated throughout project
  • npm run build passes successfully
  • No orphan imports or missing files
  • Barrel exports created for shared folders

Risk Mitigation

RiskDetectionMitigation
Build failure after restructurenpm run build failsRollback: restore from source, investigate specific error
Missing importsModule not found errorsScan all imports before/after, update missed paths
Circular dependenciesBuild warning or runtime errorAnalyze dependency graph, break cycles by extracting shared code
Lost functionalityTests fail or UI brokenRun existing tests before/after transformation
Name collisionsDuplicate export namesRename with feature prefix before moving

Reference Files

FilePurpose
references/transformation_rules.mdSplit thresholds, extraction rules, transformation order
references/component_patterns.mdComponent classification by category
references/import_strategy.mdImport update rules, path aliases, barrel exports
references/react_folder_structure.mdTarget directory structure template

Version: 3.0.0 Last Updated: 2026-02-07

Source

git clone https://github.com/levnikolaevich/claude-code-skills/blob/master/ln-721-frontend-restructure/SKILL.mdView on GitHub

Overview

Ln-721 is a frontend structure worker with two modes: SCAFFOLD to bootstrap a minimal React + Vite + TypeScript project, and RESTRUCTURE to convert an existing monolith into a component-based architecture. It relies on inputs from ln-720-structure-migrator and applies reference rules to reorganize code without adding new functionality.

How This Skill Works

In SCAFFOLD mode, it generates starter project files (package.json, vite.config.ts, tsconfig.json, index.html, src/main.tsx, src/App.tsx, src/index.css). In RESTRUCTURE mode, it analyzes TS/TSX sources to inventory components, measures complexity, plans file moves against split thresholds, executes folder restructuring and import updates, and then runs a build to verify the result.

When to Use It

  • Bootstrapping a brand-new React + TypeScript + Vite project from a target stack config (SCAFFOLD).
  • Transforming an existing monolithic React frontend into a component-based architecture (RESTRUCTURE).
  • Validating scaffold readiness by checking file structure and config validity against the target stack.
  • Applying transformation rules and generating a migration plan from detailed analysis.
  • Verifying the final build and import integrity after restructuring.

Quick Start

  1. Step 1: Choose mode (SCAFFOLD or RESTRUCTURE) and provide inputs (target stack config from ln-720 or monolithic React source).
  2. Step 2: If SCAFFOLD, generate starter files for a minimal React + Vite + TypeScript project (package.json, vite.config.ts, tsconfig.json, index.html, src/*).
  3. Step 3: If RESTRUCTURE, run Analyze, Plan, Execute, and Verify phases to restructure and validate.

Best Practices

  • Use SCAFFOLD only for projects with no business logic yet; it creates a minimal starter skeleton.
  • Keep tsconfig.json strict and align path aliases with the project root to avoid import issues.
  • In RESTRUCTURE, start with an inventory and complexity metrics before planning moves.
  • Do not introduce new functionality during RESTRUCTURE; focus on restructuring and refactoring only.
  • After changes, run a build and import checks to confirm the project skeleton remains valid.

Example Use Cases

  • Bootstrap a minimal React + Vite + TypeScript starter for a new frontend project using a target stack config.
  • Migrate a large monolithic React app into a component-based structure without altering behavior.
  • Validate a scaffold against the ln-720 target stack configuration before shipping.
  • Generate a component inventory and complexity metrics for a mid-size React codebase.
  • Apply transformation rules from reference files to reorganize an existing React + TS project.

Frequently Asked Questions

Add this skill to your agents
Sponsor this space

Reach thousands of developers