Skip to content

Commit 852bc25

Browse files
docs: update cli docs
1 parent ad957d8 commit 852bc25

1 file changed

Lines changed: 181 additions & 3 deletions

File tree

apps/docs/CLI.mdx

Lines changed: 181 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,13 +77,191 @@ npx rich-domain init [directory] [options]
7777
npx rich-domain init my-app
7878

7979
# Specify template and package manager
80-
npx rich-domain init my-app --template fullstack -p pnpm
80+
npx rich-domain init my-app --template fullstack-prisma -p pnpm
8181

8282
# Initialize in current directory
83-
npx rich-domain init . --template fullstack
83+
npx rich-domain init . --template fullstack-drizzle
8484

8585
# Skip all prompts
86-
npx rich-domain init my-app -t fullstack -p npm -f
86+
npx rich-domain init my-app -t fullstack-typeorm -p npm -f
87+
```
88+
89+
---
90+
91+
## Templates
92+
93+
### Available Templates
94+
95+
| Template | Stack | Description |
96+
| -------------------- | --------------------------------------- | ---------------------------------------- |
97+
| `fullstack-prisma` | Fastify + Prisma + BullMQ + Zod | Prisma v7 with driver adapter (pg) |
98+
| `fullstack-drizzle` | Fastify + Drizzle ORM + BullMQ + Zod | Drizzle with node-postgres |
99+
| `fullstack-typeorm` | Fastify + TypeORM + BullMQ + Zod | TypeORM with decorators and DataSource |
100+
101+
All templates share the same DDD architecture and generate the same project structure. They differ only in the ORM layer.
102+
103+
### Generated Project Structure
104+
105+
```
106+
my-app/
107+
├── prisma.config.ts # ORM config (Prisma) / drizzle.config.ts (Drizzle)
108+
├── docker-compose.yml # PostgreSQL + Redis
109+
├── .env.example
110+
├── tsconfig.json
111+
└── src/
112+
├── env.ts # Zod-validated environment variables
113+
├── server.ts # Fastify app entry point
114+
├── constants.ts # Queue name constants
115+
├── domain/
116+
│ ├── entities/
117+
│ │ └── user.aggregate.ts
118+
│ ├── repositories/
119+
│ │ └── user.repository.ts
120+
│ ├── events/
121+
│ │ └── user-created.event.ts
122+
│ └── value-objects/
123+
│ └── email.ts
124+
├── application/
125+
│ ├── service/
126+
│ │ └── user.service.ts
127+
│ └── processor/
128+
│ ├── events.processor.ts # Observe-only handlers (logging, emails)
129+
│ └── action.processor.ts # Mutation handlers
130+
├── infra/
131+
│ ├── database/
132+
│ │ ├── <orm>/ # Schema/entity files
133+
│ │ ├── mappers/ # Domain ↔ persistence mappers
134+
│ │ ├── repositories/ # Concrete repository implementations
135+
│ │ ├── schemas/ # Persistence type definitions
136+
│ │ └── seed/
137+
│ ├── queue/
138+
│ │ ├── connection.ts # IORedis connection
139+
│ │ ├── event-bus.ts # BullMQ IDomainEventBus implementation
140+
│ │ ├── event-worker.ts # BullMQ domain event worker
141+
│ │ └── queue-publisher.ts
142+
│ └── di/
143+
│ ├── container.ts # DI container
144+
│ └── fastify-plugin.ts # Fastify DI decorator
145+
└── presentation/
146+
├── controllers/
147+
│ └── user.controller.ts
148+
└── dto/
149+
└── user/
150+
└── user.dto.ts
151+
```
152+
153+
### Scripts
154+
155+
All templates include the same base scripts:
156+
157+
| Script | Description |
158+
| --------------- | ------------------------------- |
159+
| `dev` | Start dev server with tsx watch |
160+
| `build` | Compile TypeScript |
161+
| `start` | Start production server |
162+
| `lint` | Type-check without emitting |
163+
| `db:generate` | Generate ORM client/migrations |
164+
| `db:migrate` | Run migrations |
165+
| `db:push` | Push schema to database |
166+
| `db:studio` | Open ORM studio UI |
167+
| `db:seed` | Run seed script |
168+
| `docker:up` | Start PostgreSQL + Redis |
169+
| `docker:down` | Stop Docker services |
170+
171+
<Note>
172+
TypeORM does not include `db:generate`, `db:migrate`, `db:push`, or `db:studio` — schema synchronization is handled by `synchronize: true` in development mode.
173+
</Note>
174+
175+
### fullstack-prisma
176+
177+
Uses **Prisma v7** with the `@prisma/adapter-pg` driver adapter (required in v7) and `prisma.config.ts` for schema configuration.
178+
179+
**Key dependencies:** `@prisma/client`, `@prisma/adapter-pg`, `pg`, `@woltz/rich-domain-prisma`
180+
181+
```typescript
182+
// src/infra/database/prisma.ts
183+
import { PrismaClient } from "@prisma/client";
184+
import { PrismaPg } from "@prisma/adapter-pg";
185+
186+
const adapter = new PrismaPg({ connectionString: env.DATABASE_URL });
187+
export const prisma = new PrismaClient({ adapter });
188+
```
189+
190+
```typescript
191+
// prisma.config.ts
192+
import { defineConfig } from "prisma/config";
193+
194+
export default defineConfig({
195+
schema: path.join("src", "infra", "database", "prisma", "schema.prisma"),
196+
datasource: {
197+
url: env.DATABASE_URL,
198+
},
199+
migrations: {
200+
path: path.join("src", "infra", "database", "prisma", "migrations"),
201+
seed: path.join("src", "infra", "database", "seed", "seed.ts"),
202+
},
203+
});
204+
```
205+
206+
### fullstack-drizzle
207+
208+
Uses **Drizzle ORM** with `drizzle-orm/node-postgres` and a lazy-initialized connection pool.
209+
210+
**Key dependencies:** `drizzle-orm`, `pg`, `@woltz/rich-domain-drizzle`
211+
212+
```typescript
213+
// src/infra/database/db.ts
214+
export async function initializeDatabase() {
215+
pool = new Pool({ connectionString: env.DATABASE_URL });
216+
db = drizzle(pool, { schema });
217+
}
218+
```
219+
220+
```typescript
221+
// drizzle.config.ts
222+
export default defineConfig({
223+
schema: "./src/infra/database/drizzle/schema.ts",
224+
out: "./src/infra/database/drizzle/migrations",
225+
dialect: "postgresql",
226+
});
227+
```
228+
229+
### fullstack-typeorm
230+
231+
Uses **TypeORM** with `DataSource`, decorator-based entities, and `synchronize: true` in development.
232+
233+
**Key dependencies:** `typeorm`, `pg`, `reflect-metadata`, `@woltz/rich-domain-typeorm`
234+
235+
```typescript
236+
// src/infra/database/db.ts
237+
export const AppDataSource = new DataSource({
238+
type: "postgres",
239+
url: env.DATABASE_URL,
240+
synchronize: env.NODE_ENV === "development",
241+
entities: [UserEntity],
242+
});
243+
```
244+
245+
<Warning>
246+
The TypeORM template enables `synchronize: true` in development mode. Disable this and use migrations in production.
247+
</Warning>
248+
249+
### Getting Started
250+
251+
After running `init`:
252+
253+
```bash
254+
cd my-app
255+
pnpm install
256+
cp .env.example .env
257+
pnpm docker:up
258+
pnpm db:push # or db:migrate for Prisma/Drizzle
259+
pnpm dev
260+
```
261+
262+
```
263+
API: http://localhost:3000
264+
Swagger: http://localhost:3000/doc
87265
```
88266

89267
---

0 commit comments

Comments
 (0)