Quick Start
The steps use Bun. On Node.js or Deno pass --runtime node or --runtime deno in step 1 and run the scripts with npm run or deno task.
1. Create the project
bun create miia my-app -y
cd my-app
-y takes the defaults and skips the prompts; without it the CLI asks for the runtime and optional features. See miia new for every flag.
2. Look around
src/
├── main.ts
├── env.schema.ts
└── app/
├── app.module.ts
├── app.controller.ts
├── app.service.ts
└── app.test.ts
The root module configures ConfigModule globally, so every module can inject ConfigService, and registers the controller and its service:
import { ConfigModule } from '@miiajs/config'
import { Module } from '@miiajs/core'
import { envSchema } from '../env.schema.js'
import { AppController } from './app.controller.js'
import { AppService } from './app.service.js'
@Module({
imports: [ConfigModule.configure({ schema: envSchema }, { global: true })],
controllers: [AppController],
providers: [AppService],
})
export class AppModule {}
import { Controller, Get, inject } from '@miiajs/core'
import { AppService } from './app.service.js'
@Controller()
export class AppController {
private readonly appService = inject(AppService)
@Get()
hello() {
return { message: this.appService.getHello() }
}
}
main.ts reads PORT and HOST, validated by src/env.schema.ts, through a typed ConfigService and starts the server. Bun and Deno are detected by app.listen(); on Node.js the generated main.ts passes serve from @miiajs/node-server.
import { ConfigService } from '@miiajs/config'
import { Miia } from '@miiajs/core'
import { AppModule } from './app/app.module.js'
import type { Env } from './env.schema.js'
const app = new Miia().register(AppModule)
const config = app.get<ConfigService<Env>>(ConfigService)
await app.listen(config.get('PORT'), config.get('HOST'))
3. Run it
bun run dev
miia dev restarts the app on file changes and type-checks in the background.
curl http://localhost:3000/
# {"message":"Hello, Miia!"}
4. Test it
bun run test
src/app/app.test.ts starts the controller in a TestApp and sends a request in-process - no port, no .env.
5. Add a CRUD resource
bunx miia g resource posts
This writes src/posts/ - module, controller, service, the Posts interface in posts.types.ts, zod schemas in schemas/ and a test - and adds PostsModule to the imports of the root module. The resource answers right away:
curl -X POST http://localhost:3000/posts \
-H "Content-Type: application/json" \
-d '{"name":"First"}'
# {"id":"0f8fad5b-d9cb-469f-a165-70867728950e","name":"First"}
curl http://localhost:3000/posts/42
# 422: the id is not a UUID
curl http://localhost:3000/posts/00000000-0000-4000-8000-000000000000
# 404
bun run test
# the posts test runs next to the app test
6. Add Swagger
bunx miia add swagger
The add-on installs @miiajs/swagger, registers SwaggerModule in the root module and leaves the rest of the file as it was. The spec is at /docs/json and the UI at /docs. Other add-ons: jwt-auth, cors, serve-static, rate-limit, biome and the databases - see miia add.
Next steps
- Controllers and validation with route schemas
- Providers and modules to structure the app
- Authentication with
bunx miia add jwt-auth - Manual setup if you would rather wire a project by hand