Skip to main content
Syncer is Sonamu’s automatic generation system. It detects file changes, automatically generates necessary code, and synchronizes to target projects (web, app, etc.).

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 patterns: Managed in file-patterns.ts, change detection via checksum

Manual Synchronization

You can manually sync without the development server.
Execution result:

Automatic Synchronization (HMR)

During development server runtime, file changes are automatically detected and synchronized.
HMR log example:

Syncer Events

Syncer emits events as an EventEmitter.
Event types:

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:
  1. Reload EntityManager
  2. Generate *.types.ts for new Entity
  3. Generate schema files:
    • sonamu.generated.ts
    • sonamu.generated.sso.ts
  4. 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:
  1. Collect changed file list
  2. Copy to each target (web, app)
  3. Transform sonamu import 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:
  1. Reload Model, Types, APIs
  2. Generate API client (services.generated.ts)
  3. Generate HTTP test file (sonamu.generated.http)
  4. 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:
  1. Create/update .sonamu.env file
  2. 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/**/!(sd.generated).ts change Actions:
  1. Copy Locale files to targets
  2. 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:
  1. Invalidate changed file (HMR)
  2. Reload all SSR routes (autoloadSSRRoutes)
  3. 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
How it works:
  1. Calculate SHA-1 hash of file content
  2. Compare with stored checksum
  3. Consider changed if different
  4. Update checksum after sync
Advantages:
  • 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 in sonamu.config.ts.
api/src/sonamu.config.ts

Development Workflow

Typical development flow using Syncer:
1

Start Development Server

Syncer watches for file changes.
2

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
3

Write Model

Write business logic in Model and add @api decorator.Auto-executed:
  • Update services.generated.ts
  • Update sonamu.generated.http
  • Update SSR files
4

Frontend Development

Develop UI using generated API clients and Types.
5

Real-time Reflection

Modifying Model or Entity reflects immediately via HMR.Check changes without browser refresh!

Troubleshooting

When Syncer Doesn’t Work

Check:
  1. Confirm development server is running
  2. Verify file matches watched patterns
  3. Delete checksum file and retry
Check:
  1. Verify sync.targets in sonamu.config.ts
  2. Confirm target directory exists
  3. Create src/services/ directory in target
Optimization methods:
  1. Use latest Node.js version (v22+)
  2. Use SSD (HDD is slow)
  3. Exclude unnecessary files
  4. Separate TypeScript projects (monorepo)
Cause: sonamu import not transformed to ./sonamu.sharedSolution:

Next Steps

When Files Regenerate

Detailed guide on file regeneration timing

Customizing Generated Code

How to customize generated code

Templates

Create custom templates

HMR System

Deep understanding of HMR system