Skip to main content
Sonamu automatically generates type definitions and Service code when Entities and APIs change, synchronizing them to frontend projects. Use sync.targets to specify the frontends to sync to.

Basic Structure

targets

Specifies the list of frontend projects to synchronize. Type: string[] (required)

How It Works

When Entities or APIs change, Sonamu automatically generates and synchronizes the following files to each target directory:
  1. Type Definitions ({entity}.types.ts)
    • TypeScript types generated from Entity fields
    • Zod validation schemas
    • Subset types
  2. Service Classes ({entity}.service.ts)
    • Type-safe methods for API calls
    • TanStack Query integration ready

Directory Structure

Single Frontend

The most common case, using only one web frontend.
Project structure:
Sync location: web/src/services/

Multiple Frontends

When developing web and app (React Native, Flutter, etc.) simultaneously:
Project structure:
Sync locations:
  • web/src/services/
  • app/src/services/
Each frontend shares the same types and Services, so all clients are automatically updated when APIs change.

target Directory Location

By default, Sonamu looks for directories with the same name as the target in the project root.

Custom Paths

If target directories are in different locations, you can use relative paths:
Project structure:

Verifying Sync

When you modify and save an Entity, sync messages appear in the console:

Generated Files

Two files are generated for each Entity: user.types.ts:
user.service.ts:

Disabling Sync

If there’s no frontend or sync is not needed, specify an empty array:
Sync can be disabled for API-only projects (e.g., microservices).

Practical Examples

Basic Web Project

Project structure:

Web + Mobile App

Project structure:

Monorepo Structure

Project structure:

Sync Cautions

1. Don’t Modify Auto-generated Files

Synced files are auto-generated, so don’t modify them directly.
Use a wrapper class instead:

2. Git Management

Commit synced files to Git.
Reasons:
  • Team members can develop frontend without running backend
  • CI/CD can build frontend without Sonamu

3. Verify target Directory Exists

The directory specified as target must exist.
Solution:

Frontend Setup

Some configuration is needed in the frontend to use synced Services.

1. API Client Setup

web/src/lib/api-client.ts:

2. Using Services

β†’ Frontend Integration Guide

Next Steps

After completing sync target configuration: