How netease/tango works
Project Type and Purpose
• Tango is a monorepo (Lerna + Yarn) that delivers a front‑end low‑code builder.
• It provides core AST‑based code generation libraries, a React “designer” UI, helper utilities, code sandbox runtime, setting‐form DSL components, and UI primitives.
• Two consumer apps live alongside: a Playground demo app and a Storybook showcase.
Main Components
A. Monorepo Root & Tooling
• Lerna (package management)
• Yarn workspaces
• CI/CD (GitHub workflows: ci.yml, deploy.yml)
• Build configs (babel.config.js, jest.config.js, tsconfig.json files)
B. Package Layer (each published to NPM)
1) @music163/tango-core
– AST parser/traverser/generator, Code workspace models, engine, history.
2) @music163/tango-context
– React Context providers for workspace, selection, drag‑drop.
3) @music163/tango-designer
– Designer Panel, Simulator, Sidebar, Toolbar, DnD, variable trees, context menus, setters.
4) @music163/tango-ui
5) @music163/tango-setting-form
– Form model, UI for property panels, built-in setters (bool, code, text, etc.).
6) @music163/tango-sandbox
– CodeSandbox integration, iframe protocol, live preview manager.
7) @music163/tango-helpers
– Generic JS/React utilities, hooks, stores, HOCs.
8) @music163/tango-spec
– Configuration schema for AST rules (tango-config).
C. Consumer Applications
1) Playground (apps/playground)
– Demo / local development environment, imports all packages, serves over Umi.
2) Storybook (apps/storybook)
– Isolated component catalog for designer, ui, setting‑form, sandbox artifacts.
Relationships & Interactions
• Playground & Storybook → import all packages via workspace links.
• Designer components (tango-designer) → use core for AST-based code logic, context for state propagation, ui and setting-form for rendering property editors.
• Sandbox provides runtime embedding for live‑editing previews and code execution.
• Helpers are consumed pervasively by all other packages.
• Spec feeds AST transforms and code schema validations into core and designer.
Architectural Patterns & Principles
• Modular Monorepo: clear separation of concerns by package; Lerna for versioning/publishing.
• Component‑Based UI: React components grouped by domain (designer UI, setting form, sandbox).
• AST‑Driven Code Gen: core library uses visitor pattern to parse, traverse, generate code.
• Context‑based State: React Context to share editor/workspace state.
• Pluggable Extensions: setting‑form setters, ui primitives, spec config make the system extensible.