Skip to main content
If you directly modify code auto-generated by Sonamu, it will be overwritten on the next regeneration. This document explains how to safely customize generated code.

Basic Principles

Generated Files are Read-Only

Never modify *.generated.* files Changes lost on auto-regeneration

Customize Through Extension

Wrap or extend in separate files Safe and maintainable

Control at Source

Adjust in Entity, Model, Types Preserved across regenerations

Leverage Templates

Control generation with custom templates Reflect project requirements

Modifiable vs Non-Modifiable Files

❌ Non-Modifiable Files

Never modify these files. They are overwritten on regeneration.

✅ Modifiable Files

These files can be modified after initial generation.

Customizing API Clients

Don’t modify services.generated.ts directly—wrap it instead.

❌ Wrong Approach

services.generated.ts

✅ Correct Approach 1: Wrapper Functions

Benefits:
  • No modification to generated files
  • Reuses original functions
  • Maintains type safety

✅ Correct Approach 2: Axios Interceptor

services/axios-config.ts (create new)
Benefits:
  • Automatically applies to all APIs
  • Eliminates duplicate code
  • Centralized configuration

✅ Correct Approach 3: TanStack Query Customization

hooks/useUserQuery.ts (create new)
Benefits:
  • Centralized management of common options
  • Per-component customization possible
  • Leverages TanStack Query features

Customizing Types

{entity}.types.ts is not regenerated, so you can modify it freely.

Adding Custom Types

api/src/application/user/user.types.ts
Note: {entity}.types.ts is copied to targets, so changes are automatically synchronized.

Enhanced Validation

user.types.ts

Customizing Models

Model files can be freely modified after scaffolding.

Adding Methods

api/src/application/user/user.model.ts
Added APIs are auto-generated:
  • login(), me() functions added to services.generated.ts
  • Test cases added to sonamu.generated.http

Separating Helper Methods

api/src/application/user/user.helpers.ts (create new)
Usage in user.model.ts

Customizing React Components

Components generated via scaffold can be freely modified.

Customizing Form Components

web/src/pages/user/UserForm.tsx

Customizing List Components

web/src/pages/user/UserList.tsx

Customizing Enums

To add or modify enums, adjust them in the Entity.

Modifying Enums in Entity

Extending Enums (Separate File)

user.types.ts

Customizing Subsets

To modify subsets, adjust them in the Entity.

Adding/Removing Subset Fields

Next Steps

When Files Regenerate

Understand file regeneration timing

Syncer

Deep dive into the Syncer system

Templates

Create custom templates

Testing

Test your customized code