refactor: modularize serialization and improve codebase quality #3
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
Major refactoring to improve code maintainability, organization, and quality. This PR transforms the codebase into a well-structured, production-ready project.
Key Changes
🏗️ Architecture Improvements
serializers/primitives.ts- Color, Vector2, Matrix, Transform, Paintserializers/animations.ts- Timeline, Keyframe, AnimationTrackserializers/nodes.ts- Scene graph serializationserializers/assets.ts- Asset bundlingserializers/file.ts- Validation, versioning, compressionserializer.ts- Main coordinator (331 LOC)✨ Error Handling
RendererErrorwith helper methods (notInitialized(),invalidDimensions())📚 Documentation
🧪 Testing
Impact
Metrics
Breaking Changes
None - all changes are backward compatible.
Greptile Overview
Greptile Summary
This PR transforms the codebase through a well-executed modularization refactoring. The main serializer module was split from 1,597 lines into 5 focused modules totaling ~1,600 lines, significantly improving maintainability without changing functionality.
Key Improvements
serializer.tsis now a clean 331-line coordinator that delegates to specialized modules (primitives,animations,nodes,assets,file)RendererErrorfor common scenarios (notInitialized(),invalidDimensions())Quality Indicators
The refactoring follows solid design principles with clear module boundaries and cohesive responsibilities.
Confidence Score: 5/5
Important Files Changed
Sequence Diagram
sequenceDiagram participant User participant Serializer participant FileSerializers participant NodeSerializers participant AnimationSerializers participant PrimitiveSerializers participant AssetSerializers Note over User,AssetSerializers: Serialization Flow User->>Serializer: serializeSamcanFile(artboards, metadata, options) alt Include Assets Serializer->>AssetSerializers: collectAssets(artboards, assetManager) AssetSerializers-->>Serializer: assets[] end loop For each artboard Serializer->>NodeSerializers: serializeArtboard(artboard) NodeSerializers->>NodeSerializers: assignNodeIds(artboard) NodeSerializers->>AnimationSerializers: setNodeIdMap(nodeIdMap) NodeSerializers->>PrimitiveSerializers: serializeColor(backgroundColor) PrimitiveSerializers-->>NodeSerializers: ColorData loop For each child node NodeSerializers->>NodeSerializers: serializeNode(child) NodeSerializers->>PrimitiveSerializers: serializeTransform(node.transform) PrimitiveSerializers-->>NodeSerializers: TransformData alt ShapeNode NodeSerializers->>PrimitiveSerializers: serializePaint(fill/stroke) PrimitiveSerializers-->>NodeSerializers: PaintData end end NodeSerializers->>AnimationSerializers: serializeTimeline(timeline) AnimationSerializers-->>NodeSerializers: TimelineData NodeSerializers-->>Serializer: ArtboardData end Serializer-->>User: SamcanFile Note over User,AssetSerializers: Deserialization Flow User->>Serializer: fromJSON(jsonString) Serializer->>FileSerializers: fromJSON(json) FileSerializers->>FileSerializers: validateSamcanFile(data) FileSerializers->>FileSerializers: migrateSamcanFile(data) FileSerializers-->>Serializer: SamcanFile Serializer->>Serializer: deserializeSamcanFile(data) loop For each artboard Serializer->>NodeSerializers: deserializeArtboard(artboardData) NodeSerializers->>PrimitiveSerializers: deserializeColor(backgroundColor) PrimitiveSerializers-->>NodeSerializers: Color loop For each node NodeSerializers->>NodeSerializers: deserializeNode(nodeData, nodeMap) NodeSerializers->>PrimitiveSerializers: deserializeTransform(transformData) PrimitiveSerializers-->>NodeSerializers: Transform alt ShapeNode NodeSerializers->>PrimitiveSerializers: deserializePaint(paintData) PrimitiveSerializers-->>NodeSerializers: Paint end end NodeSerializers->>AnimationSerializers: deserializeTimeline(timelineData, nodeMap) AnimationSerializers-->>NodeSerializers: Timeline NodeSerializers-->>Serializer: Artboard end Serializer-->>User: {artboards, stateMachines}