前端架构改造

Universal

ln-721-frontend-restructure

by levnikolaevich

面向React+TypeScript+Vite前端,既能快速生成精简项目骨架,也能把臃肿单体代码重构为组件化结构,并验证构建和导入是否正常。

帮你快速搭起 React 新项目骨架,更难得的是能把臃肿单体前端重构成组件化架构,特别适合架构升级。

405编码与调试未扫描2026年3月5日

安装

claude skill add --url github.com/levnikolaevich/claude-code-skills/tree/master/ln-721-frontend-restructure

文档

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

相关 Skills

网页构建器

by anthropics

Universal
热门

面向复杂 claude.ai HTML artifact 开发,快速初始化 React + Tailwind CSS + shadcn/ui 项目并打包为单文件 HTML,适合需要状态管理、路由或多组件交互的页面。

在 claude.ai 里做复杂网页 Artifact 很省心,多组件、状态和路由都能顺手搭起来,React、Tailwind 与 shadcn/ui 组合效率高、成品也更精致。

编码与调试
未扫描119.1k

前端设计

by anthropics

Universal
热门

面向组件、页面、海报和 Web 应用开发,按鲜明视觉方向生成可直接落地的前端代码与高质感 UI,适合做 landing page、Dashboard 或美化现有界面,避开千篇一律的 AI 审美。

想把页面做得既能上线又有设计感,就用前端设计:组件到整站都能产出,难得的是能避开千篇一律的 AI 味。

编码与调试
未扫描119.1k

网页应用测试

by anthropics

Universal
热门

用 Playwright 为本地 Web 应用编写自动化测试,支持启动开发服务器、校验前端交互、排查 UI 异常、抓取截图与浏览器日志,适合调试动态页面和回归验证。

借助 Playwright 一站式验证本地 Web 应用前端功能,调 UI 时还能同步查看日志和截图,定位问题更快。

编码与调试
未扫描119.1k

相关 MCP 服务

GitHub

编辑精选

by GitHub

热门

GitHub 是 MCP 官方参考服务器,让 Claude 直接读写你的代码仓库和 Issues。

这个参考服务器解决了开发者想让 AI 安全访问 GitHub 数据的问题,适合需要自动化代码审查或 Issue 管理的团队。但注意它只是参考实现,生产环境得自己加固安全。

编码与调试
83.9k

by Context7

热门

Context7 是实时拉取最新文档和代码示例的智能助手,让你告别过时资料。

它能解决开发者查找文档时信息滞后的问题,特别适合快速上手新库或跟进更新。不过,依赖外部源可能导致偶尔的数据延迟,建议结合官方文档使用。

编码与调试
52.9k

by tldraw

热门

tldraw 是让 AI 助手直接在无限画布上绘图和协作的 MCP 服务器。

这解决了 AI 只能输出文本、无法视觉化协作的痛点——想象让 Claude 帮你画流程图或白板讨论。最适合需要快速原型设计或头脑风暴的开发者。不过,目前它只是个基础连接器,你得自己搭建画布应用才能发挥全部潜力。

编码与调试
46.4k

评论