Monorepo Migration: Modular Architecture for Enhanced Development and Publishing
维护者通常 1 天内回复
还没有人认领这个 Issue。
评估
- 难度
- 5/5
- 预计耗时
- 一周以上
- 新手友好度
- 20/100
- Issue 类型
- 重构
- 描述清晰度
- 基本清楚
- 活跃度
- 停滞
- 技术栈
- rollup, typescript
调研方向
Start by reviewing the current package structure and build configuration, then compare them with the proposed six-package layout and TypeScript composite project setup. The issue is an architectural RFC with no files or tests identified; completion would require a migration plan and a proof of concept that supports the proposed package exports and backward compatibility.
由索引模型根据 Issue 内容生成。
描述
Motivation
As @gravity-ui/graph continues to evolve, we need a more flexible architecture that enables:
- Independent Plugin Development: New layers and features can be developed and published without requiring a full library release
- Selective Consumption: Users can import only the parts they need, reducing bundle size
- Enhanced Tooling: Separate packages for development tools (devtools, minimap) that don't bloat the core library
- Better Maintenance: Clear separation of concerns makes the codebase easier to maintain and contribute to
- Ecosystem Growth: Third-party developers can more easily extend the library with custom layers and plugins
The current monolithic structure limits our ability to iterate quickly on supplementary features while maintaining stability in the core library.
Proposed Solution
Transform @gravity-ui/graph into a monorepo with 6 focused packages:
Package Architecture
graph LR
subgraph "Main Package with Routing"
MAIN["@gravity-ui/graph<br/>package.json with exports routing"]
end
subgraph "Internal Packages"
PRIM["@gravity-ui/graph-primitives<br/>• shapes: curvePolyline, triangle, polyline<br/>• renderers: text, svg, render<br/>• basic types: TPoint, TRect, IPoint, IRect<br/>• simple utils: clamp"]
CORE["@gravity-ui/graph-core<br/>• lib/: CoreComponent, Component, Scheduler<br/>• store/: RootStore, blocks, connections<br/>• services/: Layer, Camera, HitTest<br/>• components/canvas/<br/>• api/: PublicGraphApi<br/>• graph.ts: main class<br/>• utils/functions, utils/types"]
REACT["@gravity-ui/graph-react<br/>• GraphCanvas<br/>• hooks: useGraph, useLayer<br/>• React components"]
DEVTOOLS["@gravity-ui/graph-devtools<br/>• DevToolsLayer<br/>• ruler and crosshairs"]
MINIMAP["@gravity-ui/graph-minimap<br/>• MiniMapLayer<br/>• navigation minimap"]
end
PRIM --> CORE
PRIM --> REACT
CORE --> REACT
CORE --> DEVTOOLS
CORE --> MINIMAP
CORE --> MAIN
REACT --> MAIN
DEVTOOLS --> MAIN
MINIMAP --> MAIN
Package Details
1. @gravity-ui/graph-primitives
Foundation package with basic building blocks
- Geometric shapes (
curvePolyline,triangle,polyline) - Rendering utilities (
text,svg,render) - Core types (
TPoint,TRect,IPoint,IRect) - Simple utilities (
clamp, basic math functions)
2. @gravity-ui/graph-core
Consolidated core functionality
- Component system (
lib/) - State management (
store/) - Core services (
services/) - Canvas components (
components/canvas/) - Public API (
api/,graph.ts) - Remaining utilities
Rationale: These modules are tightly coupled and only valuable together
3. @gravity-ui/graph-react
React integration layer
GraphCanvascomponent- React hooks (
useGraph,useLayer, etc.) - React-specific components and utilities
4. @gravity-ui/graph-devtools
Development tools plugin
- DevTools layer with rulers and crosshairs
- Independent package for development-time features
- Peer dependency on
@gravity-ui/graph-core
5. @gravity-ui/graph-minimap
Navigation minimap plugin
- Minimap layer for graph navigation
- Independent package for optional UI enhancement
- Peer dependency on
@gravity-ui/graph-core
6. @gravity-ui/graph
Main package with routing
- Consolidates all packages with proper exports
- Maintains backward compatibility
- Provides clean API surface
Implementation Plan
Phase 1: Monorepo Setup
packages/
├── primitives/ # @gravity-ui/graph-primitives
├── core/ # @gravity-ui/graph-core
├── react/ # @gravity-ui/graph-react
├── devtools/ # @gravity-ui/graph-devtools
├── minimap/ # @gravity-ui/graph-minimap
└── graph/ # @gravity-ui/graph (main with routing)
Phase 2: Package Configuration
Main package package.json with exports routing:
{
"name": "@gravity-ui/graph",
"exports": {
".": {
"types": "./dist/core/index.d.ts",
"default": "./dist/core/index.js"
},
"./react": {
"types": "./dist/react/index.d.ts",
"default": "./dist/react/index.js"
},
"./primitives": {
"types": "./dist/primitives/index.d.ts",
"default": "./dist/primitives/index.js"
},
"./devtools": {
"types": "./dist/devtools/index.d.ts",
"default": "./dist/devtools/index.js"
},
"./minimap": {
"types": "./dist/minimap/index.d.ts",
"default": "./dist/minimap/index.js"
}
}
}
Phase 3: Migration Strategy
- Create packages structure while maintaining single build output
- Update internal dependencies and imports
- Configure build system and publishing workflow
- Update documentation and examples
Tools and Technologies
Build System
- TypeScript Composite Projects: Use TypeScript's composite option for incremental builds and project references
- Rollup: For optimized bundling and tree-shaking support
- Shared build configuration: Consistent build setup across all packages
Publishing and Versioning
- Changesets: Industry-standard tool for managing versions and changelogs in monorepos
- Independent versioning: Each package can evolve at its own pace
- Coordinated releases: Core updates can trigger dependent package updates
Development Workflow
- Workspaces: npm/yarn workspaces for dependency management
- Shared tooling: ESLint, Prettier, TypeScript configs
- Cross-package development: Easy local development with package linking
Benefits
For Users
- Smaller bundles: Import only needed functionality
- Faster adoption: Try specific features without full library commitment
- Clear upgrade paths: Update individual packages as needed
For Maintainers
- Independent releases: Ship devtools improvements without core library changes
- Clear boundaries: Easier to reason about code organization
- Better testing: Isolated testing per package
- Community contributions: Easier for contributors to focus on specific areas
For Ecosystem
- Plugin development: Clear pattern for extending with custom layers
- Third-party tools: Better foundation for community-built extensions
- Framework integration: Other frameworks can consume core without React dependencies
Backward Compatibility
The main @gravity-ui/graph package will maintain 100% backward compatibility through proper exports routing. Existing users won't need to change any import statements.
Next Steps
- Community feedback on this RFC
- Proof of concept with TypeScript composite setup
- Migration timeline planning
- Documentation updates for new architecture
This migration represents a significant step toward a more modular, maintainable, and extensible @gravity-ui/graph ecosystem while preserving the seamless developer experience users expect.
- 主要语言
- TypeScript
- 星标
- 145
- 派生
- 12
- 平均合并
- 1 天 14 小时
- 30 天内合并 PR
- 43
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
gravity-ui/graph 的其他 Issue
-
难度 2/5 1-3 小时 新手友好度 82/100
gravity-ui/graph#457 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 77/100
gravity-ui/graph#455 ·
维护者通常 1 天内回复
-
难度 4/5 3-5 天 新手友好度 55/100
gravity-ui/graph#456 ·
维护者通常 1 天内回复
-
难度 4/5 3-5 天 新手友好度 48/100
gravity-ui/graph#431 ·
维护者通常 1 天内回复
-
proposal
难度 5/5 一周以上 新手友好度 25/100
gravity-ui/graph#416 ·
维护者通常 1 天内回复
相似的 Issue
-
area:cli area:security bug priority:medium
难度 2/5 1-3 小时 新手友好度 82/100
维护者通常 1 天内回复
-
"code source" and "numerique.gouv" links: "new window" mention duplicated in the accessible name未关闭accessibility
难度 2/5 1-3 小时 新手友好度 72/100
numerique-gouv/lasuite-landingpage#315 ·
维护者通常 1 天内回复
-
needs:triage
难度 1/5 1 小时以内 新手友好度 92/100
维护者通常 1 天内回复
-
难度 1/5 1 小时以内 新手友好度 72/100
HyeokjaeChoi/vaultme#585 ·
维护者通常 1 天内回复
-
enhancement priority/P2
难度 2/5 1-3 小时 新手友好度 72/100
beettlle/pi-smart-router#200 ·