Paths: File paths (references/, ../ln-*) are relative to this skill directory.
ln-721-frontend-restructure
Type: L3 Worker
Category: 7XX Project Bootstrap
Frontend structure worker with two modes: SCAFFOLD (generate minimal React project from template) or RESTRUCTURE (migrate monolith to component-based architecture).
Mode Selection
| Mode |
When |
Input |
Output |
| SCAFFOLD |
CREATE pipeline — no existing frontend |
Target stack config from ln-720 |
Minimal React + Vite project (~7 files) |
| RESTRUCTURE |
TRANSFORM pipeline — existing frontend found |
Monolithic React source |
Component-based architecture |
Purpose & Scope
| Aspect |
Description |
| Input |
Target stack config (SCAFFOLD) or monolithic React source (RESTRUCTURE) |
| Output |
Minimal project (SCAFFOLD) or component-based architecture (RESTRUCTURE) |
| Framework |
React + 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)
| Phase |
Name |
Actions |
Output |
| S1 |
Generate |
Create minimal React + Vite + TypeScript project files |
~7 starter files |
| S2 |
Verify |
Check file structure, validate configs |
Valid project skeleton |
RESTRUCTURE Mode (TRANSFORM pipeline)
| Phase |
Name |
Actions |
Output |
| 1 |
Analyze |
Scan source, detect component types, measure complexity |
File inventory, complexity metrics |
| 2 |
Plan |
Apply split thresholds, calculate file moves, detect conflicts |
Migration plan |
| 3 |
Execute |
Create folders, extract content, update imports |
Restructured files |
| 4 |
Verify |
Run build, check imports, validate structure |
Build success report |
SCAFFOLD Mode Phases
Phase S1: Generate Starter Files
Create minimal React + Vite + TypeScript project.
| File |
Purpose |
package.json |
Dependencies: react, react-dom, typescript, vite, @vitejs/plugin-react |
vite.config.ts |
Vite config with React plugin, port, proxy settings |
tsconfig.json |
Strict TypeScript config with path aliases |
index.html |
Entry HTML with root div |
src/main.tsx |
React entry point with StrictMode |
src/App.tsx |
Root App component with router placeholder |
src/index.css |
Base styles (reset, variables, layout) |
Phase S2: Verify Scaffold
| Check |
Method |
Expected |
| All files created |
File existence check |
7 files present |
| package.json valid |
JSON parse |
No syntax errors |
| tsconfig.json valid |
JSON parse |
No syntax errors |
| No hardcoded values |
Content scan |
Project name from config, not hardcoded |
RESTRUCTURE Mode Phases
Phase 1: Analyze
Scan current frontend structure and classify components.
| Step |
Action |
Reference |
| 1.1 |
Scan all .tsx and .ts files in source |
— |
| 1.2 |
Measure file complexity (lines, hooks, types) |
transformation_rules.md |
| 1.3 |
Classify components by category |
component_patterns.md |
| 1.4 |
Build import dependency graph |
import_strategy.md |
Output: Component inventory with classifications and metrics.
Phase 2: Plan
Generate migration plan based on analysis.
| Step |
Action |
Reference |
| 2.1 |
Apply split thresholds to identify files to restructure |
transformation_rules.md |
| 2.2 |
Calculate target paths for each file |
react_folder_structure.md |
| 2.3 |
Identify import updates needed |
import_strategy.md |
| 2.4 |
Detect potential conflicts (name collisions, circular deps) |
— |
Output: Migration plan with Before/After mapping.
Phase 3: Execute
Apply transformations in correct order.
| Step |
Action |
Notes |
| 3.1 |
Create directory structure |
All target folders |
| 3.2 |
Extract types to types.ts |
Types have no dependencies |
| 3.3 |
Extract constants to constants.ts |
Constants depend only on types |
| 3.4 |
Extract hooks to hooks.ts |
Hooks depend on types, constants |
| 3.5 |
Extract sub-components |
Components use all above |
| 3.6 |
Create barrel exports (index.ts) |
For clean imports |
| 3.7 |
Update all import paths |
Fix references |
Order is critical: Execute in sequence to avoid broken imports.
Phase 4: Verify
Validate restructured project.
| Check |
Command |
Expected |
| TypeScript compilation |
npx tsc --noEmit |
No errors |
| Build |
npm run build |
Success |
| No orphan files |
Manual check |
Source location empty |
| Imports resolve |
Build success |
No module not found errors |
Transformation Summary
| Transformation |
Before State |
After State |
| Component Split |
Single file >300 lines |
Feature folder with co-located files |
| Type Extraction |
Inline interfaces |
Separate types.ts |
| Constant Extraction |
Inline magic values |
Separate constants.ts |
| Hook Extraction |
Inline useState/useEffect |
Separate hooks.ts or shared hooks |
| UI Component Move |
Scattered in features |
Centralized in components/ui/ |
| Layout Component Move |
Mixed with features |
Centralized 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:
RESTRUCTURE mode:
Risk Mitigation
| Risk |
Detection |
Mitigation |
| Build failure after restructure |
npm run build fails |
Rollback: restore from source, investigate specific error |
| Missing imports |
Module not found errors |
Scan all imports before/after, update missed paths |
| Circular dependencies |
Build warning or runtime error |
Analyze dependency graph, break cycles by extracting shared code |
| Lost functionality |
Tests fail or UI broken |
Run existing tests before/after transformation |
| Name collisions |
Duplicate export names |
Rename with feature prefix before moving |
Reference Files
| File |
Purpose |
references/transformation_rules.md |
Split thresholds, extraction rules, transformation order |
references/component_patterns.md |
Component classification by category |
references/import_strategy.md |
Import update rules, path aliases, barrel exports |
references/react_folder_structure.md |
Target directory structure template |
Version: 3.0.0
Last Updated: 2026-02-07
1---2name: ln-721-frontend-restructure-43description: Scaffolds new React projects or restructures monoliths to component-based architecture. Use when setting up frontend structure.4license: MIT5---67> **Paths:** File paths (`references/`, `../ln-*`) are relative to this skill directory.89# ln-721-frontend-restructure1011**Type:** L3 Worker12**Category:** 7XX Project Bootstrap1314Frontend structure worker with two modes: SCAFFOLD (generate minimal React project from template) or RESTRUCTURE (migrate monolith to component-based architecture).1516---1718## Mode Selection1920| Mode | When | Input | Output |21|------|------|-------|--------|22| **SCAFFOLD** | CREATE pipeline — no existing frontend | Target stack config from ln-720 | Minimal React + Vite project (~7 files) |23| **RESTRUCTURE** | TRANSFORM pipeline — existing frontend found | Monolithic React source | Component-based architecture |2425---2627## Purpose & Scope2829| Aspect | Description |30|--------|-------------|31| **Input** | Target stack config (SCAFFOLD) or monolithic React source (RESTRUCTURE) |32| **Output** | Minimal project (SCAFFOLD) or component-based architecture (RESTRUCTURE) |33| **Framework** | React + TypeScript + Vite |3435**Scope boundaries:**36- SCAFFOLD: generates minimal starter files, no business logic37- RESTRUCTURE: restructures existing code, does not add new functionality38- Works with React + TypeScript projects39- Applies transformation rules from reference files4041---4243## Workflow4445### SCAFFOLD Mode (CREATE pipeline)4647| Phase | Name | Actions | Output |48|-------|------|---------|--------|49| S1 | Generate | Create minimal React + Vite + TypeScript project files | ~7 starter files |50| S2 | Verify | Check file structure, validate configs | Valid project skeleton |5152### RESTRUCTURE Mode (TRANSFORM pipeline)5354| Phase | Name | Actions | Output |55|-------|------|---------|--------|56| 1 | Analyze | Scan source, detect component types, measure complexity | File inventory, complexity metrics |57| 2 | Plan | Apply split thresholds, calculate file moves, detect conflicts | Migration plan |58| 3 | Execute | Create folders, extract content, update imports | Restructured files |59| 4 | Verify | Run build, check imports, validate structure | Build success report |6061---6263## SCAFFOLD Mode Phases6465### Phase S1: Generate Starter Files6667Create minimal React + Vite + TypeScript project.6869| File | Purpose |70|------|---------|71| `package.json` | Dependencies: react, react-dom, typescript, vite, @vitejs/plugin-react |72| `vite.config.ts` | Vite config with React plugin, port, proxy settings |73| `tsconfig.json` | Strict TypeScript config with path aliases |74| `index.html` | Entry HTML with root div |75| `src/main.tsx` | React entry point with StrictMode |76| `src/App.tsx` | Root App component with router placeholder |77| `src/index.css` | Base styles (reset, variables, layout) |7879### Phase S2: Verify Scaffold8081| Check | Method | Expected |82|-------|--------|----------|83| All files created | File existence check | 7 files present |84| package.json valid | JSON parse | No syntax errors |85| tsconfig.json valid | JSON parse | No syntax errors |86| No hardcoded values | Content scan | Project name from config, not hardcoded |8788---8990## RESTRUCTURE Mode Phases9192### Phase 1: Analyze9394Scan current frontend structure and classify components.9596| Step | Action | Reference |97|------|--------|-----------|98| 1.1 | Scan all `.tsx` and `.ts` files in source | — |99| 1.2 | Measure file complexity (lines, hooks, types) | `transformation_rules.md` |100| 1.3 | Classify components by category | `component_patterns.md` |101| 1.4 | Build import dependency graph | `import_strategy.md` |102103**Output:** Component inventory with classifications and metrics.104105---106107### Phase 2: Plan108109Generate migration plan based on analysis.110111| Step | Action | Reference |112|------|--------|-----------|113| 2.1 | Apply split thresholds to identify files to restructure | `transformation_rules.md` |114| 2.2 | Calculate target paths for each file | `react_folder_structure.md` |115| 2.3 | Identify import updates needed | `import_strategy.md` |116| 2.4 | Detect potential conflicts (name collisions, circular deps) | — |117118**Output:** Migration plan with Before/After mapping.119120---121122### Phase 3: Execute123124Apply transformations in correct order.125126| Step | Action | Notes |127|------|--------|-------|128| 3.1 | Create directory structure | All target folders |129| 3.2 | Extract types to `types.ts` | Types have no dependencies |130| 3.3 | Extract constants to `constants.ts` | Constants depend only on types |131| 3.4 | Extract hooks to `hooks.ts` | Hooks depend on types, constants |132| 3.5 | Extract sub-components | Components use all above |133| 3.6 | Create barrel exports (`index.ts`) | For clean imports |134| 3.7 | Update all import paths | Fix references |135136**Order is critical:** Execute in sequence to avoid broken imports.137138---139140### Phase 4: Verify141142Validate restructured project.143144| Check | Command | Expected |145|-------|---------|----------|146| TypeScript compilation | `npx tsc --noEmit` | No errors |147| Build | `npm run build` | Success |148| No orphan files | Manual check | Source location empty |149| Imports resolve | Build success | No module not found errors |150151---152153## Transformation Summary154155| Transformation | Before State | After State |156|----------------|--------------|-------------|157| Component Split | Single file >300 lines | Feature folder with co-located files |158| Type Extraction | Inline interfaces | Separate `types.ts` |159| Constant Extraction | Inline magic values | Separate `constants.ts` |160| Hook Extraction | Inline useState/useEffect | Separate `hooks.ts` or shared hooks |161| UI Component Move | Scattered in features | Centralized in `components/ui/` |162| Layout Component Move | Mixed with features | Centralized in `components/layout/` |163164---165166## Critical Rules167168- **Mode Awareness:** SCAFFOLD creates from template; RESTRUCTURE transforms existing — never mix169- **Single Responsibility:** Handle only frontend structure, no backend changes170- **Idempotent:** Can re-run without duplicate files or corruption171- **Build Verification:** Must verify build passes after changes (RESTRUCTURE: `npm run build`)172- **Preserve Functionality:** No behavioral changes, only structural (RESTRUCTURE mode)173- **Backup Strategy:** Do not delete source files until verification passes (RESTRUCTURE mode)174- **Import Consistency:** Use path aliases for shared, relative for co-located175176---177178## Definition of Done179180**SCAFFOLD mode:**181- [ ] All 7 starter files generated182- [ ] package.json and tsconfig.json valid183- [ ] No hardcoded project names (uses config values)184185**RESTRUCTURE mode:**186- [ ] All source files analyzed and classified187- [ ] Migration plan generated with Before/After mapping188- [ ] Directory structure created per template189- [ ] All extractions completed (types, constants, hooks, components)190- [ ] Import paths updated throughout project191- [ ] `npm run build` passes successfully192- [ ] No orphan imports or missing files193- [ ] Barrel exports created for shared folders194195---196197## Risk Mitigation198199| Risk | Detection | Mitigation |200|------|-----------|------------|201| Build failure after restructure | `npm run build` fails | Rollback: restore from source, investigate specific error |202| Missing imports | Module not found errors | Scan all imports before/after, update missed paths |203| Circular dependencies | Build warning or runtime error | Analyze dependency graph, break cycles by extracting shared code |204| Lost functionality | Tests fail or UI broken | Run existing tests before/after transformation |205| Name collisions | Duplicate export names | Rename with feature prefix before moving |206207---208209## Reference Files210211| File | Purpose |212|------|---------|213| `references/transformation_rules.md` | Split thresholds, extraction rules, transformation order |214| `references/component_patterns.md` | Component classification by category |215| `references/import_strategy.md` | Import update rules, path aliases, barrel exports |216| `references/react_folder_structure.md` | Target directory structure template |217218---219220**Version:** 3.0.0221**Last Updated:** 2026-02-07