blockend-cli 2.1.0 → 2.2.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/README.md CHANGED
@@ -1,704 +1,197 @@
1
1
  # Blockend CLI
2
2
 
3
- > **shadcn/ui for your backend.**
3
+ The Blockend CLI writes backend source blocks into a TypeScript project. It detects your framework, copies the selected files, installs missing packages, and records installed versions for updates.
4
4
 
5
- Generate production-ready TypeScript backend blocks — rate limiting, validation, logging, error handling, configuration, health checks, and more — directly into your project from the terminal.
5
+ ## Quick start
6
6
 
7
- **You own the code.**
8
-
9
- Blockend detects your framework, then copies audited, fully typed infrastructure source files directly into your repository. No runtime wrapper. No black box in `node_modules`. No lock-in.
10
-
11
- ---
12
-
13
- ## Quick Start
14
-
15
- In any TypeScript backend project:
7
+ From your project root:
16
8
 
17
9
  ```bash
18
10
  npx blockend-cli init
19
11
  npx blockend-cli add rate-limiter
20
12
  ```
21
13
 
22
- `init` detects your framework and creates a `blockend.json` configuration.
23
-
24
- `add` copies the selected block into your project.
25
-
26
- For example:
27
-
28
- ```text
29
- src/
30
- └── blocks/
31
- └── rate-limiter/
32
- ├── core.ts
33
- ├── express.ts
34
- └── ...
35
- ```
36
-
37
- Open the files. Read them. Edit them. Commit them.
38
-
39
- They're yours.
40
-
41
- Blockend does not run inside your application and does not lock your project into a runtime dependency.
42
-
43
- ---
44
-
45
- ## Why Blockend?
46
-
47
- Backend infrastructure is repetitive, but it still needs to be reliable, typed, and easy to customize.
14
+ `init` creates `blockend.json`. `add` writes the block under the configured blocks directory.
48
15
 
49
- Blockend gives you production-ready infrastructure as source code:
50
-
51
- - Rate limiting
52
- - Request validation
53
- - Error handling
54
- - Structured logging
55
- - API response formatting
56
- - Environment configuration
57
- - Health checks
58
- - Password hashing
59
-
60
- Instead of installing another backend framework or runtime abstraction, Blockend generates the implementation directly into your repository.
61
-
62
- ---
63
-
64
- ## Installation
65
-
66
- You don't need to install Blockend globally.
67
-
68
- Run it directly with your package manager:
69
-
70
- ```bash
71
- npx blockend-cli init
72
- ```
73
-
74
- Or:
16
+ You can also run the CLI with other package runners:
75
17
 
76
18
  ```bash
77
19
  pnpm dlx blockend-cli init
78
- ```
79
-
80
- ```bash
81
20
  yarn dlx blockend-cli init
82
- ```
83
-
84
- ```bash
85
21
  bunx blockend-cli init
86
22
  ```
87
23
 
88
- ---
24
+ ## Requirements
89
25
 
90
- # Commands
26
+ - Node.js 20 or newer
27
+ - A TypeScript project for `add`
28
+ - Express, Fastify, Next.js App Router, or Hono
29
+ - Network access to GitHub for registry commands
91
30
 
92
- ## `init`
31
+ The `add` command rejects JavaScript projects.
93
32
 
94
- Detect your framework and initialize Blockend.
33
+ ## Commands
95
34
 
96
- ```bash
97
- npx blockend-cli init
98
- ```
99
-
100
- This creates:
101
-
102
- ```text
103
- blockend.json
104
- ```
105
-
106
- Blockend uses your project structure and detected framework to determine how blocks should be generated.
107
-
108
- ### Skip prompts
35
+ ### `init`
109
36
 
110
37
  ```bash
111
- npx blockend-cli init --yes
38
+ npx blockend-cli init [--yes] [--json]
112
39
  ```
113
40
 
114
- or:
41
+ Detects the framework, language, package manager, Redis, and import alias, then writes `blockend.json`.
115
42
 
116
- ```bash
117
- npx blockend-cli init -y
118
- ```
43
+ `--yes` accepts detected defaults and overwrites an existing config without prompting. If no framework is detected, it uses Express.
119
44
 
120
- ### JSON output
45
+ ### `add`
121
46
 
122
47
  ```bash
123
- npx blockend-cli init --json
48
+ npx blockend-cli add [block] [options]
124
49
  ```
125
50
 
126
- ---
127
-
128
- ## `add`
129
-
130
- Generate a specific backend block into your project.
131
-
132
- ```bash
133
- npx blockend-cli add rate-limiter
134
- ```
51
+ | Option | Alias | Description |
52
+ | ---------- | ----- | ------------------------------------------------------------ |
53
+ | `[block]` | | Registry key, such as `rate-limiter` or `logger`. |
54
+ | `--yes` | `-y` | Skip prompts, install dependencies, and overwrite conflicts. |
55
+ | `--json` | | Write machine-readable output. |
56
+ | `--multi` | `-m` | Select multiple blocks. |
57
+ | `--recipe` | | Add every block in a published recipe, in integration order. |
135
58
 
136
- Other examples:
59
+ Without a block name, the CLI opens a selector. For blocks with storage options, it asks for a variant. In interactive mode, `includeRedis: true` selects the Redis variant when one exists. With `--yes`, it selects memory when available, otherwise the first variant.
137
60
 
138
- ```bash
139
- npx blockend-cli add request-validator
140
- ```
61
+ `add --yes` without a block name is an error.
141
62
 
142
- ```bash
143
- npx blockend-cli add error-handler
144
- ```
63
+ `--recipe` installs a curated, ordered stack from the registry in one command:
145
64
 
146
65
  ```bash
147
- npx blockend-cli add logger
66
+ npx blockend-cli add --recipe authenticated-api
148
67
  ```
149
68
 
150
- ### Interactive mode
69
+ It installs the recipe's required blocks in integration order. Optional blocks are offered interactively and skipped with `--yes` or `--json`. `--recipe` cannot be combined with `--multi` or a positional block name.
151
70
 
152
- Run `add` without specifying a block:
71
+ Dependency installation runs `pnpm add` when `packageManager` is `pnpm`, and `npm install` for every other value. Yarn and bun projects should decline the install prompt and add the listed packages themselves.
153
72
 
154
- ```bash
155
- npx blockend-cli add
156
- ```
157
-
158
- Blockend will display compatible blocks and let you choose one interactively.
159
-
160
- ### Add multiple blocks
73
+ ### `list`
161
74
 
162
75
  ```bash
163
- npx blockend-cli add --multi
76
+ npx blockend-cli list [--json] [--recipes]
164
77
  ```
165
78
 
166
- or:
79
+ Lists blocks compatible with the framework in `blockend.json`. With `--recipes`, it lists published recipes instead and does not require `blockend.json`.
167
80
 
168
- ```bash
169
- npx blockend-cli add -m
170
- ```
171
-
172
- ### Skip confirmation
81
+ ### `detect`
173
82
 
174
83
  ```bash
175
- npx blockend-cli add rate-limiter --yes
84
+ npx blockend-cli detect [--json]
176
85
  ```
177
86
 
178
- or:
179
-
180
- ```bash
181
- npx blockend-cli add rate-limiter -y
182
- ```
87
+ Reports framework, language, package manager, source directory, import rewrite strategy, and detected Redis, Prisma, and Drizzle usage. It does not require `blockend.json`.
183
88
 
184
- ### JSON output
89
+ ### `diff`
185
90
 
186
91
  ```bash
187
- npx blockend-cli add rate-limiter --json
92
+ npx blockend-cli diff <block> [--json]
188
93
  ```
189
94
 
190
- This is useful for automation and CI environments.
191
-
192
- ---
193
-
194
- ## `list`
195
-
196
- List all available backend blocks.
197
-
198
- ```bash
199
- npx blockend-cli list
200
- ```
201
-
202
- Example:
203
-
204
- ```text
205
- Available Blocks
206
-
207
- rate-limiter
208
- request-validator
209
- error-handler
210
- logger
211
- response-formatter
212
- env-config
213
- health-check
214
- password-hash
215
- ```
216
-
217
- ### JSON output
218
-
219
- ```bash
220
- npx blockend-cli list --json
221
- ```
222
-
223
- ---
224
-
225
- ## `detect`
226
-
227
- Detect information about your current project.
228
-
229
- ```bash
230
- npx blockend-cli detect
231
- ```
232
-
233
- Blockend can inspect:
234
-
235
- - Framework
236
- - Package manager
237
- - TypeScript configuration
238
- - Project structure
239
- - Workspace configuration
240
- - Runtime environment
241
- - Relevant project directories
242
-
243
- ### JSON output
244
-
245
- ```bash
246
- npx blockend-cli detect --json
247
- ```
248
-
249
- ---
250
-
251
- ## `diff`
252
-
253
- Preview the files that a block would generate without modifying your project.
254
-
255
- ```bash
256
- npx blockend-cli diff rate-limiter
257
- ```
258
-
259
- This lets you inspect changes before adding a block.
260
-
261
- ### JSON output
262
-
263
- ```bash
264
- npx blockend-cli diff rate-limiter --json
265
- ```
266
-
267
- ---
268
-
269
- ## `doctor`
270
-
271
- Diagnose Blockend configuration and project issues.
272
-
273
- ```bash
274
- npx blockend-cli doctor
275
- ```
276
-
277
- Blockend checks your project for problems such as:
278
-
279
- - Missing `blockend.json`
280
- - Unsupported or undetected frameworks
281
- - Invalid configuration
282
- - Missing dependencies
283
- - Invalid generated block layouts
284
- - Project integration issues
285
-
286
- ### JSON output
287
-
288
- ```bash
289
- npx blockend-cli doctor --json
290
- ```
291
-
292
- ---
293
-
294
- ## `update`
295
-
296
- Check installed blocks for newer versions.
297
-
298
- ```bash
299
- npx blockend-cli update
300
- ```
301
-
302
- Blockend compares your installed blocks with newer available versions and shows their differences.
303
-
304
- ### Apply updates
305
-
306
- ```bash
307
- npx blockend-cli update --apply
308
- ```
309
-
310
- Blockend will let you select which blocks to update.
311
-
312
- ### JSON output
313
-
314
- ```bash
315
- npx blockend-cli update --json
316
- ```
317
-
318
- ### Disable diff output
319
-
320
- ```bash
321
- npx blockend-cli update --no-diff
322
- ```
323
-
324
- ---
325
-
326
- # MCP Integration
95
+ Shows which files a block would add, modify, or leave unchanged. It does not write to disk.
327
96
 
328
- Blockend ships with an MCP server so AI assistants can use vetted, framework-native backend blocks instead of generating infrastructure from scratch.
329
-
330
- Supported clients include:
331
-
332
- - Claude
333
- - Cursor
334
- - Codex
335
- - VS Code
336
- - Windsurf
337
-
338
- ## Configure MCP
339
-
340
- Run:
97
+ ### `doctor`
341
98
 
342
99
  ```bash
343
- npx blockend-cli mcp init
344
- ```
345
-
346
- Or target a specific client:
347
-
348
- ```bash
349
- npx blockend-cli mcp init --client claude
350
- ```
351
-
352
- Supported client profiles:
353
-
354
- ```text
355
- claude
356
- codex
357
- cursor
358
- vscode
359
- windsurf
100
+ npx blockend-cli doctor [--json]
360
101
  ```
361
102
 
362
- ### Preview configuration
103
+ Checks `package.json`, `blockend.json`, `tsconfig.json`, lockfiles, framework detection, and the configured blocks directory. Text mode exits with code 1 on errors. JSON mode returns `success`, `warnings`, and `errors`.
363
104
 
364
- ```bash
365
- npx blockend-cli mcp init --dry-run
366
- ```
367
-
368
- ### Force configuration
105
+ ### `update`
369
106
 
370
107
  ```bash
371
- npx blockend-cli mcp init --force
108
+ npx blockend-cli update [--json] [--diff] [--apply]
372
109
  ```
373
110
 
374
- ### Skip confirmation
375
-
376
- ```bash
377
- npx blockend-cli mcp init --yes
378
- ```
111
+ Compares installed blocks in `blockend.json` with registry versions. `--apply` prompts for blocks to update, confirms before writing, downloads new files, rewrites imports, and updates the installed metadata. In JSON mode, `--apply` updates every available block without prompting.
379
112
 
380
- ### Start the MCP server
113
+ ### `mcp`
381
114
 
382
115
  ```bash
383
116
  npx blockend-cli mcp
117
+ npx blockend-cli mcp init [options]
384
118
  ```
385
119
 
386
- Running `mcp` without a subcommand starts the Blockend MCP server.
120
+ Starts the MCP server or writes a client config. `mcp init` supports `--client`, `--dry-run`, `--force`, and `--yes`.
387
121
 
388
- ---
122
+ Supported clients: `claude`, `codex`, `cursor`, `vscode`, and `windsurf`.
389
123
 
390
- # Available Blocks
124
+ ## Config
391
125
 
392
- | Block | What it solves |
393
- | -------------------- | ---------------------------------------------------------- |
394
- | `rate-limiter` | Token bucket rate limiting with pluggable storage adapters |
395
- | `request-validator` | Zod-based input validation with framework adapters |
396
- | `error-handler` | Centralized error pipeline with typed errors |
397
- | `logger` | Structured request logging with async context propagation |
398
- | `response-formatter` | Standard API response shapes for success/error payloads |
399
- | `env-config` | Type-safe environment validation with Zod schemas |
400
- | `health-check` | Liveness/readiness probes for app and dependency health |
401
- | `password-hash` | Argon2id password hashing with PHC-string output |
126
+ A generated config looks like this:
402
127
 
403
- ---
404
-
405
- # Supported Frameworks
406
-
407
- Blockend currently supports:
408
-
409
- - **Next.js**
410
- - **Express**
411
- - **Fastify**
412
- - **Hono**
413
-
414
- Each block ships with typed, framework-native adapters where appropriate.
415
-
416
- More frameworks are coming soon.
417
-
418
- ---
419
-
420
- # Example: Rate Limiter
421
-
422
- Initialize Blockend:
423
-
424
- ```bash
425
- npx blockend-cli init
128
+ ```json
129
+ {
130
+ "$schema": "https://blockend.noorulhassan.com/schema.json",
131
+ "environment": "express",
132
+ "language": "typescript",
133
+ "packageManager": "pnpm",
134
+ "importRewriteStrategy": "remove",
135
+ "includeRedis": false,
136
+ "aliases": {
137
+ "blocks": "@/blocks"
138
+ },
139
+ "paths": {
140
+ "blocks": "./src/blocks"
141
+ }
142
+ }
426
143
  ```
427
144
 
428
- Add the rate limiter:
145
+ `add` appends an `installed` array with block names, versions, install times, file lists, and content hashes.
429
146
 
430
- ```bash
431
- npx blockend-cli add rate-limiter
432
- ```
147
+ ## Generated structure
433
148
 
434
- You may get a structure similar to:
149
+ The rate limiter with the Express adapter and memory store is written as:
435
150
 
436
151
  ```text
437
152
  src/
438
153
  └── blocks/
439
154
  └── rate-limiter/
440
- ├── core.ts
441
- ├── express.ts
442
- ├── fastify.ts
443
- └── ...
155
+ ├── adapters/
156
+ │ ├── express.ts
157
+ │ └── express.test.ts
158
+ ├── core/
159
+ │ └── core.ts
160
+ ├── utils/
161
+ │ ├── ip.ts
162
+ │ └── ip.test.ts
163
+ └── variants/
164
+ ├── memory-store.ts
165
+ └── memory-store.test.ts
444
166
  ```
445
167
 
446
- The core implementation contains the framework-agnostic rate-limiting logic, while framework adapters integrate it with your application.
447
-
448
- For example:
168
+ Import the adapter by its actual path:
449
169
 
450
170
  ```ts
451
- import { rateLimiter } from "./blocks/rate-limiter/express.js";
171
+ import { expressRateLimit } from "@/blocks/rate-limiter/adapters/express";
172
+ import { MemoryStore } from "@/blocks/rate-limiter/variants/memory-store";
452
173
  ```
453
174
 
454
- The implementation lives inside your repository.
455
-
456
- You can modify it however you need.
457
-
458
- ---
459
-
460
- # Source Ownership
175
+ There is no root `index.ts` for the rate limiter. Importing from `@/blocks/rate-limiter` will fail.
461
176
 
462
- Blockend follows a simple principle:
177
+ ## Import paths
463
178
 
464
- > **Generate it. Own it.**
179
+ Blocks are copied into `paths.blocks`. If `aliases.blocks` exists, imports use it, for example `@/blocks/logger/core`. If it does not, imports stay relative.
465
180
 
466
- Blockend does not hide your infrastructure behind a runtime package.
467
-
468
- Instead of:
181
+ Blocks with a root `index.ts` can be imported from the block folder, for example:
469
182
 
470
183
  ```ts
471
- import { rateLimiter } from "blockend";
184
+ import { createErrorBoundary } from "@/blocks/error-handler";
472
185
  ```
473
186
 
474
- your application gets source code:
187
+ Blocks without one need a file path, for example:
475
188
 
476
189
  ```ts
477
- import { rateLimiter } from "./blocks/rate-limiter/express.js";
478
- ```
479
-
480
- You can:
481
-
482
- - Read the implementation
483
- - Change the implementation
484
- - Add your own features
485
- - Remove code you don't need
486
- - Commit it to Git
487
- - Review it in pull requests
488
- - Customize it for your architecture
489
-
490
- ---
491
-
492
- # Automatic Dependencies
493
-
494
- Blockend detects your package manager automatically.
495
-
496
- Supported package managers include:
497
-
498
- - npm
499
- - pnpm
500
- - yarn
501
- - bun
502
-
503
- When a block requires dependencies, Blockend installs the required packages using the detected package manager.
504
-
505
- For example, a block using Zod can automatically install its required dependency.
506
-
507
- You don't need to manually figure out which packages are required.
508
-
509
- ---
510
-
511
- # TypeScript First
512
-
513
- Blockend is designed for TypeScript backend projects.
514
-
515
- Generated blocks are:
516
-
517
- - Fully typed
518
- - Framework-aware
519
- - Production-oriented
520
- - Designed for direct source ownership
521
- - Compatible with strict TypeScript configurations
522
-
523
- ---
524
-
525
- # Configuration
526
-
527
- After running:
528
-
529
- ```bash
530
- npx blockend-cli init
531
- ```
532
-
533
- Blockend creates a project configuration file:
534
-
535
- ```text
536
- blockend.json
190
+ import { createHealth } from "@/blocks/health-check/core/create-health";
537
191
  ```
538
192
 
539
- A configuration may look like:
540
-
541
- ```json
542
- {
543
- "framework": "express",
544
- "language": "typescript",
545
- "blocksDir": "src/blocks"
546
- }
547
- ```
548
-
549
- The exact configuration is determined from your project during initialization.
550
-
551
- ---
552
-
553
- # CLI Overview
554
-
555
- ```text
556
- blockend
557
- │
558
- ├── init
559
- │ ├── --yes
560
- │ └── --json
561
- │
562
- ├── add [block]
563
- │ ├── --yes
564
- │ ├── --json
565
- │ └── --multi
566
- │
567
- ├── list
568
- │ └── --json
569
- │
570
- ├── detect
571
- │ └── --json
572
- │
573
- ├── diff <block>
574
- │ └── --json
575
- │
576
- ├── doctor
577
- │ └── --json
578
- │
579
- ├── update
580
- │ ├── --json
581
- │ ├── --diff
582
- │ └── --apply
583
- │
584
- └── mcp
585
- └── init
586
- ├── --client
587
- ├── --force
588
- ├── --dry-run
589
- └── --yes
590
- ```
591
-
592
- ---
593
-
594
- # Typical Workflow
595
-
596
- ### 1. Initialize
597
-
598
- ```bash
599
- npx blockend-cli init
600
- ```
601
-
602
- ### 2. Check your project
603
-
604
- ```bash
605
- npx blockend-cli detect
606
- ```
607
-
608
- ### 3. Browse available blocks
609
-
610
- ```bash
611
- npx blockend-cli list
612
- ```
613
-
614
- ### 4. Preview a block
615
-
616
- ```bash
617
- npx blockend-cli diff rate-limiter
618
- ```
619
-
620
- ### 5. Add the block
621
-
622
- ```bash
623
- npx blockend-cli add rate-limiter
624
- ```
625
-
626
- ### 6. Check your project
627
-
628
- ```bash
629
- npx blockend-cli doctor
630
- ```
631
-
632
- ### 7. Keep blocks updated
633
-
634
- ```bash
635
- npx blockend-cli update
636
- ```
637
-
638
- ### 8. Connect your AI assistant
639
-
640
- ```bash
641
- npx blockend-cli mcp init
642
- ```
643
-
644
- ---
645
-
646
- # Roadmap
647
-
648
- The following blocks and capabilities are planned:
649
-
650
- - JWT authentication
651
- - CORS
652
- - Security headers
653
- - Idempotency
654
- - Webhooks
655
- - Additional framework adapters
656
- - More storage adapters
657
- - More AI/MCP integrations
658
-
659
- ---
660
-
661
- # Documentation
662
-
663
- Full documentation:
664
-
665
- [https://blockend.noorulhassan.com/docs](https://blockend.noorulhassan.com/docs)
666
-
667
- ---
668
-
669
- # Repository
670
-
671
- Source code, issues, block implementations, and contribution guides:
672
-
673
- [https://github.com/codewithnuh/blockend](https://github.com/codewithnuh/blockend)
674
-
675
- If Blockend saves you from rewriting backend boilerplate, consider giving the project a star.
676
-
677
- ---
678
-
679
- # Contributing
680
-
681
- Contributions are welcome.
682
-
683
- You can contribute by:
684
-
685
- - Adding new backend blocks
686
- - Improving existing blocks
687
- - Adding framework adapters
688
- - Improving documentation
689
- - Reporting bugs
690
- - Suggesting new infrastructure primitives
691
- - Improving the CLI
692
- - Improving MCP integrations
693
-
694
- See the repository for contribution guidelines.
695
-
696
- ---
697
-
698
- # License
699
-
700
- MIT © CodeWithNuh
193
+ Each block's documentation page lists the correct paths.
701
194
 
702
- See the full license:
195
+ ## License
703
196
 
704
- [https://github.com/codewithnuh/blockend/blob/master/LICENSE](https://github.com/codewithnuh/blockend/blob/master/LICENSE)
197
+ MIT. See the repository [LICENSE](../../LICENSE).