Skip to main content
Sonamu is a TypeScript framework that enables entity-centric full-stack development. This guide explains Sonamu’s overall architecture and core operating principles.

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
  1. {entity}.types.ts - Per-entity types (extensible)
  2. sonamu.generated.ts - All Base schemas (auto-generated)
  3. 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 @api decorator
  • 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 dev is running (HMR)
  • Manual: When pnpm sync command 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)

Auto-generated on save:
  • post.types.ts
  • sonamu.generated.ts updated
2

2. Migration (Migration tab)

On execution:
  • Table created in database
3

3. Write Model (manual or scaffolding)

Auto-generated on save:
  • REST API: GET /api/posts/:id
  • PostService.ts (frontend)
  • sonamu.generated.http updated
4

4. Frontend Usage

Type safety:
  • 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

Files You Should Never Modify
  • sonamu.generated.ts - Overwritten on next sync
  • {Entity}Service.ts - Overwritten on next sync
  • sonamu.generated.sso.ts - Overwritten on next sync
These files are always auto-generated, so don’t modify them directly!

Type Safety Flow

Visualizing Sonamu’s End-to-End type safety:
Type Safety Guaranteed
  1. Entity definition β†’ Type generation
  2. Model β†’ API type inference
  3. API β†’ Service type synchronization
  4. Service β†’ UI type checking
When types change at any stage, it’s reflected across the entire chain and errors are caught at compile time!

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:
Constraints to Be Aware Of
  1. Learning curve: Need to understand Sonamu’s concepts and rules
  2. Cannot modify auto-generated files: Manual modifications get overwritten
  3. Entity-centric design required: Must follow the Sonamu way
  4. Complex queries: Very complex cases may require Raw SQL
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.