What is Syncer?
File Change Detection
Track Entity, Model, Types file changesEfficient checksum-based detection
Auto Code Generation
Generate types, schemas, API clientsTemplate-based generation
HMR Support
Real-time reflection during developmentFile invalidation and reload
Multi-Target Sync
Sync to web, app, and other projectsAutomatic file copying
Syncer Operation Flow
Watched File Patterns
File patterns that Syncer tracks for changes:| File Type | Pattern | Purpose |
|---|---|---|
| Entity | src/application/**/*.entity.json | Data structure definition |
| Types | src/application/**/*.types.ts | Type definitions |
| Model | src/application/**/*.model.ts | Business logic |
| Frame | src/application/**/*.frame.ts | Frame logic |
| Functions | src/application/**/*.functions.ts | Utility functions |
| Generated | src/application/sonamu.generated.ts | Generated base file |
| Config | src/sonamu.config.ts | Sonamu configuration |
| Workflow | src/application/**/*.workflow.ts | Workflow definitions |
| i18n | src/i18n/**/*.ts | Internationalization files |
File patterns: Managed in
file-patterns.ts, change detection via checksumManual Synchronization
You can manually sync without the development server.Automatic Synchronization (HMR)
During development server runtime, file changes are automatically detected and synchronized.Syncer Events
Syncer emits events as an EventEmitter.| Event | When Triggered | Use Case |
|---|---|---|
onHMRCompleted | HMR completion | Trigger follow-up tasks |
Syncer Actions
Different actions execute based on file change type.1. Entity Change (handleTruthSourceChanges)
Regenerates schemas when Entity file changes.
Trigger: *.entity.json file change
Actions:
- Reload EntityManager
- Generate
*.types.tsfor new Entity - Generate schema files:
sonamu.generated.tssonamu.generated.sso.ts
- Copy files to targets
2. Types/Functions/Generated Change
Copies type files to targets when they change. Trigger:*.types.ts, *.functions.ts, *.generated.ts change
Actions:
- Collect changed file list
- Copy to each target (
web,app) - Transform
sonamuimport to./sonamu.shared
sonamu.shared.ts: Since web/app donβt have the sonamu package, common utilities are provided via a shared file.
3. Model/Frame Change
Regenerates API clients when Model file changes. Trigger:*.model.ts, *.frame.ts change
Actions:
- Reload Model, Types, APIs
- Generate API client (
services.generated.ts) - Generate HTTP test file (
sonamu.generated.http) - Regenerate SSR files (
queries.generated.ts,entry-server.generated.tsx)
4. Config Change
Synchronizes environment variables when config file changes. Trigger:sonamu.config.ts change
Actions:
- Create/update
.sonamu.envfile - Copy to each target
web/.sonamu.env
5. Workflow Change
Reloads when workflow file changes. Trigger:*.workflow.ts change
Actions: Reload and sync workflows
6. i18n Change
Regenerates SD file when i18n file changes. Trigger:src/i18n/**/*.ts change
Actions:
- Copy Locale files to targets
- Generate
sd.generated.ts(api, web, app)
7. SSR Config Change
Immediately reloads when SSR route config files change. Trigger:src/ssr/**/*.ts change
Actions:
- Invalidate changed file (HMR)
- Reload all SSR routes (
autoloadSSRRoutes) - Emit HMR completed event
SSR config changes are not part of checksum-based sync. The watcher detects them directly and processes them through a separate path.
Checksum-Based Change Detection
Syncer stores file checksums for efficient change detection.sonamu.lock
- Calculate SHA-1 hash of file content
- Compare with stored checksum
- Consider changed if different
- Update checksum after sync
- Fast change detection (no file content comparison needed)
- Accurate change tracking (unaffected by timestamp)
- Handle multiple file changes simultaneously
Syncer API
Syncer can be used programmatically.Manual Synchronization
Template Generation
Module Loading
Syncer Configuration
You can configure Syncer behavior insonamu.config.ts.
api/src/sonamu.config.ts
Development Workflow
Typical development flow using Syncer:Define Entity
Define Entity in Sonamu UI or modify
.entity.json file.Auto-executed:- Generate
*.types.ts - Update
sonamu.generated.ts - Update
sonamu.generated.sso.ts - Copy files to targets
Write Model
Write business logic in Model and add
@api decorator.Auto-executed:- Update
services.generated.ts - Update
sonamu.generated.http - Update SSR files
Troubleshooting
When Syncer Doesnβt Work
Files Not Being Generated
Files Not Being Generated
Check:
- Confirm development server is running
- Verify file matches watched patterns
- Delete checksum file and retry
Files Not Being Copied to Targets
Files Not Being Copied to Targets
Check:
- Verify
sync.targetsinsonamu.config.ts - Confirm target directory exists
- Create
src/services/directory in target
Slow HMR
Slow HMR
Optimization methods:
- Use latest Node.js version (v22+)
- Use SSD (HDD is slow)
- Exclude unnecessary files
- Separate TypeScript projects (monorepo)
Import Errors
Import Errors
Cause:
sonamu import not transformed to ./sonamu.sharedSolution: