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
| 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-33description: Frontend structure worker: SCAFFOLD new React project or RESTRUCTURE existing monolith to component-based architecture4---56# ln-721-frontend-restructure78**Type:** L3 Worker9**Category:** 7XX Project Bootstrap10**Parent:** ln-720-structure-migrator1112Frontend structure worker with two modes: SCAFFOLD (generate minimal React project from template) or RESTRUCTURE (migrate monolith to component-based architecture).1314---1516## Mode Selection1718| Mode | When | Input | Output |19|------|------|-------|--------|20| **SCAFFOLD** | CREATE pipeline — no existing frontend | Target stack config from ln-720 | Minimal React + Vite project (~7 files) |21| **RESTRUCTURE** | TRANSFORM pipeline — existing frontend found | Monolithic React source | Component-based architecture |2223---2425## Purpose & Scope2627| Aspect | Description |28|--------|-------------|29| **Input** | Target stack config (SCAFFOLD) or monolithic React source (RESTRUCTURE) |30| **Output** | Minimal project (SCAFFOLD) or component-based architecture (RESTRUCTURE) |31| **Framework** | React + TypeScript + Vite |3233**Scope boundaries:**34- SCAFFOLD: generates minimal starter files, no business logic35- RESTRUCTURE: restructures existing code, does not add new functionality36- Works with React + TypeScript projects37- Applies transformation rules from reference files3839---4041## Workflow4243### SCAFFOLD Mode (CREATE pipeline)4445| Phase | Name | Actions | Output |46|-------|------|---------|--------|47| S1 | Generate | Create minimal React + Vite + TypeScript project files | ~7 starter files |48| S2 | Verify | Check file structure, validate configs | Valid project skeleton |4950### RESTRUCTURE Mode (TRANSFORM pipeline)5152| Phase | Name | Actions | Output |53|-------|------|---------|--------|54| 1 | Analyze | Scan source, detect component types, measure complexity | File inventory, complexity metrics |55| 2 | Plan | Apply split thresholds, calculate file moves, detect conflicts | Migration plan |56| 3 | Execute | Create folders, extract content, update imports | Restructured files |57| 4 | Verify | Run build, check imports, validate structure | Build success report |5859---6061## SCAFFOLD Mode Phases6263### Phase S1: Generate Starter Files6465Create minimal React + Vite + TypeScript project.6667| File | Purpose |68|------|---------|69| `package.json` | Dependencies: react, react-dom, typescript, vite, @vitejs/plugin-react |70| `vite.config.ts` | Vite config with React plugin, port, proxy settings |71| `tsconfig.json` | Strict TypeScript config with path aliases |72| `index.html` | Entry HTML with root div |73| `src/main.tsx` | React entry point with StrictMode |74| `src/App.tsx` | Root App component with router placeholder |75| `src/index.css` | Base styles (reset, variables, layout) |7677### Phase S2: Verify Scaffold7879| Check | Method | Expected |80|-------|--------|----------|81| All files created | File existence check | 7 files present |82| package.json valid | JSON parse | No syntax errors |83| tsconfig.json valid | JSON parse | No syntax errors |84| No hardcoded values | Content scan | Project name from config, not hardcoded |8586---8788## RESTRUCTURE Mode Phases8990### Phase 1: Analyze9192Scan current frontend structure and classify components.9394| Step | Action | Reference |95|------|--------|-----------|96| 1.1 | Scan all `.tsx` and `.ts` files in source | — |97| 1.2 | Measure file complexity (lines, hooks, types) | `transformation_rules.md` |98| 1.3 | Classify components by category | `component_patterns.md` |99| 1.4 | Build import dependency graph | `import_strategy.md` |100101**Output:** Component inventory with classifications and metrics.102103---104105### Phase 2: Plan106107Generate migration plan based on analysis.108109| Step | Action | Reference |110|------|--------|-----------|111| 2.1 | Apply split thresholds to identify files to restructure | `transformation_rules.md` |112| 2.2 | Calculate target paths for each file | `react_folder_structure.md` |113| 2.3 | Identify import updates needed | `import_strategy.md` |114| 2.4 | Detect potential conflicts (name collisions, circular deps) | — |115116**Output:** Migration plan with Before/After mapping.117118---119120### Phase 3: Execute121122Apply transformations in correct order.123124| Step | Action | Notes |125|------|--------|-------|126| 3.1 | Create directory structure | All target folders |127| 3.2 | Extract types to `types.ts` | Types have no dependencies |128| 3.3 | Extract constants to `constants.ts` | Constants depend only on types |129| 3.4 | Extract hooks to `hooks.ts` | Hooks depend on types, constants |130| 3.5 | Extract sub-components | Components use all above |131| 3.6 | Create barrel exports (`index.ts`) | For clean imports |132| 3.7 | Update all import paths | Fix references |133134**Order is critical:** Execute in sequence to avoid broken imports.135136---137138### Phase 4: Verify139140Validate restructured project.141142| Check | Command | Expected |143|-------|---------|----------|144| TypeScript compilation | `npx tsc --noEmit` | No errors |145| Build | `npm run build` | Success |146| No orphan files | Manual check | Source location empty |147| Imports resolve | Build success | No module not found errors |148149---150151## Transformation Summary152153| Transformation | Before State | After State |154|----------------|--------------|-------------|155| Component Split | Single file >300 lines | Feature folder with co-located files |156| Type Extraction | Inline interfaces | Separate `types.ts` |157| Constant Extraction | Inline magic values | Separate `constants.ts` |158| Hook Extraction | Inline useState/useEffect | Separate `hooks.ts` or shared hooks |159| UI Component Move | Scattered in features | Centralized in `components/ui/` |160| Layout Component Move | Mixed with features | Centralized in `components/layout/` |161162---163164## Critical Rules165166- **Mode Awareness:** SCAFFOLD creates from template; RESTRUCTURE transforms existing — never mix167- **Single Responsibility:** Handle only frontend structure, no backend changes168- **Idempotent:** Can re-run without duplicate files or corruption169- **Build Verification:** Must verify build passes after changes (RESTRUCTURE: `npm run build`)170- **Preserve Functionality:** No behavioral changes, only structural (RESTRUCTURE mode)171- **Backup Strategy:** Do not delete source files until verification passes (RESTRUCTURE mode)172- **Import Consistency:** Use path aliases for shared, relative for co-located173174---175176## Definition of Done177178**SCAFFOLD mode:**179- [ ] All 7 starter files generated180- [ ] package.json and tsconfig.json valid181- [ ] No hardcoded project names (uses config values)182183**RESTRUCTURE mode:**184- [ ] All source files analyzed and classified185- [ ] Migration plan generated with Before/After mapping186- [ ] Directory structure created per template187- [ ] All extractions completed (types, constants, hooks, components)188- [ ] Import paths updated throughout project189- [ ] `npm run build` passes successfully190- [ ] No orphan imports or missing files191- [ ] Barrel exports created for shared folders192193---194195## Risk Mitigation196197| Risk | Detection | Mitigation |198|------|-----------|------------|199| Build failure after restructure | `npm run build` fails | Rollback: restore from source, investigate specific error |200| Missing imports | Module not found errors | Scan all imports before/after, update missed paths |201| Circular dependencies | Build warning or runtime error | Analyze dependency graph, break cycles by extracting shared code |202| Lost functionality | Tests fail or UI broken | Run existing tests before/after transformation |203| Name collisions | Duplicate export names | Rename with feature prefix before moving |204205---206207## Reference Files208209| File | Purpose |210|------|---------|211| `references/transformation_rules.md` | Split thresholds, extraction rules, transformation order |212| `references/component_patterns.md` | Component classification by category |213| `references/import_strategy.md` | Import update rules, path aliases, barrel exports |214| `references/react_folder_structure.md` | Target directory structure template |215216---217218**Version:** 3.0.0219**Last Updated:** 2026-02-07