@buenojs/bueno 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.env.example +109 -0
- package/.github/workflows/ci.yml +31 -0
- package/LICENSE +21 -0
- package/README.md +892 -0
- package/architecture.md +652 -0
- package/bun.lock +70 -0
- package/dist/cli/index.js +3233 -0
- package/dist/index.js +9014 -0
- package/package.json +77 -0
- package/src/cache/index.ts +795 -0
- package/src/cli/ARCHITECTURE.md +837 -0
- package/src/cli/bin.ts +10 -0
- package/src/cli/commands/build.ts +425 -0
- package/src/cli/commands/dev.ts +248 -0
- package/src/cli/commands/generate.ts +541 -0
- package/src/cli/commands/help.ts +55 -0
- package/src/cli/commands/index.ts +112 -0
- package/src/cli/commands/migration.ts +355 -0
- package/src/cli/commands/new.ts +804 -0
- package/src/cli/commands/start.ts +208 -0
- package/src/cli/core/args.ts +283 -0
- package/src/cli/core/console.ts +349 -0
- package/src/cli/core/index.ts +60 -0
- package/src/cli/core/prompt.ts +424 -0
- package/src/cli/core/spinner.ts +265 -0
- package/src/cli/index.ts +135 -0
- package/src/cli/templates/deploy.ts +295 -0
- package/src/cli/templates/docker.ts +307 -0
- package/src/cli/templates/index.ts +24 -0
- package/src/cli/utils/fs.ts +428 -0
- package/src/cli/utils/index.ts +8 -0
- package/src/cli/utils/strings.ts +197 -0
- package/src/config/env.ts +408 -0
- package/src/config/index.ts +506 -0
- package/src/config/loader.ts +329 -0
- package/src/config/merge.ts +285 -0
- package/src/config/types.ts +320 -0
- package/src/config/validation.ts +441 -0
- package/src/container/forward-ref.ts +143 -0
- package/src/container/index.ts +386 -0
- package/src/context/index.ts +360 -0
- package/src/database/index.ts +1142 -0
- package/src/database/migrations/index.ts +371 -0
- package/src/database/schema/index.ts +619 -0
- package/src/frontend/api-routes.ts +640 -0
- package/src/frontend/bundler.ts +643 -0
- package/src/frontend/console-client.ts +419 -0
- package/src/frontend/console-stream.ts +587 -0
- package/src/frontend/dev-server.ts +846 -0
- package/src/frontend/file-router.ts +611 -0
- package/src/frontend/frameworks/index.ts +106 -0
- package/src/frontend/frameworks/react.ts +85 -0
- package/src/frontend/frameworks/solid.ts +104 -0
- package/src/frontend/frameworks/svelte.ts +110 -0
- package/src/frontend/frameworks/vue.ts +92 -0
- package/src/frontend/hmr-client.ts +663 -0
- package/src/frontend/hmr.ts +728 -0
- package/src/frontend/index.ts +342 -0
- package/src/frontend/islands.ts +552 -0
- package/src/frontend/isr.ts +555 -0
- package/src/frontend/layout.ts +475 -0
- package/src/frontend/ssr/react.ts +446 -0
- package/src/frontend/ssr/solid.ts +523 -0
- package/src/frontend/ssr/svelte.ts +546 -0
- package/src/frontend/ssr/vue.ts +504 -0
- package/src/frontend/ssr.ts +699 -0
- package/src/frontend/types.ts +2274 -0
- package/src/health/index.ts +604 -0
- package/src/index.ts +410 -0
- package/src/lock/index.ts +587 -0
- package/src/logger/index.ts +444 -0
- package/src/logger/transports/index.ts +969 -0
- package/src/metrics/index.ts +494 -0
- package/src/middleware/built-in.ts +360 -0
- package/src/middleware/index.ts +94 -0
- package/src/modules/filters.ts +458 -0
- package/src/modules/guards.ts +405 -0
- package/src/modules/index.ts +1256 -0
- package/src/modules/interceptors.ts +574 -0
- package/src/modules/lazy.ts +418 -0
- package/src/modules/lifecycle.ts +478 -0
- package/src/modules/metadata.ts +90 -0
- package/src/modules/pipes.ts +626 -0
- package/src/router/index.ts +339 -0
- package/src/router/linear.ts +371 -0
- package/src/router/regex.ts +292 -0
- package/src/router/tree.ts +562 -0
- package/src/rpc/index.ts +1263 -0
- package/src/security/index.ts +436 -0
- package/src/ssg/index.ts +631 -0
- package/src/storage/index.ts +456 -0
- package/src/telemetry/index.ts +1097 -0
- package/src/testing/index.ts +1586 -0
- package/src/types/index.ts +236 -0
- package/src/types/optional-deps.d.ts +219 -0
- package/src/validation/index.ts +276 -0
- package/src/websocket/index.ts +1004 -0
- package/tests/integration/cli.test.ts +1016 -0
- package/tests/integration/fullstack.test.ts +234 -0
- package/tests/unit/cache.test.ts +174 -0
- package/tests/unit/cli-commands.test.ts +892 -0
- package/tests/unit/cli.test.ts +1258 -0
- package/tests/unit/container.test.ts +279 -0
- package/tests/unit/context.test.ts +221 -0
- package/tests/unit/database.test.ts +183 -0
- package/tests/unit/linear-router.test.ts +280 -0
- package/tests/unit/lock.test.ts +336 -0
- package/tests/unit/middleware.test.ts +184 -0
- package/tests/unit/modules.test.ts +142 -0
- package/tests/unit/pubsub.test.ts +257 -0
- package/tests/unit/regex-router.test.ts +265 -0
- package/tests/unit/router.test.ts +373 -0
- package/tests/unit/rpc.test.ts +1248 -0
- package/tests/unit/security.test.ts +174 -0
- package/tests/unit/telemetry.test.ts +371 -0
- package/tests/unit/test-cache.test.ts +110 -0
- package/tests/unit/test-database.test.ts +282 -0
- package/tests/unit/tree-router.test.ts +325 -0
- package/tests/unit/validation.test.ts +794 -0
- package/tsconfig.json +27 -0
|
@@ -0,0 +1,837 @@
|
|
|
1
|
+
# Bueno CLI Architecture
|
|
2
|
+
|
|
3
|
+
**Version:** 1.0.0
|
|
4
|
+
**Last Updated:** 2026-02-17
|
|
5
|
+
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
## Executive Summary
|
|
9
|
+
|
|
10
|
+
The Bueno CLI provides a comprehensive command-line interface for the Bueno framework, enabling developers to scaffold projects, generate code, manage migrations, and control development/production workflows. Built using Bun's native capabilities without external CLI libraries, it follows the framework's philosophy of zero configuration and batteries-included development experience.
|
|
11
|
+
|
|
12
|
+
---
|
|
13
|
+
|
|
14
|
+
## 1. Design Principles
|
|
15
|
+
|
|
16
|
+
### 1.1 Core Principles
|
|
17
|
+
|
|
18
|
+
- **Bun-Native**: Use Bun's built-in APIs for all operations (file system, process management, transpilation)
|
|
19
|
+
- **Zero External Dependencies**: No third-party CLI libraries (commander, yargs, etc.)
|
|
20
|
+
- **Type-Safe**: Full TypeScript support with proper typing for all commands and options
|
|
21
|
+
- **Progressive Enhancement**: Simple defaults with optional advanced configuration
|
|
22
|
+
- **Consistent API**: Uniform command structure and option naming across all commands
|
|
23
|
+
|
|
24
|
+
### 1.2 Integration Philosophy
|
|
25
|
+
|
|
26
|
+
- **Framework-Aware**: CLI understands the module system, decorators, and project structure
|
|
27
|
+
- **Template-Driven**: All code generation uses customizable templates
|
|
28
|
+
- **Configuration-Respectful**: Reads `bueno.config.ts` when available
|
|
29
|
+
- **Non-Destructive**: Never overwrite existing files without explicit confirmation
|
|
30
|
+
|
|
31
|
+
---
|
|
32
|
+
|
|
33
|
+
## 2. Command Structure
|
|
34
|
+
|
|
35
|
+
### 2.1 Command Overview
|
|
36
|
+
|
|
37
|
+
```
|
|
38
|
+
bueno <command> [options] [arguments]
|
|
39
|
+
|
|
40
|
+
Commands:
|
|
41
|
+
bueno new <project> Create a new Bueno project
|
|
42
|
+
bueno generate <type> <name> Generate code artifacts
|
|
43
|
+
bueno migration <action> Manage database migrations
|
|
44
|
+
bueno dev Start development server
|
|
45
|
+
bueno build Build for production
|
|
46
|
+
bueno start Start production server
|
|
47
|
+
bueno help [command] Show help information
|
|
48
|
+
bueno version Show CLI version
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
### 2.2 Command Details
|
|
52
|
+
|
|
53
|
+
#### `bueno new <project-name>`
|
|
54
|
+
|
|
55
|
+
Create a new Bueno project with scaffolding.
|
|
56
|
+
|
|
57
|
+
**Usage:**
|
|
58
|
+
```bash
|
|
59
|
+
bueno new my-app
|
|
60
|
+
bueno new my-api --template minimal
|
|
61
|
+
bueno new my-fullstack --template fullstack
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
**Options:**
|
|
65
|
+
| Option | Alias | Default | Description |
|
|
66
|
+
|--------|-------|---------|-------------|
|
|
67
|
+
| `--template` | `-t` | `default` | Project template (default, minimal, fullstack, api) |
|
|
68
|
+
| `--framework` | `-f` | `react` | Frontend framework (react, vue, svelte, solid) |
|
|
69
|
+
| `--database` | `-d` | `sqlite` | Database driver (sqlite, postgresql, mysql) |
|
|
70
|
+
| `--skip-install` | | `false` | Skip dependency installation |
|
|
71
|
+
| `--skip-git` | | `false` | Skip git initialization |
|
|
72
|
+
| `--yes` | `-y` | `false` | Use default options without prompts |
|
|
73
|
+
|
|
74
|
+
**Templates:**
|
|
75
|
+
- `default`: Standard project with modules, database, and basic frontend
|
|
76
|
+
- `minimal`: Bare minimum project structure
|
|
77
|
+
- `fullstack`: Full-stack project with SSR, authentication, and frontend
|
|
78
|
+
- `api`: API-only project without frontend
|
|
79
|
+
|
|
80
|
+
---
|
|
81
|
+
|
|
82
|
+
#### `bueno generate <type> <name>`
|
|
83
|
+
|
|
84
|
+
Generate code artifacts (controllers, services, modules, etc.).
|
|
85
|
+
|
|
86
|
+
**Usage:**
|
|
87
|
+
```bash
|
|
88
|
+
bueno generate controller users
|
|
89
|
+
bueno generate service auth
|
|
90
|
+
bueno generate module posts
|
|
91
|
+
bueno g guard auth-guard
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
**Shortcuts:**
|
|
95
|
+
- `g` is an alias for `generate`
|
|
96
|
+
|
|
97
|
+
**Types:**
|
|
98
|
+
| Type | Short | Description |
|
|
99
|
+
|------|-------|-------------|
|
|
100
|
+
| `controller` | `c` | Generate a controller |
|
|
101
|
+
| `service` | `s` | Generate a service/injectable |
|
|
102
|
+
| `module` | `m` | Generate a module |
|
|
103
|
+
| `guard` | `gu` | Generate a guard |
|
|
104
|
+
| `interceptor` | `i` | Generate an interceptor |
|
|
105
|
+
| `pipe` | `p` | Generate a pipe |
|
|
106
|
+
| `filter` | `f` | Generate an exception filter |
|
|
107
|
+
| `dto` | `d` | Generate a DTO class |
|
|
108
|
+
| `middleware` | `mw` | Generate a middleware |
|
|
109
|
+
| `migration` | `mi` | Generate a migration file |
|
|
110
|
+
|
|
111
|
+
**Options:**
|
|
112
|
+
| Option | Alias | Default | Description |
|
|
113
|
+
|--------|-------|---------|-------------|
|
|
114
|
+
| `--module` | `-m` | | Parent module to register with |
|
|
115
|
+
| `--path` | | | Custom path for controller routes |
|
|
116
|
+
| `--dry-run` | | `false` | Show what would be created without writing |
|
|
117
|
+
| `--force` | | `false` | Overwrite existing files |
|
|
118
|
+
|
|
119
|
+
**Examples:**
|
|
120
|
+
```bash
|
|
121
|
+
# Generate a users controller in the users module
|
|
122
|
+
bueno g controller users --module users
|
|
123
|
+
|
|
124
|
+
# Generate an auth guard
|
|
125
|
+
bueno g guard auth --module auth
|
|
126
|
+
|
|
127
|
+
# Generate a DTO for creating users
|
|
128
|
+
bueno g dto create-user --module users
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
---
|
|
132
|
+
|
|
133
|
+
#### `bueno migration <action>`
|
|
134
|
+
|
|
135
|
+
Manage database migrations.
|
|
136
|
+
|
|
137
|
+
**Usage:**
|
|
138
|
+
```bash
|
|
139
|
+
bueno migration create add-users-table
|
|
140
|
+
bueno migration up
|
|
141
|
+
bueno migration down
|
|
142
|
+
bueno migration status
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
**Actions:**
|
|
146
|
+
| Action | Description |
|
|
147
|
+
|--------|-------------|
|
|
148
|
+
| `create <name>` | Create a new migration file |
|
|
149
|
+
| `up` | Run pending migrations |
|
|
150
|
+
| `down` | Rollback last migration |
|
|
151
|
+
| `reset` | Rollback all migrations |
|
|
152
|
+
| `refresh` | Reset and re-run all migrations |
|
|
153
|
+
| `status` | Show migration status |
|
|
154
|
+
|
|
155
|
+
**Options:**
|
|
156
|
+
| Option | Alias | Default | Description |
|
|
157
|
+
|--------|-------|---------|-------------|
|
|
158
|
+
| `--steps` | `-n` | `1` | Number of migrations to rollback |
|
|
159
|
+
| `--dry-run` | | `false` | Show what would happen without executing |
|
|
160
|
+
| `--seed` | | `false` | Run seeds after migration |
|
|
161
|
+
|
|
162
|
+
**Examples:**
|
|
163
|
+
```bash
|
|
164
|
+
# Create a new migration
|
|
165
|
+
bueno migration create add-users-table
|
|
166
|
+
|
|
167
|
+
# Run all pending migrations
|
|
168
|
+
bueno migration up
|
|
169
|
+
|
|
170
|
+
# Rollback last 3 migrations
|
|
171
|
+
bueno migration down --steps 3
|
|
172
|
+
|
|
173
|
+
# Reset and re-run all migrations
|
|
174
|
+
bueno migration refresh
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
---
|
|
178
|
+
|
|
179
|
+
#### `bueno dev`
|
|
180
|
+
|
|
181
|
+
Start the development server with hot reload.
|
|
182
|
+
|
|
183
|
+
**Usage:**
|
|
184
|
+
```bash
|
|
185
|
+
bueno dev
|
|
186
|
+
bueno dev --port 4000
|
|
187
|
+
bueno dev --hmr
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
**Options:**
|
|
191
|
+
| Option | Alias | Default | Description |
|
|
192
|
+
|--------|-------|---------|-------------|
|
|
193
|
+
| `--port` | `-p` | `3000` | Server port |
|
|
194
|
+
| `--host` | `-H` | `localhost` | Server hostname |
|
|
195
|
+
| `--hmr` | | `true` | Enable hot module replacement |
|
|
196
|
+
| `--watch` | `-w` | `true` | Watch for file changes |
|
|
197
|
+
| `--console` | | `true` | Enable browser console streaming |
|
|
198
|
+
| `--open` | `-o` | `false` | Open browser on start |
|
|
199
|
+
| `--config` | `-c` | | Path to config file |
|
|
200
|
+
|
|
201
|
+
**Examples:**
|
|
202
|
+
```bash
|
|
203
|
+
# Start dev server on default port
|
|
204
|
+
bueno dev
|
|
205
|
+
|
|
206
|
+
# Start on port 4000 with custom config
|
|
207
|
+
bueno dev --port 4000 --config ./bueno.config.ts
|
|
208
|
+
|
|
209
|
+
# Start without HMR
|
|
210
|
+
bueno dev --no-hmr
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
---
|
|
214
|
+
|
|
215
|
+
#### `bueno build`
|
|
216
|
+
|
|
217
|
+
Build the application for production.
|
|
218
|
+
|
|
219
|
+
**Usage:**
|
|
220
|
+
```bash
|
|
221
|
+
bueno build
|
|
222
|
+
bueno build --target bun
|
|
223
|
+
bueno build --target node
|
|
224
|
+
```
|
|
225
|
+
|
|
226
|
+
**Options:**
|
|
227
|
+
| Option | Alias | Default | Description |
|
|
228
|
+
|--------|-------|---------|-------------|
|
|
229
|
+
| `--target` | `-t` | `bun` | Build target (bun, node, standalone) |
|
|
230
|
+
| `--outdir` | `-o` | `./dist` | Output directory |
|
|
231
|
+
| `--minify` | | `true` | Minify output |
|
|
232
|
+
| `--sourcemap` | | `false` | Generate source maps |
|
|
233
|
+
| `--analyze` | | `false` | Analyze bundle size |
|
|
234
|
+
| `--config` | `-c` | | Path to config file |
|
|
235
|
+
|
|
236
|
+
**Examples:**
|
|
237
|
+
```bash
|
|
238
|
+
# Build for Bun runtime
|
|
239
|
+
bueno build
|
|
240
|
+
|
|
241
|
+
# Build standalone executable
|
|
242
|
+
bueno build --target standalone
|
|
243
|
+
|
|
244
|
+
# Build with source maps
|
|
245
|
+
bueno build --sourcemap
|
|
246
|
+
```
|
|
247
|
+
|
|
248
|
+
---
|
|
249
|
+
|
|
250
|
+
#### `bueno start`
|
|
251
|
+
|
|
252
|
+
Start the production server.
|
|
253
|
+
|
|
254
|
+
**Usage:**
|
|
255
|
+
```bash
|
|
256
|
+
bueno start
|
|
257
|
+
bueno start --port 8080
|
|
258
|
+
```
|
|
259
|
+
|
|
260
|
+
**Options:**
|
|
261
|
+
| Option | Alias | Default | Description |
|
|
262
|
+
|--------|-------|---------|-------------|
|
|
263
|
+
| `--port` | `-p` | `3000` | Server port |
|
|
264
|
+
| `--host` | `-H` | `0.0.0.0` | Server hostname |
|
|
265
|
+
| `--workers` | `-w` | `auto` | Number of worker threads |
|
|
266
|
+
| `--config` | `-c` | | Path to config file |
|
|
267
|
+
|
|
268
|
+
---
|
|
269
|
+
|
|
270
|
+
### 2.3 Global Options
|
|
271
|
+
|
|
272
|
+
Available for all commands:
|
|
273
|
+
|
|
274
|
+
| Option | Description |
|
|
275
|
+
|--------|-------------|
|
|
276
|
+
| `--help` | Show help for command |
|
|
277
|
+
| `--version` | Show CLI version |
|
|
278
|
+
| `--verbose` | Enable verbose output |
|
|
279
|
+
| `--quiet` | Suppress non-essential output |
|
|
280
|
+
| `--no-color` | Disable colored output |
|
|
281
|
+
| `--config` | Path to config file |
|
|
282
|
+
|
|
283
|
+
---
|
|
284
|
+
|
|
285
|
+
## 3. File Organization
|
|
286
|
+
|
|
287
|
+
### 3.1 CLI Module Structure
|
|
288
|
+
|
|
289
|
+
```
|
|
290
|
+
src/cli/
|
|
291
|
+
├── index.ts # CLI entry point and command router
|
|
292
|
+
├── ARCHITECTURE.md # This document
|
|
293
|
+
│
|
|
294
|
+
├── commands/ # Command implementations
|
|
295
|
+
│ ├── index.ts # Command registry
|
|
296
|
+
│ ├── new.ts # Project scaffolding
|
|
297
|
+
│ ├── generate.ts # Code generation
|
|
298
|
+
│ ├── migration.ts # Migration management
|
|
299
|
+
│ ├── dev.ts # Development server
|
|
300
|
+
│ ├── build.ts # Production build
|
|
301
|
+
│ ├── start.ts # Production server
|
|
302
|
+
│ └── help.ts # Help display
|
|
303
|
+
│
|
|
304
|
+
├── core/ # Core CLI utilities
|
|
305
|
+
│ ├── args.ts # Argument parser
|
|
306
|
+
│ ├── console.ts # Console output utilities
|
|
307
|
+
│ ├── prompt.ts # Interactive prompts
|
|
308
|
+
│ ├── spinner.ts # Progress spinners
|
|
309
|
+
│ └── config.ts # CLI config loader
|
|
310
|
+
│
|
|
311
|
+
├── generators/ # Code generators
|
|
312
|
+
│ ├── index.ts # Generator registry
|
|
313
|
+
│ ├── controller.ts # Controller generator
|
|
314
|
+
│ ├── service.ts # Service generator
|
|
315
|
+
│ ├── module.ts # Module generator
|
|
316
|
+
│ ├── guard.ts # Guard generator
|
|
317
|
+
│ ├── interceptor.ts # Interceptor generator
|
|
318
|
+
│ ├── pipe.ts # Pipe generator
|
|
319
|
+
│ ├── filter.ts # Filter generator
|
|
320
|
+
│ ├── dto.ts # DTO generator
|
|
321
|
+
│ ├── middleware.ts # Middleware generator
|
|
322
|
+
│ └── migration.ts # Migration generator
|
|
323
|
+
│
|
|
324
|
+
└── utils/ # Utility functions
|
|
325
|
+
├── fs.ts # File system utilities
|
|
326
|
+
├── strings.ts # String manipulation
|
|
327
|
+
├── paths.ts # Path utilities
|
|
328
|
+
└── validation.ts # Input validation
|
|
329
|
+
```
|
|
330
|
+
|
|
331
|
+
### 3.2 Generated Project Structure
|
|
332
|
+
|
|
333
|
+
When running `bueno new <project>`, the following structure is created:
|
|
334
|
+
|
|
335
|
+
```
|
|
336
|
+
my-app/
|
|
337
|
+
├── server/
|
|
338
|
+
│ ├── main.ts # Application entry point
|
|
339
|
+
│ ├── app.module.ts # Root module
|
|
340
|
+
│ │
|
|
341
|
+
│ ├── modules/ # Feature modules
|
|
342
|
+
│ │ └── app/
|
|
343
|
+
│ │ ├── app.module.ts
|
|
344
|
+
│ │ ├── app.controller.ts
|
|
345
|
+
│ │ └── app.service.ts
|
|
346
|
+
│ │
|
|
347
|
+
│ ├── common/ # Shared utilities
|
|
348
|
+
│ │ ├── middleware/
|
|
349
|
+
│ │ ├── decorators/
|
|
350
|
+
│ │ ├── filters/
|
|
351
|
+
│ │ ├── guards/
|
|
352
|
+
│ │ ├── interceptors/
|
|
353
|
+
│ │ └── pipes/
|
|
354
|
+
│ │
|
|
355
|
+
│ ├── config/ # Configuration
|
|
356
|
+
│ │ └── database.config.ts
|
|
357
|
+
│ │
|
|
358
|
+
│ └── database/ # Database assets
|
|
359
|
+
│ ├── migrations/
|
|
360
|
+
│ └── seeds/
|
|
361
|
+
│
|
|
362
|
+
├── client/ # Frontend (if applicable)
|
|
363
|
+
│ ├── index.html
|
|
364
|
+
│ └── src/
|
|
365
|
+
│ ├── main.tsx
|
|
366
|
+
│ └── components/
|
|
367
|
+
│
|
|
368
|
+
├── tests/ # Test files
|
|
369
|
+
│ ├── unit/
|
|
370
|
+
│ └── integration/
|
|
371
|
+
│
|
|
372
|
+
├── bueno.config.ts # Framework configuration
|
|
373
|
+
├── package.json
|
|
374
|
+
├── tsconfig.json
|
|
375
|
+
└── .env.example
|
|
376
|
+
```
|
|
377
|
+
|
|
378
|
+
---
|
|
379
|
+
|
|
380
|
+
## 4. Template System
|
|
381
|
+
|
|
382
|
+
### 4.1 Dynamic Template Generation
|
|
383
|
+
|
|
384
|
+
The CLI uses a dynamic template generation approach via TypeScript functions in [`commands/new.ts`](src/cli/commands/new.ts). Instead of static template files, templates are generated programmatically at runtime, providing several advantages:
|
|
385
|
+
|
|
386
|
+
- **No external files to maintain**: All templates are self-contained in the codebase
|
|
387
|
+
- **Type-safe**: Templates benefit from TypeScript type checking
|
|
388
|
+
- **Easier version control**: Templates are part of the source code, not separate files
|
|
389
|
+
- **Dynamic customization**: Templates can adapt based on project configuration
|
|
390
|
+
- **Simpler debugging**: Template code is regular TypeScript with full IDE support
|
|
391
|
+
|
|
392
|
+
### 4.2 Template Functions
|
|
393
|
+
|
|
394
|
+
The following functions in [`commands/new.ts`](src/cli/commands/new.ts) generate project files:
|
|
395
|
+
|
|
396
|
+
| Function | File Generated | Purpose |
|
|
397
|
+
|----------|---------------|---------|
|
|
398
|
+
| [`getPackageJsonTemplate()`](src/cli/commands/new.ts:75) | `package.json` | Generates npm package configuration with dependencies based on template type |
|
|
399
|
+
| [`getTsConfigTemplate()`](src/cli/commands/new.ts:117) | `tsconfig.json` | Generates TypeScript configuration |
|
|
400
|
+
| [`getMainTemplate()`](src/cli/commands/new.ts:144) | `server/main.ts` | Generates application entry point with controller/service/module based on template |
|
|
401
|
+
| [`getConfigTemplate()`](src/cli/commands/new.ts:201) | `bueno.config.ts` | Generates framework configuration with database settings |
|
|
402
|
+
| [`getEnvExampleTemplate()`](src/cli/commands/new.ts:233) | `.env.example` | Generates environment variable template |
|
|
403
|
+
| [`getGitignoreTemplate()`](src/cli/commands/new.ts:249) | `.gitignore` | Generates git ignore patterns |
|
|
404
|
+
| [`getReadmeTemplate()`](src/cli/commands/new.ts:288) | `README.md` | Generates project documentation |
|
|
405
|
+
|
|
406
|
+
### 4.3 Template Types
|
|
407
|
+
|
|
408
|
+
The CLI supports four project templates, selected via `--template` or `-t` option:
|
|
409
|
+
|
|
410
|
+
| Template | Description | Features |
|
|
411
|
+
|----------|-------------|----------|
|
|
412
|
+
| `default` | Standard project with modules, database, and basic frontend | Controllers, Services, Modules, Database config, Zod |
|
|
413
|
+
| `minimal` | Bare minimum project structure | Simple server with router, no decorators |
|
|
414
|
+
| `fullstack` | Full-stack project with SSR and frontend | Full framework features with frontend integration |
|
|
415
|
+
| `api` | API-only project without frontend | Controllers, Services, Database, no frontend |
|
|
416
|
+
|
|
417
|
+
### 4.4 Template Customization
|
|
418
|
+
|
|
419
|
+
Templates adapt based on the project configuration:
|
|
420
|
+
|
|
421
|
+
- **Database selection**: Template functions check `config.database` to include appropriate connection strings
|
|
422
|
+
- **Template type**: Different code is generated for `minimal` vs full framework projects
|
|
423
|
+
- **Project name**: All templates use the project name for package.json, README, etc.
|
|
424
|
+
|
|
425
|
+
Example from [`getMainTemplate()`](src/cli/commands/new.ts:144):
|
|
426
|
+
```typescript
|
|
427
|
+
function getMainTemplate(config: ProjectConfig): string {
|
|
428
|
+
if (config.template === 'minimal') {
|
|
429
|
+
// Simple router-based approach
|
|
430
|
+
return `import { createServer } from 'bueno';
|
|
431
|
+
const app = createServer();
|
|
432
|
+
app.router.get('/', () => {
|
|
433
|
+
return { message: 'Hello, Bueno!' };
|
|
434
|
+
});
|
|
435
|
+
await app.listen(3000);`;
|
|
436
|
+
}
|
|
437
|
+
// Full framework approach with decorators
|
|
438
|
+
return `import { createApp, Module, Controller, Get, Injectable } from 'bueno';
|
|
439
|
+
// ... full module structure with @Controller, @Injectable, etc.
|
|
440
|
+
await createApp(AppModule).listen(3000);`;
|
|
441
|
+
}
|
|
442
|
+
```
|
|
443
|
+
|
|
444
|
+
### 4.5 Future: Static Template Support
|
|
445
|
+
|
|
446
|
+
The architecture allows for future expansion to support static template files if needed. The current dynamic approach can coexist with file-based templates for custom user templates.
|
|
447
|
+
|
|
448
|
+
---
|
|
449
|
+
|
|
450
|
+
## 5. Integration Points
|
|
451
|
+
|
|
452
|
+
### 5.1 Module System Integration
|
|
453
|
+
|
|
454
|
+
The CLI integrates with the existing module system:
|
|
455
|
+
|
|
456
|
+
**Module Registration:**
|
|
457
|
+
When generating a controller or service, the CLI:
|
|
458
|
+
1. Reads the target module file
|
|
459
|
+
2. Parses the `@Module()` decorator metadata
|
|
460
|
+
3. Adds the new controller/service to the appropriate array
|
|
461
|
+
4. Preserves formatting and imports
|
|
462
|
+
|
|
463
|
+
**Example - Adding Controller to Module:**
|
|
464
|
+
```typescript
|
|
465
|
+
// Before
|
|
466
|
+
@Module({
|
|
467
|
+
controllers: [UsersController],
|
|
468
|
+
providers: [UsersService],
|
|
469
|
+
})
|
|
470
|
+
export class UsersModule {}
|
|
471
|
+
|
|
472
|
+
// After running: bueno g controller posts --module users
|
|
473
|
+
@Module({
|
|
474
|
+
controllers: [UsersController, PostsController],
|
|
475
|
+
providers: [UsersService],
|
|
476
|
+
})
|
|
477
|
+
export class UsersModule {}
|
|
478
|
+
```
|
|
479
|
+
|
|
480
|
+
### 5.2 Database Integration
|
|
481
|
+
|
|
482
|
+
**Migration System:**
|
|
483
|
+
- Uses existing [`MigrationRunner`](src/database/migrations/index.ts:38) class
|
|
484
|
+
- Generates migration files with proper naming convention
|
|
485
|
+
- Integrates with [`generateMigrationId()`](src/database/migrations/index.ts:361)
|
|
486
|
+
|
|
487
|
+
**Migration File Template:**
|
|
488
|
+
```typescript
|
|
489
|
+
import { createMigration, type MigrationRunner } from 'bueno';
|
|
490
|
+
|
|
491
|
+
export default createMigration('{{migrationId}}', '{{migrationName}}')
|
|
492
|
+
.up(async (db: MigrationRunner) => {
|
|
493
|
+
// TODO: Add migration logic
|
|
494
|
+
await db.createTable({
|
|
495
|
+
name: '{{tableName}}',
|
|
496
|
+
columns: [
|
|
497
|
+
// Define columns
|
|
498
|
+
],
|
|
499
|
+
});
|
|
500
|
+
})
|
|
501
|
+
.down(async (db: MigrationRunner) => {
|
|
502
|
+
// TODO: Add rollback logic
|
|
503
|
+
await db.dropTable('{{tableName}}');
|
|
504
|
+
});
|
|
505
|
+
```
|
|
506
|
+
|
|
507
|
+
### 5.3 Configuration Integration
|
|
508
|
+
|
|
509
|
+
**Config Loading:**
|
|
510
|
+
- Reads [`bueno.config.ts`](src/config/index.ts) for default values
|
|
511
|
+
- CLI options override config file values
|
|
512
|
+
- Environment variables are respected
|
|
513
|
+
|
|
514
|
+
**Config Schema Extension:**
|
|
515
|
+
```typescript
|
|
516
|
+
// bueno.config.ts
|
|
517
|
+
export default defineConfig({
|
|
518
|
+
cli: {
|
|
519
|
+
// CLI-specific configuration
|
|
520
|
+
templatesDir: '.bueno/templates',
|
|
521
|
+
defaultModule: 'app',
|
|
522
|
+
generate: {
|
|
523
|
+
spec: true, // Generate test files
|
|
524
|
+
flat: false, // Use flat structure
|
|
525
|
+
},
|
|
526
|
+
},
|
|
527
|
+
|
|
528
|
+
// Existing config
|
|
529
|
+
server: { port: 3000 },
|
|
530
|
+
database: { url: process.env.DATABASE_URL },
|
|
531
|
+
});
|
|
532
|
+
```
|
|
533
|
+
|
|
534
|
+
### 5.4 Development Server Integration
|
|
535
|
+
|
|
536
|
+
**Dev Command Integration:**
|
|
537
|
+
- Uses existing [`DevServer`](src/frontend/dev-server.ts:142) class
|
|
538
|
+
- Integrates with [`HMRManager`](src/frontend/dev-server.ts:151)
|
|
539
|
+
- Supports [`ConsoleStreamManager`](src/frontend/dev-server.ts:152)
|
|
540
|
+
|
|
541
|
+
### 5.5 Logger Integration
|
|
542
|
+
|
|
543
|
+
Uses the existing [`Logger`](src/logger/index.ts) system for consistent output:
|
|
544
|
+
|
|
545
|
+
```typescript
|
|
546
|
+
import { createLogger } from '../logger';
|
|
547
|
+
|
|
548
|
+
const logger = createLogger({
|
|
549
|
+
level: 'debug',
|
|
550
|
+
pretty: true,
|
|
551
|
+
context: { component: 'CLI' },
|
|
552
|
+
});
|
|
553
|
+
```
|
|
554
|
+
|
|
555
|
+
---
|
|
556
|
+
|
|
557
|
+
## 6. Implementation Approach
|
|
558
|
+
|
|
559
|
+
### 6.1 Phase 1: Core Infrastructure
|
|
560
|
+
|
|
561
|
+
1. **Argument Parser** (`core/args.ts`)
|
|
562
|
+
- Parse command line arguments using `process.argv`
|
|
563
|
+
- Support for positional arguments, flags, and options
|
|
564
|
+
- Auto-generate help text from command definitions
|
|
565
|
+
|
|
566
|
+
2. **Console Utilities** (`core/console.ts`)
|
|
567
|
+
- Colored output using ANSI codes
|
|
568
|
+
- Formatted tables, lists, and trees
|
|
569
|
+
- Progress indicators and spinners
|
|
570
|
+
|
|
571
|
+
3. **Interactive Prompts** (`core/prompt.ts`)
|
|
572
|
+
- Text input, confirm, select, multi-select
|
|
573
|
+
- Validation and default values
|
|
574
|
+
- Graceful fallback for non-TTY environments
|
|
575
|
+
|
|
576
|
+
### 6.2 Phase 2: Scaffolding
|
|
577
|
+
|
|
578
|
+
1. **Dynamic Template Functions** (`commands/new.ts`)
|
|
579
|
+
- Template functions generate project files programmatically
|
|
580
|
+
- Supports 4 template types: default, minimal, fullstack, api
|
|
581
|
+
- Templates adapt based on project configuration (database, framework)
|
|
582
|
+
- Post-generation hooks (bun install, git init)
|
|
583
|
+
|
|
584
|
+
2. **New Command** (`commands/new.ts`)
|
|
585
|
+
- Interactive project creation with prompts
|
|
586
|
+
- Template selection and customization
|
|
587
|
+
- Project validation and directory creation
|
|
588
|
+
- Dependency installation using `bun install`
|
|
589
|
+
|
|
590
|
+
### 6.3 Phase 3: Code Generation
|
|
591
|
+
|
|
592
|
+
1. **Generator Base Class** (`generators/index.ts`)
|
|
593
|
+
- Abstract base for all generators
|
|
594
|
+
- Template rendering and file writing
|
|
595
|
+
- Module registration logic
|
|
596
|
+
|
|
597
|
+
2. **Individual Generators** (`generators/*.ts`)
|
|
598
|
+
- Controller, Service, Module generators
|
|
599
|
+
- Guard, Interceptor, Pipe, Filter generators
|
|
600
|
+
- DTO and Middleware generators
|
|
601
|
+
|
|
602
|
+
3. **Generate Command** (`commands/generate.ts`)
|
|
603
|
+
- Parse generator type and name
|
|
604
|
+
- Resolve options and execute generator
|
|
605
|
+
- Output created files summary
|
|
606
|
+
|
|
607
|
+
### 6.4 Phase 4: Migration Commands
|
|
608
|
+
|
|
609
|
+
1. **Migration Generator** (`generators/migration.ts`)
|
|
610
|
+
- Create migration files with timestamp IDs
|
|
611
|
+
- Template for up/down methods
|
|
612
|
+
|
|
613
|
+
2. **Migration Command** (`commands/migration.ts`)
|
|
614
|
+
- Execute migrations using existing `MigrationRunner`
|
|
615
|
+
- Status display and rollback support
|
|
616
|
+
|
|
617
|
+
### 6.5 Phase 5: Dev/Build/Start
|
|
618
|
+
|
|
619
|
+
1. **Dev Command** (`commands/dev.ts`)
|
|
620
|
+
- Start `DevServer` with options
|
|
621
|
+
- File watching and restart logic
|
|
622
|
+
- Integration with HMR and console streaming
|
|
623
|
+
|
|
624
|
+
2. **Build Command** (`commands/build.ts`)
|
|
625
|
+
- Use `bun build` with configuration
|
|
626
|
+
- Target-specific builds (bun, node, standalone)
|
|
627
|
+
- Bundle analysis and optimization
|
|
628
|
+
|
|
629
|
+
3. **Start Command** (`commands/start.ts`)
|
|
630
|
+
- Production server startup
|
|
631
|
+
- Worker thread management
|
|
632
|
+
- Graceful shutdown handling
|
|
633
|
+
|
|
634
|
+
---
|
|
635
|
+
|
|
636
|
+
## 7. CLI Flow Diagrams
|
|
637
|
+
|
|
638
|
+
### 7.1 Command Execution Flow
|
|
639
|
+
|
|
640
|
+
```mermaid
|
|
641
|
+
flowchart TD
|
|
642
|
+
A[CLI Entry] --> B[Parse Arguments]
|
|
643
|
+
B --> C{Command Found?}
|
|
644
|
+
C -->|No| D[Show Help]
|
|
645
|
+
C -->|Yes| E[Load Config]
|
|
646
|
+
E --> F[Execute Command]
|
|
647
|
+
F --> G{Success?}
|
|
648
|
+
G -->|Yes| H[Exit 0]
|
|
649
|
+
G -->|No| I[Show Error]
|
|
650
|
+
I --> J[Exit 1]
|
|
651
|
+
```
|
|
652
|
+
|
|
653
|
+
### 7.2 Project Scaffolding Flow
|
|
654
|
+
|
|
655
|
+
```mermaid
|
|
656
|
+
flowchart TD
|
|
657
|
+
A[bueno new my-app] --> B{Options Provided?}
|
|
658
|
+
B -->|No| C[Interactive Prompts]
|
|
659
|
+
B -->|Yes| D[Validate Options]
|
|
660
|
+
C --> D
|
|
661
|
+
D --> E[Select Template]
|
|
662
|
+
E --> F[Create Directory Structure]
|
|
663
|
+
F --> G[Render Templates]
|
|
664
|
+
G --> H{Skip Install?}
|
|
665
|
+
H -->|No| I[bun install]
|
|
666
|
+
H -->|Yes| J{Skip Git?}
|
|
667
|
+
I --> J
|
|
668
|
+
J -->|No| K[git init]
|
|
669
|
+
J -->|Yes| L[Done]
|
|
670
|
+
K --> L
|
|
671
|
+
```
|
|
672
|
+
|
|
673
|
+
### 7.3 Code Generation Flow
|
|
674
|
+
|
|
675
|
+
```mermaid
|
|
676
|
+
flowchart TD
|
|
677
|
+
A[bueno generate controller users] --> B[Parse Type and Name]
|
|
678
|
+
B --> C[Resolve Target Path]
|
|
679
|
+
C --> D{File Exists?}
|
|
680
|
+
D -->|Yes| E{Force Flag?}
|
|
681
|
+
E -->|No| F[Error: File Exists]
|
|
682
|
+
E -->|Yes| G[Load Template]
|
|
683
|
+
D -->|No| G
|
|
684
|
+
G --> H[Render Template]
|
|
685
|
+
H --> I[Write File]
|
|
686
|
+
I --> J{Module Specified?}
|
|
687
|
+
J -->|Yes| K[Update Module]
|
|
688
|
+
J -->|No| L[Done]
|
|
689
|
+
K --> L
|
|
690
|
+
```
|
|
691
|
+
|
|
692
|
+
### 7.4 Migration Flow
|
|
693
|
+
|
|
694
|
+
```mermaid
|
|
695
|
+
flowchart TD
|
|
696
|
+
A[bueno migration up] --> B[Load Config]
|
|
697
|
+
B --> C[Connect to Database]
|
|
698
|
+
C --> D[Get Pending Migrations]
|
|
699
|
+
D --> E{Pending Migrations?}
|
|
700
|
+
E -->|No| F[Nothing to Migrate]
|
|
701
|
+
E -->|Yes| G[For Each Migration]
|
|
702
|
+
G --> H[Begin Transaction]
|
|
703
|
+
H --> I[Execute Up Method]
|
|
704
|
+
I --> J{Success?}
|
|
705
|
+
J -->|Yes| K[Record Migration]
|
|
706
|
+
J -->|No| L[Rollback Transaction]
|
|
707
|
+
K --> M[Commit Transaction]
|
|
708
|
+
M --> N{More Migrations?}
|
|
709
|
+
N -->|Yes| G
|
|
710
|
+
N -->|No| O[Done]
|
|
711
|
+
L --> P[Error]
|
|
712
|
+
F --> O
|
|
713
|
+
```
|
|
714
|
+
|
|
715
|
+
---
|
|
716
|
+
|
|
717
|
+
## 8. Error Handling
|
|
718
|
+
|
|
719
|
+
### 8.1 Error Types
|
|
720
|
+
|
|
721
|
+
```typescript
|
|
722
|
+
// Error categories
|
|
723
|
+
enum CLIErrorType {
|
|
724
|
+
INVALID_ARGS = 'INVALID_ARGS',
|
|
725
|
+
FILE_EXISTS = 'FILE_EXISTS',
|
|
726
|
+
FILE_NOT_FOUND = 'FILE_NOT_FOUND',
|
|
727
|
+
MODULE_NOT_FOUND = 'MODULE_NOT_FOUND',
|
|
728
|
+
TEMPLATE_ERROR = 'TEMPLATE_ERROR',
|
|
729
|
+
DATABASE_ERROR = 'DATABASE_ERROR',
|
|
730
|
+
NETWORK_ERROR = 'NETWORK_ERROR',
|
|
731
|
+
PERMISSION_ERROR = 'PERMISSION_ERROR',
|
|
732
|
+
}
|
|
733
|
+
```
|
|
734
|
+
|
|
735
|
+
### 8.2 Error Display
|
|
736
|
+
|
|
737
|
+
- Clear, actionable error messages
|
|
738
|
+
- Suggested fixes when possible
|
|
739
|
+
- Stack traces only in verbose mode
|
|
740
|
+
- Color-coded severity (red for errors, yellow for warnings)
|
|
741
|
+
|
|
742
|
+
---
|
|
743
|
+
|
|
744
|
+
## 9. Testing Strategy
|
|
745
|
+
|
|
746
|
+
### 9.1 Unit Tests
|
|
747
|
+
|
|
748
|
+
- Test each command in isolation
|
|
749
|
+
- Mock file system operations
|
|
750
|
+
- Template rendering tests
|
|
751
|
+
- Argument parsing tests
|
|
752
|
+
|
|
753
|
+
### 9.2 Integration Tests
|
|
754
|
+
|
|
755
|
+
- End-to-end command execution
|
|
756
|
+
- Generated file validation
|
|
757
|
+
- Module registration verification
|
|
758
|
+
|
|
759
|
+
### 9.3 Test Utilities
|
|
760
|
+
|
|
761
|
+
```typescript
|
|
762
|
+
// Test helper for CLI commands
|
|
763
|
+
async function runCommand(args: string[]): Promise<{
|
|
764
|
+
exitCode: number;
|
|
765
|
+
stdout: string;
|
|
766
|
+
stderr: string;
|
|
767
|
+
files: Map<string, string>;
|
|
768
|
+
}>
|
|
769
|
+
```
|
|
770
|
+
|
|
771
|
+
---
|
|
772
|
+
|
|
773
|
+
## 10. Future Enhancements
|
|
774
|
+
|
|
775
|
+
### 10.1 Planned Features
|
|
776
|
+
|
|
777
|
+
- **Plugin System**: Allow third-party CLI extensions
|
|
778
|
+
- **Interactive Mode**: Full TUI for project management
|
|
779
|
+
- **Update Checker**: Notify when new version available
|
|
780
|
+
- **Telemetry**: Optional usage analytics
|
|
781
|
+
- **Autocomplete**: Shell completion for commands
|
|
782
|
+
|
|
783
|
+
### 10.2 Potential Extensions
|
|
784
|
+
|
|
785
|
+
- `bueno addon <action>` - Manage addons/plugins
|
|
786
|
+
- `bueno info` - Show project diagnostics
|
|
787
|
+
- `bueno update` - Update framework version
|
|
788
|
+
- `bueno deploy` - Deployment helpers
|
|
789
|
+
|
|
790
|
+
---
|
|
791
|
+
|
|
792
|
+
## 11. Appendix
|
|
793
|
+
|
|
794
|
+
### 11.1 Exit Codes
|
|
795
|
+
|
|
796
|
+
| Code | Meaning |
|
|
797
|
+
|------|---------|
|
|
798
|
+
| 0 | Success |
|
|
799
|
+
| 1 | General error |
|
|
800
|
+
| 2 | Invalid arguments |
|
|
801
|
+
| 3 | File system error |
|
|
802
|
+
| 4 | Database error |
|
|
803
|
+
| 5 | Network error |
|
|
804
|
+
| 130 | Interrupted (Ctrl+C) |
|
|
805
|
+
|
|
806
|
+
### 11.2 Environment Variables
|
|
807
|
+
|
|
808
|
+
| Variable | Description |
|
|
809
|
+
|----------|-------------|
|
|
810
|
+
| `BUENO_CONFIG` | Path to config file |
|
|
811
|
+
| `BUENO_NO_COLOR` | Disable colored output |
|
|
812
|
+
| `BUENO_VERBOSE` | Enable verbose output |
|
|
813
|
+
| `BUENO_TEMPLATES_DIR` | Custom templates directory |
|
|
814
|
+
|
|
815
|
+
### 11.3 Configuration Schema
|
|
816
|
+
|
|
817
|
+
```typescript
|
|
818
|
+
interface BuenoCLIConfig {
|
|
819
|
+
templatesDir?: string;
|
|
820
|
+
defaultModule?: string;
|
|
821
|
+
generate?: {
|
|
822
|
+
spec?: boolean;
|
|
823
|
+
flat?: boolean;
|
|
824
|
+
path?: string;
|
|
825
|
+
};
|
|
826
|
+
migration?: {
|
|
827
|
+
dir?: string;
|
|
828
|
+
table?: string;
|
|
829
|
+
};
|
|
830
|
+
}
|
|
831
|
+
```
|
|
832
|
+
|
|
833
|
+
---
|
|
834
|
+
|
|
835
|
+
## Conclusion
|
|
836
|
+
|
|
837
|
+
This CLI architecture provides a comprehensive, Bun-native solution for Bueno framework development. By leveraging Bun's built-in capabilities and integrating deeply with the existing module system, the CLI delivers a seamless developer experience while maintaining the framework's core principles of performance, type safety, and zero configuration.
|