Sonamuβs Philosophy
Sonamu is designed based on the following principles:1
1. Entity First
All development starts with entity definition. Define the data structure first, and the rest is automatically generated.
2
2. Type Safety
Complete type safety is guaranteed from backend to frontend. Errors can be caught at compile time.
3
3. Code Generation
Repetitive boilerplate code is automatically generated. Developers can focus only on business logic.
4
4. Developer Experience
Excellent developer experience with HMR, type inference, Sonamu UI, and more.
Overall Architecture
Sonamu operates with 6 layers automatically connected:Core Components
1. Entity
Entity is the starting point of everything in Sonamu.user.entity.json
Role of Entity Definition
- Source of database schema
- Basis for TypeScript type generation
- Definition of API interfaces
- Standard for frontend types
2. Type System
3 type files are automatically generated from entity definitions:Three Type Files
{entity}.types.ts- Per-entity types (extensible)sonamu.generated.ts- All Base schemas (auto-generated)sonamu.generated.sso.ts- Subset queries (auto-generated)
3. Model (Business Logic)
Model handles the business logic of entities.user.model.ts
Model Features
- Auto REST API generation with
@apidecorator - Basic CRUD methods provided by inheriting
BaseModelClass - Type-safe DB queries with Puri query builder
- Focus only on business logic
4. Syncer (Synchronization System)
Syncer is Sonamuβs core engine. It detects file changes and automatically generates code.πΈ Needed: Syncer operation flowchart (file change detection β code generation β synchronization)
When Syncer Runs
- Auto: During file changes while
pnpm devis running (HMR) - Manual: When
pnpm synccommand is executed
5. API Layer (REST API)
The Modelβs@api decorator automatically generates REST APIs.
Whatβs Auto-Generated
- β REST API routes
- β Request parameter validation (Zod)
- β Response types
- β Error handling
- β API documentation (sonamu.generated.http)
6. Frontend Service (Frontend Integration)
Model APIs are automatically generated as frontend Services.web/src/services/UserService.ts (auto-generated)
Type Safety
Backend types are synchronized directly to the frontend, so type mismatch errors can be caught at compile time!
Development Flow
Letβs see how Sonamu works during actual development:1
1. Entity Definition (Sonamu UI)
post.types.tssonamu.generated.tsupdated
2
2. Migration (Migration tab)
- Table created in database
3
3. Write Model (manual or scaffolding)
- REST API:
GET /api/posts/:id PostService.ts(frontend)sonamu.generated.httpupdated
4
4. Frontend Usage
- Frontend immediately detects errors when backend types change
π¬ Needed: Animation or video showing the above 4-step flow
HMR (Hot Module Replacement)
Sonamu provides a powerful HMR system.How HMR Works
Benefits of HMR
- β Fast feedback - Reflected within 1-2 seconds after code change
- β State preservation - Database connections, etc. maintained
- β Auto sync - Frontend Service auto-updated
πΈ Needed: Terminal logs showing HMR in action (file change β invalidate β restart)
Auto Generation Mechanism
Letβs summarize what Sonamu automatically generates:On Entity Definition Change
On Model File Change
On Types File Change
Type Safety Flow
Visualizing Sonamuβs End-to-End type safety:Type Safety Guaranteed
- Entity definition β Type generation
- Model β API type inference
- API β Service type synchronization
- Service β UI type checking
Key Advantages of Sonamu
1. Development Speed Improvement
2. Type Safety
3. Maintainability
4. Consistency
Constraints and Trade-offs
Sonamuβs powerful features come with some constraints:But the advantages far outweighβ
Development speed improvement (90% time reduction)
β
Type safety guaranteed
β
Improved maintainability
β
Code consistency
β
Team productivity improvement
Next Steps
Now that you understand how Sonamu works, learn about each component in detail:Defining Entities
Learn entity structure and configuration options in detail.
Understanding Models
Learn the role of Models and how to write business logic.
Auto Generation Mechanism
Learn which files are automatically generated.
Type System
Understand how Sonamuβs type safety works.