blockend-cli 2.1.0 → 2.1.1

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,188 @@
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
- ---
89
-
90
- # Commands
91
-
92
- ## `init`
93
-
94
- Detect your framework and initialize Blockend.
95
-
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
109
-
110
- ```bash
111
- npx blockend-cli init --yes
112
- ```
113
-
114
- or:
115
-
116
- ```bash
117
- npx blockend-cli init -y
118
- ```
119
-
120
- ### JSON output
121
-
122
- ```bash
123
- npx blockend-cli init --json
124
- ```
125
-
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
- ```
135
-
136
- Other examples:
137
-
138
- ```bash
139
- npx blockend-cli add request-validator
140
- ```
141
-
142
- ```bash
143
- npx blockend-cli add error-handler
144
- ```
145
-
146
- ```bash
147
- npx blockend-cli add logger
148
- ```
149
-
150
- ### Interactive mode
151
-
152
- Run `add` without specifying a block:
153
-
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
161
-
162
- ```bash
163
- npx blockend-cli add --multi
164
- ```
165
-
166
- or:
167
-
168
- ```bash
169
- npx blockend-cli add -m
170
- ```
171
-
172
- ### Skip confirmation
173
-
174
- ```bash
175
- npx blockend-cli add rate-limiter --yes
176
- ```
177
-
178
- or:
179
-
180
- ```bash
181
- npx blockend-cli add rate-limiter -y
182
- ```
183
-
184
- ### JSON output
185
-
186
- ```bash
187
- npx blockend-cli add rate-limiter --json
188
- ```
189
-
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
24
+ ## Requirements
218
25
 
219
- ```bash
220
- npx blockend-cli list --json
221
- ```
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
222
30
 
223
- ---
31
+ The `add` command rejects JavaScript projects.
224
32
 
225
- ## `detect`
33
+ ## Commands
226
34
 
227
- Detect information about your current project.
35
+ ### `init`
228
36
 
229
37
  ```bash
230
- npx blockend-cli detect
38
+ npx blockend-cli init [--yes] [--json]
231
39
  ```
232
40
 
233
- Blockend can inspect:
41
+ Detects the framework, language, package manager, Redis, and import alias, then writes `blockend.json`.
234
42
 
235
- - Framework
236
- - Package manager
237
- - TypeScript configuration
238
- - Project structure
239
- - Workspace configuration
240
- - Runtime environment
241
- - Relevant project directories
43
+ `--yes` accepts detected defaults and overwrites an existing config without prompting. If no framework is detected, it uses Express.
242
44
 
243
- ### JSON output
45
+ ### `add`
244
46
 
245
47
  ```bash
246
- npx blockend-cli detect --json
48
+ npx blockend-cli add [block] [options]
247
49
  ```
248
50
 
249
- ---
250
-
251
- ## `diff`
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. |
252
57
 
253
- Preview the files that a block would generate without modifying your project.
58
+ 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.
254
59
 
255
- ```bash
256
- npx blockend-cli diff rate-limiter
257
- ```
60
+ `add --yes` without a block name is an error.
258
61
 
259
- This lets you inspect changes before adding a block.
62
+ 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.
260
63
 
261
- ### JSON output
64
+ ### `list`
262
65
 
263
66
  ```bash
264
- npx blockend-cli diff rate-limiter --json
67
+ npx blockend-cli list [--json]
265
68
  ```
266
69
 
267
- ---
70
+ Lists blocks compatible with the framework in `blockend.json`.
268
71
 
269
- ## `doctor`
270
-
271
- Diagnose Blockend configuration and project issues.
72
+ ### `detect`
272
73
 
273
74
  ```bash
274
- npx blockend-cli doctor
75
+ npx blockend-cli detect [--json]
275
76
  ```
276
77
 
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
78
+ Reports framework, language, package manager, source directory, import rewrite strategy, and detected Redis, Prisma, and Drizzle usage. It does not require `blockend.json`.
285
79
 
286
- ### JSON output
80
+ ### `diff`
287
81
 
288
82
  ```bash
289
- npx blockend-cli doctor --json
83
+ npx blockend-cli diff <block> [--json]
290
84
  ```
291
85
 
292
- ---
86
+ Shows which files a block would add, modify, or leave unchanged. It does not write to disk.
293
87
 
294
- ## `update`
295
-
296
- Check installed blocks for newer versions.
88
+ ### `doctor`
297
89
 
298
90
  ```bash
299
- npx blockend-cli update
91
+ npx blockend-cli doctor [--json]
300
92
  ```
301
93
 
302
- Blockend compares your installed blocks with newer available versions and shows their differences.
94
+ 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`.
303
95
 
304
- ### Apply updates
96
+ ### `update`
305
97
 
306
98
  ```bash
307
- npx blockend-cli update --apply
99
+ npx blockend-cli update [--json] [--diff] [--apply]
308
100
  ```
309
101
 
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
327
-
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:
341
-
342
- ```bash
343
- npx blockend-cli mcp init
344
- ```
102
+ 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.
345
103
 
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
360
- ```
361
-
362
- ### Preview configuration
363
-
364
- ```bash
365
- npx blockend-cli mcp init --dry-run
366
- ```
367
-
368
- ### Force configuration
369
-
370
- ```bash
371
- npx blockend-cli mcp init --force
372
- ```
373
-
374
- ### Skip confirmation
375
-
376
- ```bash
377
- npx blockend-cli mcp init --yes
378
- ```
379
-
380
- ### Start the MCP server
104
+ ### `mcp`
381
105
 
382
106
  ```bash
383
107
  npx blockend-cli mcp
108
+ npx blockend-cli mcp init [options]
384
109
  ```
385
110
 
386
- Running `mcp` without a subcommand starts the Blockend MCP server.
387
-
388
- ---
389
-
390
- # Available Blocks
391
-
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 |
402
-
403
- ---
404
-
405
- # Supported Frameworks
406
-
407
- Blockend currently supports:
408
-
409
- - **Next.js**
410
- - **Express**
411
- - **Fastify**
412
- - **Hono**
111
+ Starts the MCP server or writes a client config. `mcp init` supports `--client`, `--dry-run`, `--force`, and `--yes`.
413
112
 
414
- Each block ships with typed, framework-native adapters where appropriate.
113
+ Supported clients: `claude`, `codex`, `cursor`, `vscode`, and `windsurf`.
415
114
 
416
- More frameworks are coming soon.
115
+ ## Config
417
116
 
418
- ---
117
+ A generated config looks like this:
419
118
 
420
- # Example: Rate Limiter
421
-
422
- Initialize Blockend:
423
-
424
- ```bash
425
- npx blockend-cli init
119
+ ```json
120
+ {
121
+ "$schema": "https://blockend.noorulhassan.com/schema.json",
122
+ "environment": "express",
123
+ "language": "typescript",
124
+ "packageManager": "pnpm",
125
+ "importRewriteStrategy": "remove",
126
+ "includeRedis": false,
127
+ "aliases": {
128
+ "blocks": "@/blocks"
129
+ },
130
+ "paths": {
131
+ "blocks": "./src/blocks"
132
+ }
133
+ }
426
134
  ```
427
135
 
428
- Add the rate limiter:
136
+ `add` appends an `installed` array with block names, versions, install times, file lists, and content hashes.
429
137
 
430
- ```bash
431
- npx blockend-cli add rate-limiter
432
- ```
138
+ ## Generated structure
433
139
 
434
- You may get a structure similar to:
140
+ The rate limiter with the Express adapter and memory store is written as:
435
141
 
436
142
  ```text
437
143
  src/
438
144
  └── blocks/
439
145
  └── rate-limiter/
440
- ├── core.ts
441
- ├── express.ts
442
- ├── fastify.ts
443
- └── ...
146
+ ├── adapters/
147
+ │ ├── express.ts
148
+ │ └── express.test.ts
149
+ ├── core/
150
+ │ └── core.ts
151
+ ├── utils/
152
+ │ ├── ip.ts
153
+ │ └── ip.test.ts
154
+ └── variants/
155
+ ├── memory-store.ts
156
+ └── memory-store.test.ts
444
157
  ```
445
158
 
446
- The core implementation contains the framework-agnostic rate-limiting logic, while framework adapters integrate it with your application.
447
-
448
- For example:
159
+ Import the adapter by its actual path:
449
160
 
450
161
  ```ts
451
- import { rateLimiter } from "./blocks/rate-limiter/express.js";
162
+ import { expressRateLimit } from "@/blocks/rate-limiter/adapters/express";
163
+ import { MemoryStore } from "@/blocks/rate-limiter/variants/memory-store";
452
164
  ```
453
165
 
454
- The implementation lives inside your repository.
455
-
456
- You can modify it however you need.
166
+ There is no root `index.ts` for the rate limiter. Importing from `@/blocks/rate-limiter` will fail.
457
167
 
458
- ---
168
+ ## Import paths
459
169
 
460
- # Source Ownership
170
+ 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.
461
171
 
462
- Blockend follows a simple principle:
463
-
464
- > **Generate it. Own it.**
465
-
466
- Blockend does not hide your infrastructure behind a runtime package.
467
-
468
- Instead of:
172
+ Blocks with a root `index.ts` can be imported from the block folder, for example:
469
173
 
470
174
  ```ts
471
- import { rateLimiter } from "blockend";
175
+ import { createErrorBoundary } from "@/blocks/error-handler";
472
176
  ```
473
177
 
474
- your application gets source code:
178
+ Blocks without one need a file path, for example:
475
179
 
476
180
  ```ts
477
- import { rateLimiter } from "./blocks/rate-limiter/express.js";
181
+ import { createHealth } from "@/blocks/health-check/core/create-health";
478
182
  ```
479
183
 
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
537
- ```
538
-
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
184
+ Each block's documentation page lists the correct paths.
701
185
 
702
- See the full license:
186
+ ## License
703
187
 
704
- [https://github.com/codewithnuh/blockend/blob/master/LICENSE](https://github.com/codewithnuh/blockend/blob/master/LICENSE)
188
+ MIT. See the repository [LICENSE](../../LICENSE).