@domain-first/project-structure 2.3.0 → 2.4.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,11 +1,54 @@
1
- # Domain-First Project Structure
1
+ # @domain-first/project-structure
2
2
 
3
- Build and manage your Domain-First project structure with CLI.
3
+ Stop hand-rolling folders. Scaffold a clean, consistent **Domain-First** architecture — bounded contexts, aggregates, use cases, commands/queries, ports, REST endpoints, React modules — with one command, every time.
4
4
 
5
- ## Usage
5
+ ```bash
6
+ npx df-ps
7
+ ```
8
+
9
+ ## Why
10
+
11
+ - **Zero boilerplate** — aggregates, repositories, wiring and tests generated in seconds, correctly named and cross-linked
12
+ - **One consistent architecture** — every bounded context, layer and file lands in the same place, no matter who on the team runs it
13
+ - **Grows with your stack** — adapts output to whichever `@domain-first` packages (`types`, `errors`, `handlers`, `wire`, `handlers-rest`) you use, or stays framework-free if you don't
14
+ - **Interactive, not magic** — a guided CLI menu, not a rigid template you fight against
15
+
16
+ ## Install
6
17
 
7
18
  ```bash
8
- npm i @domain-first/project-structure
19
+ npm i -D @domain-first/project-structure
20
+ ```
21
+
22
+ ## Quick start
9
23
 
24
+ ```bash
10
25
  npx df-ps
11
26
  ```
27
+
28
+ First run walks you through a short setup (source folder, packages, testing library) and writes a config file. Every run after that opens a menu to scaffold whatever you need next — a new aggregate, use case, endpoint, widget — into your existing structure.
29
+
30
+ ## What gets generated
31
+
32
+ Pick a piece, get the whole slice — class, tests, infra implementation and wiring, all linked together:
33
+
34
+ - **Domain** — aggregates, repositories, services, namespaced errors
35
+ - **Application** — use cases, commands & queries (execution or orchestration), ports
36
+ - **Infrastructure** — adapter implementations per port/repository (e.g. `prisma`, `in-memory`)
37
+ - **Presentation** — REST endpoints, React pages/widgets
38
+
39
+ Everything lands with consistent naming and imports. For example:
40
+
41
+ ```
42
+ bounded-contexts/
43
+ order/
44
+ domain/aggregates/order/
45
+ application/use-cases/
46
+ application/commands/
47
+ infrastructure/repositories/
48
+ presentation/rest/
49
+ wiring/
50
+ ```
51
+
52
+ ## License
53
+
54
+ MIT
package/dist/index.cjs CHANGED
@@ -481,6 +481,10 @@ const scaffoldNewCommand = async (boundedContextFolder)=>{
481
481
  const commandName = await (0, prompts_namespaceObject.input)({
482
482
  message: 'Name: '
483
483
  });
484
+ let scaffoldUnitTests;
485
+ if (ConfigFile.Instance.data.testingLibrary) scaffoldUnitTests = await (0, prompts_namespaceObject.confirm)({
486
+ message: 'Scaffold unit-tests'
487
+ });
484
488
  const naming = new UnknownFormatNaming(commandName);
485
489
  const commandType = await (0, prompts_namespaceObject.select)({
486
490
  choices: [
@@ -490,6 +494,25 @@ const scaffoldNewCommand = async (boundedContextFolder)=>{
490
494
  message: 'Command type'
491
495
  });
492
496
  const isOrchestrator = 'Orchestrator (no infrastructure implementation)' === commandType;
497
+ if (scaffoldUnitTests) commandsFolder.subitem([
498
+ isOrchestrator ? 'orchestration' : 'execution'
499
+ ]).createFile(`${naming.fileName}-command.spec.ts`, `
500
+ import { describe, test, expect, beforeEach } from '${ConfigFile.Instance.data.testingLibrary}'
501
+ import { type ${naming.ClassName}Command } from './${naming.fileName}-command'
502
+ import { wire${naming.ClassName}Command } from '../../../wiring/commands/wire-${naming.fileName}-command'
503
+
504
+ let ${naming.variableName}Command: ${naming.ClassName}Command
505
+
506
+ beforeEach(() => {
507
+ ${naming.variableName}Command = wire${naming.ClassName}Command()
508
+ })
509
+
510
+ describe('${naming.withSpaces} command', () => {
511
+ test('can be wired', () => {
512
+ expect(${naming.variableName}Command).toBeDefined()
513
+ })
514
+ })
515
+ `);
493
516
  if (!isOrchestrator) {
494
517
  const implementationType = await (0, prompts_namespaceObject.input)({
495
518
  message: 'Command infrastructure implementation type:',
@@ -603,11 +626,10 @@ export class ${naming.ClassName}Command {
603
626
  }`.trim());
604
627
  if (ConfigFile.Instance.data.domainFirstPackages.includes('@domain-first/wire')) boundedContextFolder.subitem([
605
628
  'wiring',
606
- 'application',
607
629
  'commands'
608
630
  ]).createFile(`wire-${naming.fileName}-command.ts`, `
609
631
  import { wireClass } from '@domain-first/wire'
610
- import { ${naming.ClassName}Command } from '../../../application/commands/orchestration/${naming.fileName}-command'
632
+ import { ${naming.ClassName}Command } from '../../application/commands/orchestration/${naming.fileName}-command'
611
633
 
612
634
  export const wire${naming.ClassName}Command = wireClass(${naming.ClassName}Command, [])
613
635
  `.trim());
package/dist/index.js CHANGED
@@ -451,6 +451,10 @@ const scaffoldNewCommand = async (boundedContextFolder)=>{
451
451
  const commandName = await input({
452
452
  message: 'Name: '
453
453
  });
454
+ let scaffoldUnitTests;
455
+ if (ConfigFile.Instance.data.testingLibrary) scaffoldUnitTests = await prompts_confirm({
456
+ message: 'Scaffold unit-tests'
457
+ });
454
458
  const naming = new UnknownFormatNaming(commandName);
455
459
  const commandType = await prompts_select({
456
460
  choices: [
@@ -460,6 +464,25 @@ const scaffoldNewCommand = async (boundedContextFolder)=>{
460
464
  message: 'Command type'
461
465
  });
462
466
  const isOrchestrator = 'Orchestrator (no infrastructure implementation)' === commandType;
467
+ if (scaffoldUnitTests) commandsFolder.subitem([
468
+ isOrchestrator ? 'orchestration' : 'execution'
469
+ ]).createFile(`${naming.fileName}-command.spec.ts`, `
470
+ import { describe, test, expect, beforeEach } from '${ConfigFile.Instance.data.testingLibrary}'
471
+ import { type ${naming.ClassName}Command } from './${naming.fileName}-command'
472
+ import { wire${naming.ClassName}Command } from '../../../wiring/commands/wire-${naming.fileName}-command'
473
+
474
+ let ${naming.variableName}Command: ${naming.ClassName}Command
475
+
476
+ beforeEach(() => {
477
+ ${naming.variableName}Command = wire${naming.ClassName}Command()
478
+ })
479
+
480
+ describe('${naming.withSpaces} command', () => {
481
+ test('can be wired', () => {
482
+ expect(${naming.variableName}Command).toBeDefined()
483
+ })
484
+ })
485
+ `);
463
486
  if (!isOrchestrator) {
464
487
  const implementationType = await input({
465
488
  message: 'Command infrastructure implementation type:',
@@ -573,11 +596,10 @@ export class ${naming.ClassName}Command {
573
596
  }`.trim());
574
597
  if (ConfigFile.Instance.data.domainFirstPackages.includes('@domain-first/wire')) boundedContextFolder.subitem([
575
598
  'wiring',
576
- 'application',
577
599
  'commands'
578
600
  ]).createFile(`wire-${naming.fileName}-command.ts`, `
579
601
  import { wireClass } from '@domain-first/wire'
580
- import { ${naming.ClassName}Command } from '../../../application/commands/orchestration/${naming.fileName}-command'
602
+ import { ${naming.ClassName}Command } from '../../application/commands/orchestration/${naming.fileName}-command'
581
603
 
582
604
  export const wire${naming.ClassName}Command = wireClass(${naming.ClassName}Command, [])
583
605
  `.trim());
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@domain-first/project-structure",
3
3
  "description": "Build and manage your Domain-First project structure with CLI",
4
- "version": "2.3.0",
4
+ "version": "2.4.0",
5
5
  "type": "module",
6
6
  "repository": {
7
7
  "type": "git",