Getting Started
How do I start a new project with Sonamu?
How do I start a new project with Sonamu?
Create a new project with the following command:Follow the interactive prompts to configure your project:Run the project:Accessible URLs:Requirements:
Node.js >= 18, pnpm >= 10, DockerWhat tech stack does Sonamu use?
What tech stack does Sonamu use?
Development Environment
What exactly happens when I run pnpm dev?
What exactly happens when I run pnpm dev?
-
Instant TypeScript execution
- Transforms TypeScript files at runtime with
@sonamu-kit/ts-loader - Registered via Node.js
--importflag
- Transforms TypeScript files at runtime with
-
Sonamu initialization (
Sonamu.init)- Load DB configuration
- Load Entity files
- Create Syncer and auto-load Types/Models/APIs
- Run initial sync (
syncer.sync()) - Start file watcher (
startWatcher())
-
Fastify server creation and configuration
- Register plugins (
formbody,multipart,session, etc.) - Auth setup (if needed)
- Register methods with
@apidecorator as API endpoints
- Register plugins (
-
Server starts listening
- Fastify server starts on the configured port
-
HMR enabled
- Automatically regenerates types and reloads modules when files change
I ran pnpm dev and got "Port 1028 is already in use" error
I ran pnpm dev and got "Port 1028 is already in use" error
Method 1: Change the portMethod 2: Kill existing process (macOS/Linux)
File Generation
What code does Sonamu generate?
What code does Sonamu generate?
What files does Sonamu generate and when?
What files does Sonamu generate and when?
1. Auto-generated (on Entity creation/modification)
-
{entity}.entity.json- Entity table structure, fields, relations, indexes, Subset definitions
- Created: When Entity is created in Sonamu UI
-
{entity}.types.ts- Custom type definitions for the Entity
- Created: When Entity is created (initial template only, modified by developer afterwards)
-
sonamu.generated.ts- Auto-generates all Entity
BaseSchema,Enum,Subsettypes - Created: Auto-regenerated whenever Entity or type files change
- Auto-generates all Entity
-
sonamu.generated.sso.ts- Subset-specific query builders and server-only types
- Created: Auto-regenerated whenever Entity changes
-
migrations/{timestamp}_{action}.ts- Migration files for database schema changes
- Created: When clicking Generate in DB Migration tab
-
{entity}.model.ts- Entity business logic and API definitions with
@apidecorator - Created: When generating Model template in Scaffolding tab (once only)
- Entity business logic and API definitions with
-
{entity}.model.test.ts- Unit test files for Model methods
- Created: When generating Test template in Scaffolding tab
-
*.view.tsx- React-based back-office UI components
- Created: When generating View template in Scaffolding tab
-
{entity}.service.ts- Frontend client code that calls backend APIs
- Created: When Model file changes are detected
-
sonamu.generated.http- API test templates for VSCode REST Client
- Created: When methods with
@apidecorator are added/changed
-
Frontend file copy
types.ts,generated.ts, etc. auto-copied toweb/src/services/- Created: Auto-copied to paths defined in sync.targets when backend files change
-
sonamu.lock- Checksum file for tracking file changes
- Created: Auto-updated for file change tracking
What happens if I directly modify code generated by Sonamu?
What happens if I directly modify code generated by Sonamu?
Always overwritten (overwrite: true)The following files are always overwritten on regeneration, so do not modify:
sonamu.generated.ts- Always regenerated on Entity changessonamu.generated.sso.ts- Always regenerated on Entity changes{entity}.service.ts- Always regenerated on Model changessonamu.generated.http- Always regenerated on@apimethod changes
{entity}.types.ts- Can add custom types{entity}.model.ts- Can add/modify business logic{entity}.model.test.ts- Can add/modify test cases*.view.tsx- Can customize UI
- Add custom types in
{entity}.types.ts - Implement business logic in
{entity}.model.ts - Use Sonamu UI for Entity definitions
Should lock files and generated code managed by Sonamu be version controlled?
Should lock files and generated code managed by Sonamu be version controlled?
Files that must be committed:
sonamu.lock- Entity schema change tracking, team synchronizationsonamu.generated.ts- Type synchronization, immediately usable by frontend{entity}.types.ts- Custom type definitionsmigrations/*.ts- DB schema change history{entity}.model.ts- Business logic
- Type synchronization allows frontend developers to use immediately
- Reduces build time
- Easier code review
Scaffolding
What is scaffolding and why do I need it?
What is scaffolding and why do I need it?
Scaffolding is a feature that auto-generates repetitive boilerplate code based on templates.What can be generated:
- Model classes (
{entity}.model.ts) - Test files (
{entity}.model.test.ts) - View components (
*.view.tsx)
- Access Sonamu UI
- Go to Scaffolding tab
- Select Entity
- Select Template (model/model_test/view_list/view_form)
- Click Generate
- Saves development time by auto-generating repetitive CRUD code
- Maintains consistent code structure
- Prevents typos and omissions
- Beginners can learn standard patterns
overwrite: false(default): Does not generate if file already exists (model, test, view templates)overwrite: true: Always overwrites even if file exists (generated, service templates)