Skip to content

Commit fc4b88e

Browse files
committed
feat(create-tbk-app): add module and seeder command templates
- Introduced new command templates for creating modules and seeders, including detailed instructions and verification steps. - Enhanced user guidance for generating module files, registering routers, and managing seeders with optional execution. - Improved documentation for better clarity on module and seeder functionalities.
1 parent 1758164 commit fc4b88e

File tree

3 files changed

+174
-1
lines changed

3 files changed

+174
-1
lines changed

packages/create-tbk-app/src/prompts.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ export async function collectProjectConfig(
114114

115115
export function renderSummary(config: ProjectConfig) {
116116
note(
117-
[
117+
[
118118
`Name: ${config.projectName}`,
119119
`Preset: ${config.preset}`,
120120
`Auth: ${config.auth}${config.auth === 'jwt-sessions' && config.sessionDriver ? ` (${config.sessionDriver})` : ''}`,
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
---
2+
description: Scaffold a fully-typed module with controller, service, router, schema, and model files
3+
argument-hint: <moduleName> [--path <apiPath>]
4+
allowed-tools: Bash, Read, Edit
5+
model: claude-sonnet-4-5
6+
---
7+
8+
# Create Module
9+
10+
Generate a complete module with all required files and wire it into the application.
11+
12+
## Task
13+
14+
**Arguments:**
15+
- `$1` (required): module name (e.g., `product`, `payment`)
16+
- `$2` (optional): API path flag `--path`
17+
- `$3` (optional): API path value (e.g., `/api/v1`); defaults to `/api`
18+
19+
**Module Name:** `$1`
20+
21+
1. **Generate module files**
22+
23+
Run the generator command:
24+
```bash
25+
pnpm tbk generate:module $1 $2 $3
26+
```
27+
28+
This creates:
29+
30+
- `src/modules/<moduleName>/<moduleName>.dto.ts`
31+
- `src/modules/<moduleName>/<moduleName>.model.ts`
32+
- `src/modules/<moduleName>/<moduleName>.schema.ts`
33+
- `src/modules/<moduleName>/<moduleName>.services.ts`
34+
- `src/modules/<moduleName>/<moduleName>.controller.ts`
35+
- `src/modules/<moduleName>/<moduleName>.router.ts` (exports `<MODULE>_ROUTER_ROOT` and default router)
36+
37+
2. **Register router in routes**
38+
39+
Read `src/routes/routes.ts` and add the router registration:
40+
41+
- Add import at top with other module imports
42+
- Add `router.use()` call with other registrations
43+
- Use camelCase for router variable name
44+
- Use UPPER_SNAKE_CASE for the router root constant
45+
46+
3. **Rebuild OpenAPI documentation**
47+
48+
```bash
49+
pnpm openapi
50+
```
51+
52+
Auto-generates Swagger from MagicRouter + Zod schemas.
53+
54+
4. **Typecheck and lint**
55+
56+
```bash
57+
pnpm typecheck && pnpm lint
58+
```
59+
60+
5. **Register with admin dashboard** (optional)
61+
62+
Ask the user if they want to add this module to the admin panel.
63+
64+
If yes, read and edit `src/plugins/admin/registry.ts` to add the resource.
65+
66+
6. **Optional: Create seeder and factory**
67+
68+
Ask the user if they need test data generation for this module.
69+
70+
If yes, run:
71+
```bash
72+
pnpm tbk make:factory $1/$(echo $1 | sed 's/.*/\u&/')
73+
pnpm tbk make:seeder $1/$(echo $1 | sed 's/.*/\u&/')
74+
```
75+
76+
## Verification
77+
78+
After completing all steps, verify:
79+
80+
1. Module files exist in `src/modules/$1/`
81+
2. Router is registered in `src/routes/routes.ts`
82+
3. OpenAPI spec regenerated successfully
83+
4. No type errors or lint warnings
84+
5. Admin panel configured (if requested)
85+
86+
Report success with the module name and available endpoints.
87+
88+
## Context
89+
90+
- All routes use MagicRouter (NOT plain Express)
91+
- Response schemas use `R.success()`, `R.paginated()`, `R.error()` builders
92+
- Controllers use `ResponseExtended<T>` for type-safe responses
93+
- Update `src/config/env.ts` and `.env.sample` if new env vars are needed
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
---
2+
description: Scaffold a seeder and factory for a module to populate test data
3+
argument-hint: <module>/<Name>
4+
allowed-tools: Bash, Read, Edit
5+
model: claude-sonnet-4-5
6+
---
7+
8+
# Create Seeder & Factory
9+
10+
Generate a factory and seeder for an existing module, register it, and optionally run it.
11+
12+
## Task
13+
14+
**Arguments:**
15+
- `$1` (required): module/name path (e.g., `user/User`, `product/Product`)
16+
17+
Parse `$1` to extract:
18+
- Module name: everything before `/`
19+
- Entity name: everything after `/`
20+
21+
## Steps
22+
23+
1. **Generate factory and seeder files**
24+
25+
Run both commands:
26+
```bash
27+
pnpm tbk make:factory $1 && pnpm tbk make:seeder $1
28+
```
29+
30+
This creates:
31+
- `src/modules/{module}/factories/{name}.factory.ts` (exports camelCase factory)
32+
- `src/modules/{module}/seeders/{Name}Seeder.ts`
33+
34+
2. **Implement seeder logic**
35+
36+
Read the generated seeder file and verify it:
37+
- Imports the correct factory
38+
- Imports the module's model
39+
- Has proper collection name in config
40+
- Uses factory.build() correctly
41+
42+
If the seeder needs customization, ask the user about:
43+
- Number of records to generate (default: 10)
44+
- Any specific field overrides needed
45+
- Dependencies on other seeders
46+
47+
3. **Register seeder**
48+
49+
Read `src/seeders/registry.ts` and add the new seeder to the array:
50+
- Import the seeder class
51+
- Add it to the `seeders` export array
52+
53+
4. **Run seeders**
54+
55+
Ask the user if they want to run the seeder now.
56+
57+
If yes, offer options:
58+
- Dry run first (recommended): `pnpm tbk seed --dry-run --only {Name}Seeder`
59+
- Run for real: `pnpm tbk seed --only {Name}Seeder`
60+
- Fresh run (drops collection): `pnpm tbk seed --fresh --only {Name}Seeder`
61+
62+
Run the selected command.
63+
64+
## Verification
65+
66+
After completing all steps, verify:
67+
68+
1. Factory file exists with `build()` method
69+
2. Seeder file exists with correct imports
70+
3. Seeder registered in `src/seeders/registry.ts`
71+
4. Dry run executes without errors
72+
5. Actual seeding creates expected records (if run)
73+
74+
Report success with the seeder name and record count.
75+
76+
## Context
77+
78+
- Factories export `{camelName}Factory` with a `build(i, overrides)` method
79+
- Seeders use `ctx.refs.set()` and `ctx.refs.get()` to share data between seeders
80+
- MongoDB must be running before seeding (`docker compose up -d`)

0 commit comments

Comments
 (0)