@domain-first/project-structure 4.1.0 → 4.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
@@ -13,7 +13,7 @@ Spend less time setting up files. Spend more time building your domain.
13
13
 
14
14
  In most TypeScript codebases you choose between convenience and architecture. Clear boundaries and roles around the domain mean more files, more contracts and more wiring, so under deadline pressure the logic ends up wherever it is quickest to write it. The boundaries blur one shortcut at a time.
15
15
 
16
- Domain First Project Structure removes that choice: **the cleanest path is also the shortest one**. An interactive CLI asks which bounded context, layer and role a new piece of code has, and generates it in its place, with contracts, implementations, test skeletons and wiring that respect the boundaries. Dependencies are offered only where the layers allow them. Doing it right takes a few prompts; doing it wrong takes extra effort. It knows the `@domain-first` packages: types, errors, handlers, wire and handlers-rest. The generated files belong to your project; you write the business rules.
16
+ Domain First Project Structure removes that choice: **the cleanest path is also the shortest one**. An interactive CLI asks which bounded context, layer and role a new piece of code has, and generates it in its place, with contracts, implementations, test skeletons and wiring that respect the boundaries. Dependencies are offered only where the dependency rules allow them. Doing it right takes a few prompts; doing it wrong takes extra effort. It knows the `@domain-first` packages: types, errors, handlers, wire and handlers-rest. The generated files belong to your project; you write the business rules.
17
17
 
18
18
  ```
19
19
  npm i -D @domain-first/project-structure
@@ -213,7 +213,24 @@ Choose **Add integration** to configure Storybook, Prisma 8, Vitest, Playwright,
213
213
  npx df-lint
214
214
  ```
215
215
 
216
- It reports what breaks the Domain-First rules: imports between bounded contexts, imports against the layers, queries using commands, wired dependencies the CLI wouldn't offer, React modules importing what they shouldn't, and reading the time without the clock port. It exits with 1 when something is found, so you can run it in CI.
216
+ It reports what breaks the Domain-First rules: imports between bounded contexts, imports against the layers, modules using kinds the dependency rules don't allow (in imports and in wiring), React modules importing what they shouldn't, and reading the time without the clock port. It exits with 1 when something is found, so you can run it in CI.
217
+
218
+ The rules are a default. Teams that work differently change them in the config: what each kind of module may depend on (`rules.dependencies`) and which checks run (`rules.lint`). `df-ps` offers dependencies by the same rules. Without `rules`, the defaults apply and every check runs; kinds and checks you don't mention keep their defaults.
219
+
220
+ - Kinds in `rules.dependencies` (as keys and in lists): `repositories`, `domain-services`, `application-ports`, `application-services`, `use-cases`, `execution-commands`, `execution-queries`, `orchestration-commands`, `orchestration-queries`, `infrastructure-services`, `presentation-services`.
221
+ - A kind's value: a list that replaces its defaults, or `{ "add": [...], "remove": [...] }`.
222
+ - Checks in `rules.lint`: `context-isolation`, `shared-layer`, `layers`, `dependencies`, `react`, `clock`.
223
+
224
+ Defaults and details: [Dependency rules](API.md#dependency-rules), [`df-lint`](API.md#df-lint).
225
+
226
+ ```json
227
+ {
228
+ "rules": {
229
+ "dependencies": { "use-cases": { "add": ["use-cases"] } },
230
+ "lint": { "clock": false }
231
+ }
232
+ }
233
+ ```
217
234
 
218
235
  ### How to teach your coding agent
219
236
 
@@ -2,6 +2,130 @@ import node_path from "node:path";
2
2
  import zod from "zod";
3
3
  import node_fs from "node:fs";
4
4
  import { createRequire } from "node:module";
5
+ const moduleKinds = [
6
+ 'repositories',
7
+ 'domain-services',
8
+ 'application-ports',
9
+ 'application-services',
10
+ 'use-cases',
11
+ 'execution-commands',
12
+ 'execution-queries',
13
+ 'orchestration-commands',
14
+ 'orchestration-queries',
15
+ 'infrastructure-services',
16
+ 'presentation-services'
17
+ ];
18
+ const domain = [
19
+ 'repositories',
20
+ 'domain-services'
21
+ ];
22
+ const commandsAndQueries = [
23
+ 'execution-commands',
24
+ 'execution-queries',
25
+ 'orchestration-commands',
26
+ 'orchestration-queries'
27
+ ];
28
+ const infrastructure = [
29
+ ...domain,
30
+ 'application-ports',
31
+ 'infrastructure-services'
32
+ ];
33
+ const defaultDependencies = {
34
+ 'domain-services': domain,
35
+ repositories: [
36
+ 'domain-services',
37
+ 'application-ports',
38
+ 'infrastructure-services'
39
+ ],
40
+ 'application-ports': infrastructure,
41
+ 'application-services': [
42
+ ...domain,
43
+ 'application-ports'
44
+ ],
45
+ 'use-cases': [
46
+ ...domain,
47
+ 'application-ports',
48
+ 'application-services',
49
+ ...commandsAndQueries
50
+ ],
51
+ 'execution-commands': infrastructure,
52
+ 'execution-queries': infrastructure,
53
+ 'orchestration-commands': [
54
+ ...domain,
55
+ 'execution-commands',
56
+ 'execution-queries'
57
+ ],
58
+ 'orchestration-queries': [
59
+ ...domain,
60
+ 'execution-queries'
61
+ ],
62
+ 'infrastructure-services': infrastructure,
63
+ 'presentation-services': [
64
+ 'application-ports',
65
+ 'application-services',
66
+ 'use-cases',
67
+ ...commandsAndQueries,
68
+ 'presentation-services'
69
+ ]
70
+ };
71
+ const kindSchema = zod["enum"](moduleKinds);
72
+ const dependencyRulesSchema = zod.partialRecord(kindSchema, zod.union([
73
+ zod.array(kindSchema),
74
+ zod.object({
75
+ add: zod.array(kindSchema).optional(),
76
+ remove: zod.array(kindSchema).optional()
77
+ })
78
+ ]));
79
+ const resolveDependencyRules = (config = {})=>{
80
+ const entries = moduleKinds.map((kind)=>{
81
+ const override = config[kind];
82
+ if (Array.isArray(override)) return [
83
+ kind,
84
+ new Set(override)
85
+ ];
86
+ const kinds = new Set([
87
+ ...defaultDependencies[kind],
88
+ ...override?.add ?? []
89
+ ]);
90
+ for (const removed of override?.remove ?? [])kinds.delete(removed);
91
+ return [
92
+ kind,
93
+ kinds
94
+ ];
95
+ });
96
+ return Object.fromEntries(entries);
97
+ };
98
+ const defaultDependencyRules = resolveDependencyRules();
99
+ const isModuleKind = (value)=>moduleKinds.includes(value);
100
+ const wiredModuleKind = (wiringKind, typeFile)=>{
101
+ const kind = 'commands' === wiringKind || 'queries' === wiringKind ? `${'execution' === node_path.basename(node_path.dirname(typeFile)) ? 'execution' : 'orchestration'}-${wiringKind}` : wiringKind;
102
+ return isModuleKind(kind) ? kind : void 0;
103
+ };
104
+ const fileModuleKind = (segments)=>{
105
+ const [layer, folder, mode] = segments;
106
+ const file = segments.at(-1) ?? '';
107
+ if (/^index(\.tsx?)?$/.test(file)) return;
108
+ if ('domain' === layer) {
109
+ if ('services' === folder) return 'domain-services';
110
+ return 'aggregates' === folder && /-repository(\.tsx?)?$/.test(file) ? 'repositories' : void 0;
111
+ }
112
+ if ('application' === layer) {
113
+ if ('commands' === folder || 'queries' === folder) return 'execution' === mode || 'orchestration' === mode ? `${mode}-${folder}` : void 0;
114
+ return ({
115
+ ports: 'application-ports',
116
+ services: 'application-services',
117
+ 'use-cases': 'use-cases'
118
+ })[folder];
119
+ }
120
+ if ('infrastructure' === layer) return ({
121
+ repositories: 'repositories',
122
+ commands: 'execution-commands',
123
+ queries: 'execution-queries',
124
+ 'application-adapters': 'application-ports',
125
+ services: 'infrastructure-services'
126
+ })[folder];
127
+ return 'presentation' === layer && 'services' === folder ? 'presentation-services' : void 0;
128
+ };
5
129
  const pendingFiles = new Map();
6
130
  const pendingFolders = new Set();
7
131
  const pendingMoves = new Map();
@@ -151,6 +275,14 @@ class ProjectRoot {
151
275
  throw new Error('No package.json was found');
152
276
  }
153
277
  }
278
+ const lintChecks = [
279
+ 'context-isolation',
280
+ 'shared-layer',
281
+ 'layers',
282
+ 'dependencies',
283
+ 'react',
284
+ 'clock'
285
+ ];
154
286
  const configFileName = 'domain-first.project-structure.config.json';
155
287
  const configSchema = zod.object({
156
288
  rootFolder: zod.string(),
@@ -165,7 +297,11 @@ const configSchema = zod.object({
165
297
  withInMemoryDb: zod.boolean().optional(),
166
298
  useReact: zod.boolean(),
167
299
  storybookFramework: zod.string().optional(),
168
- testingLibrary: zod.string().optional()
300
+ testingLibrary: zod.string().optional(),
301
+ rules: zod.object({
302
+ dependencies: dependencyRulesSchema.optional(),
303
+ lint: zod.partialRecord(zod["enum"](lintChecks), zod.boolean()).optional()
304
+ }).optional()
169
305
  });
170
306
  class ConfigFile {
171
307
  data;
@@ -189,6 +325,7 @@ class ConfigFile {
189
325
  new File(ConfigFile.path).data = JSON.stringify(config, null, '\t');
190
326
  };
191
327
  }
328
+ const configuredDependencyRules = ()=>resolveDependencyRules(ConfigFile.exists ? ConfigFile.Instance.data.rules?.dependencies : void 0);
192
329
  const stripJsonComments = (source)=>source.replace(/("(?:\\.|[^"\\])*")|\/\/[^\n]*|\/\*[\s\S]*?\*\//g, (_, text)=>text ? text : '').replace(/,(\s*[}\]])/g, '$1');
193
330
  const resolveExtends = (fromFile, target)=>{
194
331
  if (target.startsWith('.') || node_path.isAbsolute(target)) {
@@ -385,25 +522,18 @@ const findWiredModules = (contextPath)=>{
385
522
  walk(node_path.join(contextPath, 'wiring'));
386
523
  return result.sort((a, b)=>a.typeName.localeCompare(b.typeName));
387
524
  };
388
- const isCommandOrQuery = (module)=>'commands' === module.kind || 'queries' === module.kind;
389
- const isExecution = (module)=>isCommandOrQuery(module) && 'execution' === node_path.basename(node_path.dirname(module.typeFile));
390
- const commandOrQueryRule = (candidate, consumer)=>isExecution(consumer) ? !isCommandOrQuery(candidate) : 'application' !== candidate.layer || isExecution(candidate) && ('commands' === consumer.kind || 'queries' === candidate.kind);
391
- const layerRules = {
392
- infrastructure: (candidate)=>'application' !== candidate.layer || 'application-ports' === candidate.kind
393
- };
394
- const kindRules = {
395
- 'application-services': (candidate)=>'application' !== candidate.layer || 'application-ports' === candidate.kind,
396
- 'use-cases': (candidate)=>'use-cases' !== candidate.kind,
397
- repositories: (candidate)=>'repositories' !== candidate.kind,
398
- commands: commandOrQueryRule,
399
- queries: commandOrQueryRule
400
- };
525
+ const moduleKindOf = (module)=>wiredModuleKind(module.kind, module.typeFile);
526
+ const layerRule = (consumer, candidate)=>visibleLayers[consumer.implementationsLayer].includes(candidate.layer) && ('infrastructure' !== consumer.implementationsLayer || 'application' !== candidate.layer || 'application-ports' === candidate.kind);
401
527
  const implementationType = (consumer, implementation)=>consumer.branched ? node_path.basename(node_path.dirname(implementation.file)) : void 0;
402
528
  const isSuggestedFor = (candidate, implementation)=>'infrastructure' === candidate.layer && `-${node_path.basename(candidate.typeFile, '.ts')}-`.includes(`-${implementation}-`);
403
- const canDependOn = (consumer, candidate)=>visibleLayers[consumer.implementationsLayer].includes(candidate.layer) && (layerRules[consumer.implementationsLayer]?.(candidate) ?? true) && (kindRules[consumer.kind]?.(candidate, consumer) ?? true);
404
- const availableDependencies = (consumer, implementation, candidates)=>{
529
+ const canDependOn = (consumer, candidate, rules = defaultDependencyRules)=>{
530
+ const consumerKind = moduleKindOf(consumer);
531
+ const candidateKind = moduleKindOf(candidate);
532
+ return consumerKind && candidateKind ? rules[consumerKind].has(candidateKind) : layerRule(consumer, candidate);
533
+ };
534
+ const availableDependencies = (consumer, implementation, candidates, rules = configuredDependencyRules())=>{
405
535
  const wired = wiredDependencyNames(new File(consumer.wireFile).data, implementation.className);
406
- return candidates.filter((candidate)=>candidate.wireFile !== consumer.wireFile && canDependOn(consumer, candidate) && !wired.includes(candidate.wireName));
536
+ return candidates.filter((candidate)=>candidate.wireFile !== consumer.wireFile && canDependOn(consumer, candidate, rules) && !wired.includes(candidate.wireName));
407
537
  };
408
538
  const relativeImport = (fromFile, toFile)=>{
409
539
  const relativePath = node_path.relative(node_path.dirname(fromFile), toFile).replace(/\.ts$/, '').split(node_path.sep).join('/');
@@ -566,4 +696,4 @@ const wireDependencies = (consumer, implementation, dependencies)=>{
566
696
  for (const dependency of dependencies)classSource = addImport(classSource, `import type { ${dependency.typeName} } from '${relativeImport(implementation.file, dependency.typeFile)}'`);
567
697
  classFile.update(addConstructorParameters(classSource, implementation.className, dependencies.map((x)=>`private readonly ${parameterName(x.typeName)}: ${x.typeName}`)));
568
698
  };
569
- export { ConfigFile, File, Folder, ProjectRoot, UnknownFormatNaming, addClassMember, addConstructorParameters, addImport, addWireDependencies, availableDependencies, canDependOn, compilerOption, discardPendingChanges, filesToOverwrite, findWiredModules, implementationType, isSuggestedFor, readWiredModule, relativeImport, stripJsonComments, wireDependencies, wiredDependencyNames, writePendingChanges };
699
+ export { ConfigFile, File, Folder, ProjectRoot, UnknownFormatNaming, addClassMember, addConstructorParameters, addImport, addWireDependencies, availableDependencies, canDependOn, compilerOption, configuredDependencyRules, defaultDependencyRules, discardPendingChanges, fileModuleKind, filesToOverwrite, findWiredModules, implementationType, isSuggestedFor, moduleKindOf, readWiredModule, relativeImport, stripJsonComments, wireDependencies, wiredDependencyNames, writePendingChanges };
@@ -1,4 +1,9 @@
1
1
  import z from 'zod';
2
+ /**
3
+ * `df-lint` checks that `rules.lint` can turn off.
4
+ */
5
+ export declare const lintChecks: readonly ["context-isolation", "shared-layer", "layers", "dependencies", "react", "clock"];
6
+ export type LintCheck = (typeof lintChecks)[number];
2
7
  declare const configSchema: z.ZodObject<{
3
8
  rootFolder: z.ZodString;
4
9
  domainFirstPackages: z.ZodArray<z.ZodEnum<{
@@ -13,6 +18,68 @@ declare const configSchema: z.ZodObject<{
13
18
  useReact: z.ZodBoolean;
14
19
  storybookFramework: z.ZodOptional<z.ZodString>;
15
20
  testingLibrary: z.ZodOptional<z.ZodString>;
21
+ rules: z.ZodOptional<z.ZodObject<{
22
+ dependencies: z.ZodOptional<z.ZodRecord<z.ZodEnum<{
23
+ repositories: "repositories";
24
+ "domain-services": "domain-services";
25
+ "application-ports": "application-ports";
26
+ "application-services": "application-services";
27
+ "use-cases": "use-cases";
28
+ "execution-commands": "execution-commands";
29
+ "execution-queries": "execution-queries";
30
+ "orchestration-commands": "orchestration-commands";
31
+ "orchestration-queries": "orchestration-queries";
32
+ "infrastructure-services": "infrastructure-services";
33
+ "presentation-services": "presentation-services";
34
+ }> & z.core.$partial, z.ZodUnion<readonly [z.ZodArray<z.ZodEnum<{
35
+ repositories: "repositories";
36
+ "domain-services": "domain-services";
37
+ "application-ports": "application-ports";
38
+ "application-services": "application-services";
39
+ "use-cases": "use-cases";
40
+ "execution-commands": "execution-commands";
41
+ "execution-queries": "execution-queries";
42
+ "orchestration-commands": "orchestration-commands";
43
+ "orchestration-queries": "orchestration-queries";
44
+ "infrastructure-services": "infrastructure-services";
45
+ "presentation-services": "presentation-services";
46
+ }>>, z.ZodObject<{
47
+ add: z.ZodOptional<z.ZodArray<z.ZodEnum<{
48
+ repositories: "repositories";
49
+ "domain-services": "domain-services";
50
+ "application-ports": "application-ports";
51
+ "application-services": "application-services";
52
+ "use-cases": "use-cases";
53
+ "execution-commands": "execution-commands";
54
+ "execution-queries": "execution-queries";
55
+ "orchestration-commands": "orchestration-commands";
56
+ "orchestration-queries": "orchestration-queries";
57
+ "infrastructure-services": "infrastructure-services";
58
+ "presentation-services": "presentation-services";
59
+ }>>>;
60
+ remove: z.ZodOptional<z.ZodArray<z.ZodEnum<{
61
+ repositories: "repositories";
62
+ "domain-services": "domain-services";
63
+ "application-ports": "application-ports";
64
+ "application-services": "application-services";
65
+ "use-cases": "use-cases";
66
+ "execution-commands": "execution-commands";
67
+ "execution-queries": "execution-queries";
68
+ "orchestration-commands": "orchestration-commands";
69
+ "orchestration-queries": "orchestration-queries";
70
+ "infrastructure-services": "infrastructure-services";
71
+ "presentation-services": "presentation-services";
72
+ }>>>;
73
+ }, z.core.$strip>]>>>;
74
+ lint: z.ZodOptional<z.ZodRecord<z.ZodEnum<{
75
+ "context-isolation": "context-isolation";
76
+ "shared-layer": "shared-layer";
77
+ layers: "layers";
78
+ dependencies: "dependencies";
79
+ react: "react";
80
+ clock: "clock";
81
+ }> & z.core.$partial, z.ZodBoolean>>;
82
+ }, z.core.$strip>>;
16
83
  }, z.core.$strip>;
17
84
  export declare class ConfigFile {
18
85
  readonly data: z.infer<typeof configSchema>;
@@ -22,4 +89,8 @@ export declare class ConfigFile {
22
89
  static get exists(): boolean;
23
90
  static write: (config: z.infer<typeof configSchema>) => void;
24
91
  }
92
+ /**
93
+ * The dependency rules: the defaults with the config's `rules.dependencies`.
94
+ */
95
+ export declare const configuredDependencyRules: () => import("./dependency-rules").DependencyRules;
25
96
  export {};
@@ -0,0 +1,82 @@
1
+ import z from 'zod';
2
+ /**
3
+ * Kinds of modules the dependency rules are written in: the folders
4
+ * under `wiring/`, with commands and queries split by mode.
5
+ */
6
+ export declare const moduleKinds: readonly ["repositories", "domain-services", "application-ports", "application-services", "use-cases", "execution-commands", "execution-queries", "orchestration-commands", "orchestration-queries", "infrastructure-services", "presentation-services"];
7
+ export type ModuleKind = (typeof moduleKinds)[number];
8
+ export type DependencyRules = Record<ModuleKind, ReadonlySet<ModuleKind>>;
9
+ /**
10
+ * What each kind of module may depend on. Repositories, execution
11
+ * commands and queries, and ports are their implementations here.
12
+ */
13
+ export declare const defaultDependencies: Record<ModuleKind, ModuleKind[]>;
14
+ /**
15
+ * A list replaces the default one; `add` and `remove` change it.
16
+ */
17
+ export declare const dependencyRulesSchema: z.ZodRecord<z.ZodEnum<{
18
+ repositories: "repositories";
19
+ "domain-services": "domain-services";
20
+ "application-ports": "application-ports";
21
+ "application-services": "application-services";
22
+ "use-cases": "use-cases";
23
+ "execution-commands": "execution-commands";
24
+ "execution-queries": "execution-queries";
25
+ "orchestration-commands": "orchestration-commands";
26
+ "orchestration-queries": "orchestration-queries";
27
+ "infrastructure-services": "infrastructure-services";
28
+ "presentation-services": "presentation-services";
29
+ }> & z.core.$partial, z.ZodUnion<readonly [z.ZodArray<z.ZodEnum<{
30
+ repositories: "repositories";
31
+ "domain-services": "domain-services";
32
+ "application-ports": "application-ports";
33
+ "application-services": "application-services";
34
+ "use-cases": "use-cases";
35
+ "execution-commands": "execution-commands";
36
+ "execution-queries": "execution-queries";
37
+ "orchestration-commands": "orchestration-commands";
38
+ "orchestration-queries": "orchestration-queries";
39
+ "infrastructure-services": "infrastructure-services";
40
+ "presentation-services": "presentation-services";
41
+ }>>, z.ZodObject<{
42
+ add: z.ZodOptional<z.ZodArray<z.ZodEnum<{
43
+ repositories: "repositories";
44
+ "domain-services": "domain-services";
45
+ "application-ports": "application-ports";
46
+ "application-services": "application-services";
47
+ "use-cases": "use-cases";
48
+ "execution-commands": "execution-commands";
49
+ "execution-queries": "execution-queries";
50
+ "orchestration-commands": "orchestration-commands";
51
+ "orchestration-queries": "orchestration-queries";
52
+ "infrastructure-services": "infrastructure-services";
53
+ "presentation-services": "presentation-services";
54
+ }>>>;
55
+ remove: z.ZodOptional<z.ZodArray<z.ZodEnum<{
56
+ repositories: "repositories";
57
+ "domain-services": "domain-services";
58
+ "application-ports": "application-ports";
59
+ "application-services": "application-services";
60
+ "use-cases": "use-cases";
61
+ "execution-commands": "execution-commands";
62
+ "execution-queries": "execution-queries";
63
+ "orchestration-commands": "orchestration-commands";
64
+ "orchestration-queries": "orchestration-queries";
65
+ "infrastructure-services": "infrastructure-services";
66
+ "presentation-services": "presentation-services";
67
+ }>>>;
68
+ }, z.core.$strip>]>>;
69
+ export type DependencyRulesConfig = z.infer<typeof dependencyRulesSchema>;
70
+ export declare const resolveDependencyRules: (config?: DependencyRulesConfig) => DependencyRules;
71
+ export declare const defaultDependencyRules: DependencyRules;
72
+ /**
73
+ * The kind of a wired module: its folder under `wiring/`; commands and
74
+ * queries by the folder of their type, `execution/` or `orchestration/`.
75
+ */
76
+ export declare const wiredModuleKind: (wiringKind: string, typeFile: string) => "repositories" | "domain-services" | "application-ports" | "application-services" | "use-cases" | "execution-commands" | "execution-queries" | "orchestration-commands" | "orchestration-queries" | "infrastructure-services" | "presentation-services" | undefined;
77
+ /**
78
+ * The kind of a module file, from its path inside a context or the
79
+ * Shared Layer (`application/use-cases/…`), or undefined for other files
80
+ * such as entities, value objects and errors.
81
+ */
82
+ export declare const fileModuleKind: (segments: string[]) => ModuleKind | undefined;
@@ -0,0 +1 @@
1
+ export {};
package/dist/index.cjs CHANGED
@@ -31,6 +31,105 @@ const external_node_path_namespaceObject = require("node:path");
31
31
  var external_node_path_default = /*#__PURE__*/ __webpack_require__.n(external_node_path_namespaceObject);
32
32
  const external_zod_namespaceObject = require("zod");
33
33
  var external_zod_default = /*#__PURE__*/ __webpack_require__.n(external_zod_namespaceObject);
34
+ const moduleKinds = [
35
+ 'repositories',
36
+ 'domain-services',
37
+ 'application-ports',
38
+ 'application-services',
39
+ 'use-cases',
40
+ 'execution-commands',
41
+ 'execution-queries',
42
+ 'orchestration-commands',
43
+ 'orchestration-queries',
44
+ 'infrastructure-services',
45
+ 'presentation-services'
46
+ ];
47
+ const domain = [
48
+ 'repositories',
49
+ 'domain-services'
50
+ ];
51
+ const commandsAndQueries = [
52
+ 'execution-commands',
53
+ 'execution-queries',
54
+ 'orchestration-commands',
55
+ 'orchestration-queries'
56
+ ];
57
+ const infrastructure = [
58
+ ...domain,
59
+ 'application-ports',
60
+ 'infrastructure-services'
61
+ ];
62
+ const defaultDependencies = {
63
+ 'domain-services': domain,
64
+ repositories: [
65
+ 'domain-services',
66
+ 'application-ports',
67
+ 'infrastructure-services'
68
+ ],
69
+ 'application-ports': infrastructure,
70
+ 'application-services': [
71
+ ...domain,
72
+ 'application-ports'
73
+ ],
74
+ 'use-cases': [
75
+ ...domain,
76
+ 'application-ports',
77
+ 'application-services',
78
+ ...commandsAndQueries
79
+ ],
80
+ 'execution-commands': infrastructure,
81
+ 'execution-queries': infrastructure,
82
+ 'orchestration-commands': [
83
+ ...domain,
84
+ 'execution-commands',
85
+ 'execution-queries'
86
+ ],
87
+ 'orchestration-queries': [
88
+ ...domain,
89
+ 'execution-queries'
90
+ ],
91
+ 'infrastructure-services': infrastructure,
92
+ 'presentation-services': [
93
+ 'application-ports',
94
+ 'application-services',
95
+ 'use-cases',
96
+ ...commandsAndQueries,
97
+ 'presentation-services'
98
+ ]
99
+ };
100
+ const kindSchema = external_zod_default()["enum"](moduleKinds);
101
+ const dependencyRulesSchema = external_zod_default().partialRecord(kindSchema, external_zod_default().union([
102
+ external_zod_default().array(kindSchema),
103
+ external_zod_default().object({
104
+ add: external_zod_default().array(kindSchema).optional(),
105
+ remove: external_zod_default().array(kindSchema).optional()
106
+ })
107
+ ]));
108
+ const resolveDependencyRules = (config = {})=>{
109
+ const entries = moduleKinds.map((kind)=>{
110
+ const override = config[kind];
111
+ if (Array.isArray(override)) return [
112
+ kind,
113
+ new Set(override)
114
+ ];
115
+ const kinds = new Set([
116
+ ...defaultDependencies[kind],
117
+ ...override?.add ?? []
118
+ ]);
119
+ for (const removed of override?.remove ?? [])kinds.delete(removed);
120
+ return [
121
+ kind,
122
+ kinds
123
+ ];
124
+ });
125
+ return Object.fromEntries(entries);
126
+ };
127
+ const defaultDependencyRules = resolveDependencyRules();
128
+ const isModuleKind = (value)=>moduleKinds.includes(value);
129
+ const wiredModuleKind = (wiringKind, typeFile)=>{
130
+ const kind = 'commands' === wiringKind || 'queries' === wiringKind ? `${'execution' === external_node_path_default().basename(external_node_path_default().dirname(typeFile)) ? 'execution' : 'orchestration'}-${wiringKind}` : wiringKind;
131
+ return isModuleKind(kind) ? kind : void 0;
132
+ };
34
133
  const external_node_fs_namespaceObject = require("node:fs");
35
134
  var external_node_fs_default = /*#__PURE__*/ __webpack_require__.n(external_node_fs_namespaceObject);
36
135
  const pendingFiles = new Map();
@@ -182,6 +281,14 @@ class ProjectRoot {
182
281
  throw new Error('No package.json was found');
183
282
  }
184
283
  }
284
+ const lintChecks = [
285
+ 'context-isolation',
286
+ 'shared-layer',
287
+ 'layers',
288
+ 'dependencies',
289
+ 'react',
290
+ 'clock'
291
+ ];
185
292
  const configFileName = 'domain-first.project-structure.config.json';
186
293
  const configSchema = external_zod_default().object({
187
294
  rootFolder: external_zod_default().string(),
@@ -196,7 +303,11 @@ const configSchema = external_zod_default().object({
196
303
  withInMemoryDb: external_zod_default().boolean().optional(),
197
304
  useReact: external_zod_default().boolean(),
198
305
  storybookFramework: external_zod_default().string().optional(),
199
- testingLibrary: external_zod_default().string().optional()
306
+ testingLibrary: external_zod_default().string().optional(),
307
+ rules: external_zod_default().object({
308
+ dependencies: dependencyRulesSchema.optional(),
309
+ lint: external_zod_default().partialRecord(external_zod_default()["enum"](lintChecks), external_zod_default().boolean()).optional()
310
+ }).optional()
200
311
  });
201
312
  class ConfigFile {
202
313
  data;
@@ -220,6 +331,7 @@ class ConfigFile {
220
331
  new File(ConfigFile.path).data = JSON.stringify(config, null, '\t');
221
332
  };
222
333
  }
334
+ const configuredDependencyRules = ()=>resolveDependencyRules(ConfigFile.exists ? ConfigFile.Instance.data.rules?.dependencies : void 0);
223
335
  const external_node_util_namespaceObject = require("node:util");
224
336
  const printNextSteps = (nextSteps)=>{
225
337
  const isCommand = (line)=>/^\s*(?:npm (?:i|install)|npx playwright install)\b/.test(line);
@@ -1462,25 +1574,18 @@ const findWiredModules = (contextPath)=>{
1462
1574
  walk(external_node_path_default().join(contextPath, 'wiring'));
1463
1575
  return result.sort((a, b)=>a.typeName.localeCompare(b.typeName));
1464
1576
  };
1465
- const isCommandOrQuery = (module)=>'commands' === module.kind || 'queries' === module.kind;
1466
- const isExecution = (module)=>isCommandOrQuery(module) && 'execution' === external_node_path_default().basename(external_node_path_default().dirname(module.typeFile));
1467
- const commandOrQueryRule = (candidate, consumer)=>isExecution(consumer) ? !isCommandOrQuery(candidate) : 'application' !== candidate.layer || isExecution(candidate) && ('commands' === consumer.kind || 'queries' === candidate.kind);
1468
- const layerRules = {
1469
- infrastructure: (candidate)=>'application' !== candidate.layer || 'application-ports' === candidate.kind
1470
- };
1471
- const kindRules = {
1472
- 'application-services': (candidate)=>'application' !== candidate.layer || 'application-ports' === candidate.kind,
1473
- 'use-cases': (candidate)=>'use-cases' !== candidate.kind,
1474
- repositories: (candidate)=>'repositories' !== candidate.kind,
1475
- commands: commandOrQueryRule,
1476
- queries: commandOrQueryRule
1477
- };
1577
+ const moduleKindOf = (module)=>wiredModuleKind(module.kind, module.typeFile);
1578
+ const layerRule = (consumer, candidate)=>visibleLayers[consumer.implementationsLayer].includes(candidate.layer) && ('infrastructure' !== consumer.implementationsLayer || 'application' !== candidate.layer || 'application-ports' === candidate.kind);
1478
1579
  const wiring_implementationType = (consumer, implementation)=>consumer.branched ? external_node_path_default().basename(external_node_path_default().dirname(implementation.file)) : void 0;
1479
1580
  const isSuggestedFor = (candidate, implementation)=>'infrastructure' === candidate.layer && `-${external_node_path_default().basename(candidate.typeFile, '.ts')}-`.includes(`-${implementation}-`);
1480
- const canDependOn = (consumer, candidate)=>visibleLayers[consumer.implementationsLayer].includes(candidate.layer) && (layerRules[consumer.implementationsLayer]?.(candidate) ?? true) && (kindRules[consumer.kind]?.(candidate, consumer) ?? true);
1481
- const availableDependencies = (consumer, implementation, candidates)=>{
1581
+ const canDependOn = (consumer, candidate, rules = defaultDependencyRules)=>{
1582
+ const consumerKind = moduleKindOf(consumer);
1583
+ const candidateKind = moduleKindOf(candidate);
1584
+ return consumerKind && candidateKind ? rules[consumerKind].has(candidateKind) : layerRule(consumer, candidate);
1585
+ };
1586
+ const availableDependencies = (consumer, implementation, candidates, rules = configuredDependencyRules())=>{
1482
1587
  const wired = wiredDependencyNames(new File(consumer.wireFile).data, implementation.className);
1483
- return candidates.filter((candidate)=>candidate.wireFile !== consumer.wireFile && canDependOn(consumer, candidate) && !wired.includes(candidate.wireName));
1588
+ return candidates.filter((candidate)=>candidate.wireFile !== consumer.wireFile && canDependOn(consumer, candidate, rules) && !wired.includes(candidate.wireName));
1484
1589
  };
1485
1590
  const relativeImport = (fromFile, toFile)=>{
1486
1591
  const relativePath = external_node_path_default().relative(external_node_path_default().dirname(fromFile), toFile).replace(/\.ts$/, '').split(external_node_path_default().sep).join('/');
package/dist/index.js CHANGED
@@ -3,7 +3,7 @@ import { Separator, checkbox as prompts_checkbox, confirm as prompts_confirm, in
3
3
  import { styleText } from "node:util";
4
4
  import node_path from "node:path";
5
5
  import node_fs from "node:fs";
6
- import { addImport, availableDependencies, discardPendingChanges, findWiredModules, UnknownFormatNaming, Folder, writePendingChanges, stripJsonComments, readWiredModule, addClassMember, addWireDependencies, addConstructorParameters, filesToOverwrite, ConfigFile, relativeImport, wireDependencies, File, ProjectRoot, implementationType as wiring_implementationType, compilerOption, isSuggestedFor } from "./533.js";
6
+ import { addImport, availableDependencies, discardPendingChanges, findWiredModules, UnknownFormatNaming, Folder, writePendingChanges, stripJsonComments, readWiredModule, addClassMember, addWireDependencies, addConstructorParameters, filesToOverwrite, ConfigFile, relativeImport, wireDependencies, File, ProjectRoot, implementationType as wiring_implementationType, compilerOption, isSuggestedFor } from "./201.js";
7
7
  const printNextSteps = (nextSteps)=>{
8
8
  const isCommand = (line)=>/^\s*(?:npm (?:i|install)|npx playwright install)\b/.test(line);
9
9
  const commands = nextSteps.filter(isCommand);
package/dist/lint.cjs CHANGED
@@ -31,6 +31,130 @@ const external_node_path_namespaceObject = require("node:path");
31
31
  var external_node_path_default = /*#__PURE__*/ __webpack_require__.n(external_node_path_namespaceObject);
32
32
  const external_zod_namespaceObject = require("zod");
33
33
  var external_zod_default = /*#__PURE__*/ __webpack_require__.n(external_zod_namespaceObject);
34
+ const moduleKinds = [
35
+ 'repositories',
36
+ 'domain-services',
37
+ 'application-ports',
38
+ 'application-services',
39
+ 'use-cases',
40
+ 'execution-commands',
41
+ 'execution-queries',
42
+ 'orchestration-commands',
43
+ 'orchestration-queries',
44
+ 'infrastructure-services',
45
+ 'presentation-services'
46
+ ];
47
+ const domain = [
48
+ 'repositories',
49
+ 'domain-services'
50
+ ];
51
+ const commandsAndQueries = [
52
+ 'execution-commands',
53
+ 'execution-queries',
54
+ 'orchestration-commands',
55
+ 'orchestration-queries'
56
+ ];
57
+ const infrastructure = [
58
+ ...domain,
59
+ 'application-ports',
60
+ 'infrastructure-services'
61
+ ];
62
+ const defaultDependencies = {
63
+ 'domain-services': domain,
64
+ repositories: [
65
+ 'domain-services',
66
+ 'application-ports',
67
+ 'infrastructure-services'
68
+ ],
69
+ 'application-ports': infrastructure,
70
+ 'application-services': [
71
+ ...domain,
72
+ 'application-ports'
73
+ ],
74
+ 'use-cases': [
75
+ ...domain,
76
+ 'application-ports',
77
+ 'application-services',
78
+ ...commandsAndQueries
79
+ ],
80
+ 'execution-commands': infrastructure,
81
+ 'execution-queries': infrastructure,
82
+ 'orchestration-commands': [
83
+ ...domain,
84
+ 'execution-commands',
85
+ 'execution-queries'
86
+ ],
87
+ 'orchestration-queries': [
88
+ ...domain,
89
+ 'execution-queries'
90
+ ],
91
+ 'infrastructure-services': infrastructure,
92
+ 'presentation-services': [
93
+ 'application-ports',
94
+ 'application-services',
95
+ 'use-cases',
96
+ ...commandsAndQueries,
97
+ 'presentation-services'
98
+ ]
99
+ };
100
+ const kindSchema = external_zod_default()["enum"](moduleKinds);
101
+ const dependencyRulesSchema = external_zod_default().partialRecord(kindSchema, external_zod_default().union([
102
+ external_zod_default().array(kindSchema),
103
+ external_zod_default().object({
104
+ add: external_zod_default().array(kindSchema).optional(),
105
+ remove: external_zod_default().array(kindSchema).optional()
106
+ })
107
+ ]));
108
+ const resolveDependencyRules = (config = {})=>{
109
+ const entries = moduleKinds.map((kind)=>{
110
+ const override = config[kind];
111
+ if (Array.isArray(override)) return [
112
+ kind,
113
+ new Set(override)
114
+ ];
115
+ const kinds = new Set([
116
+ ...defaultDependencies[kind],
117
+ ...override?.add ?? []
118
+ ]);
119
+ for (const removed of override?.remove ?? [])kinds.delete(removed);
120
+ return [
121
+ kind,
122
+ kinds
123
+ ];
124
+ });
125
+ return Object.fromEntries(entries);
126
+ };
127
+ const defaultDependencyRules = resolveDependencyRules();
128
+ const isModuleKind = (value)=>moduleKinds.includes(value);
129
+ const wiredModuleKind = (wiringKind, typeFile)=>{
130
+ const kind = 'commands' === wiringKind || 'queries' === wiringKind ? `${'execution' === external_node_path_default().basename(external_node_path_default().dirname(typeFile)) ? 'execution' : 'orchestration'}-${wiringKind}` : wiringKind;
131
+ return isModuleKind(kind) ? kind : void 0;
132
+ };
133
+ const fileModuleKind = (segments)=>{
134
+ const [layer, folder, mode] = segments;
135
+ const file = segments.at(-1) ?? '';
136
+ if (/^index(\.tsx?)?$/.test(file)) return;
137
+ if ('domain' === layer) {
138
+ if ('services' === folder) return 'domain-services';
139
+ return 'aggregates' === folder && /-repository(\.tsx?)?$/.test(file) ? 'repositories' : void 0;
140
+ }
141
+ if ('application' === layer) {
142
+ if ('commands' === folder || 'queries' === folder) return 'execution' === mode || 'orchestration' === mode ? `${mode}-${folder}` : void 0;
143
+ return ({
144
+ ports: 'application-ports',
145
+ services: 'application-services',
146
+ 'use-cases': 'use-cases'
147
+ })[folder];
148
+ }
149
+ if ('infrastructure' === layer) return ({
150
+ repositories: 'repositories',
151
+ commands: 'execution-commands',
152
+ queries: 'execution-queries',
153
+ 'application-adapters': 'application-ports',
154
+ services: 'infrastructure-services'
155
+ })[folder];
156
+ return 'presentation' === layer && 'services' === folder ? 'presentation-services' : void 0;
157
+ };
34
158
  const external_node_fs_namespaceObject = require("node:fs");
35
159
  var external_node_fs_default = /*#__PURE__*/ __webpack_require__.n(external_node_fs_namespaceObject);
36
160
  const pendingFiles = new Map();
@@ -107,6 +231,14 @@ class ProjectRoot {
107
231
  throw new Error('No package.json was found');
108
232
  }
109
233
  }
234
+ const lintChecks = [
235
+ 'context-isolation',
236
+ 'shared-layer',
237
+ 'layers',
238
+ 'dependencies',
239
+ 'react',
240
+ 'clock'
241
+ ];
110
242
  const configFileName = 'domain-first.project-structure.config.json';
111
243
  const configSchema = external_zod_default().object({
112
244
  rootFolder: external_zod_default().string(),
@@ -121,7 +253,11 @@ const configSchema = external_zod_default().object({
121
253
  withInMemoryDb: external_zod_default().boolean().optional(),
122
254
  useReact: external_zod_default().boolean(),
123
255
  storybookFramework: external_zod_default().string().optional(),
124
- testingLibrary: external_zod_default().string().optional()
256
+ testingLibrary: external_zod_default().string().optional(),
257
+ rules: external_zod_default().object({
258
+ dependencies: dependencyRulesSchema.optional(),
259
+ lint: external_zod_default().partialRecord(external_zod_default()["enum"](lintChecks), external_zod_default().boolean()).optional()
260
+ }).optional()
125
261
  });
126
262
  class ConfigFile {
127
263
  data;
@@ -145,6 +281,7 @@ class ConfigFile {
145
281
  new file_system_File(ConfigFile.path).data = JSON.stringify(config, null, '\t');
146
282
  };
147
283
  }
284
+ const config_file_configuredDependencyRules = ()=>resolveDependencyRules(ConfigFile.exists ? ConfigFile.Instance.data.rules?.dependencies : void 0);
148
285
  const external_node_module_namespaceObject = require("node:module");
149
286
  const stripJsonComments = (source)=>source.replace(/("(?:\\.|[^"\\])*")|\/\/[^\n]*|\/\*[\s\S]*?\*\//g, (_, text)=>text ? text : '').replace(/,(\s*[}\]])/g, '$1');
150
287
  const resolveExtends = (fromFile, target)=>{
@@ -342,20 +479,13 @@ const findWiredModules = (contextPath)=>{
342
479
  walk(external_node_path_default().join(contextPath, 'wiring'));
343
480
  return result.sort((a, b)=>a.typeName.localeCompare(b.typeName));
344
481
  };
345
- const isCommandOrQuery = (module)=>'commands' === module.kind || 'queries' === module.kind;
346
- const isExecution = (module)=>isCommandOrQuery(module) && 'execution' === external_node_path_default().basename(external_node_path_default().dirname(module.typeFile));
347
- const commandOrQueryRule = (candidate, consumer)=>isExecution(consumer) ? !isCommandOrQuery(candidate) : 'application' !== candidate.layer || isExecution(candidate) && ('commands' === consumer.kind || 'queries' === candidate.kind);
348
- const layerRules = {
349
- infrastructure: (candidate)=>'application' !== candidate.layer || 'application-ports' === candidate.kind
350
- };
351
- const kindRules = {
352
- 'application-services': (candidate)=>'application' !== candidate.layer || 'application-ports' === candidate.kind,
353
- 'use-cases': (candidate)=>'use-cases' !== candidate.kind,
354
- repositories: (candidate)=>'repositories' !== candidate.kind,
355
- commands: commandOrQueryRule,
356
- queries: commandOrQueryRule
482
+ const moduleKindOf = (module)=>wiredModuleKind(module.kind, module.typeFile);
483
+ const wiring_layerRule = (consumer, candidate)=>visibleLayers[consumer.implementationsLayer].includes(candidate.layer) && ('infrastructure' !== consumer.implementationsLayer || 'application' !== candidate.layer || 'application-ports' === candidate.kind);
484
+ const canDependOn = (consumer, candidate, rules = defaultDependencyRules)=>{
485
+ const consumerKind = moduleKindOf(consumer);
486
+ const candidateKind = moduleKindOf(candidate);
487
+ return consumerKind && candidateKind ? rules[consumerKind].has(candidateKind) : wiring_layerRule(consumer, candidate);
357
488
  };
358
- const canDependOn = (consumer, candidate)=>visibleLayers[consumer.implementationsLayer].includes(candidate.layer) && (layerRules[consumer.implementationsLayer]?.(candidate) ?? true) && (kindRules[consumer.kind]?.(candidate, consumer) ?? true);
359
489
  const codeOnly = (source)=>{
360
490
  let result = '';
361
491
  let index = 0;
@@ -501,12 +631,9 @@ const layerImportRules = {
501
631
  rule: 'presentation imports infrastructure (only wiring knows concrete classes):'
502
632
  }
503
633
  };
504
- const isKindFile = (segments, kind)=>Boolean(segments && [
505
- 'application',
506
- 'infrastructure',
507
- 'wiring'
508
- ].includes(segments[0]) && segments[1] === kind);
509
- const importViolations = (projectRoot, rootFolder)=>{
634
+ const baseName = (file)=>external_node_path_default().basename(file).replace(/\.[^.]+$/, '');
635
+ const isOwnContract = (file, target)=>baseName(file).endsWith(`-${baseName(target)}`);
636
+ const importViolations = (projectRoot, rootFolder, rules)=>{
510
637
  const root = external_node_path_default().resolve(projectRoot, rootFolder);
511
638
  const contextsFolder = external_node_path_default().join(root, 'bounded-contexts');
512
639
  const sharedFolder = external_node_path_default().join(root, 'shared');
@@ -554,7 +681,8 @@ const importViolations = (projectRoot, rootFolder)=>{
554
681
  const source = external_node_fs_default().readFileSync(file, 'utf8');
555
682
  const from = locate(file);
556
683
  const ownContext = inside(contextsFolder, file)?.[0];
557
- const report = (rule, imported)=>violations.push({
684
+ const report = (check, rule, imported)=>violations.push({
685
+ check,
558
686
  rule,
559
687
  file,
560
688
  line: imported.line,
@@ -566,10 +694,10 @@ const importViolations = (projectRoot, rootFolder)=>{
566
694
  const to = locate(target);
567
695
  const targetContext = inside(contextsFolder, target)?.[0];
568
696
  if (ownContext) {
569
- if (targetContext && targetContext !== ownContext) report(`[${ownContext}] imports another context:`, imported);
697
+ if (targetContext && targetContext !== ownContext) report('context-isolation', `[${ownContext}] imports another context:`, imported);
570
698
  } else if (inside(sharedFolder, file)) {
571
699
  const allowed = !to || 'shared' === to.owner || 'domain' === to.segments[0] && 'errors' === to.segments[1] || file === inMemoryDbFile && isDomainModel(to.segments, target);
572
- if (!allowed) report('[shared] imports a bounded context outside its domain/errors (and domain models for the in-memory DB):', imported);
700
+ if (!allowed) report('shared-layer', '[shared] imports a bounded context outside its domain/errors (and domain models for the in-memory DB):', imported);
573
701
  } else if (inside(uiKitFolder, file) || inside(hooksFolder, file)) {
574
702
  const [area] = inside(reactFolder, target) ?? [];
575
703
  const forbidden = inside(uiKitFolder, file) ? [
@@ -580,20 +708,26 @@ const importViolations = (projectRoot, rootFolder)=>{
580
708
  'widgets',
581
709
  'pages'
582
710
  ];
583
- if (targetContext || forbidden.includes(area)) report(inside(uiKitFolder, file) ? '[presentation/react/ui-kit] imports a bounded context, widget or page:' : '[presentation/react/hooks] a shared hook imports a bounded context, UI-kit, widget or page:', imported);
584
- } else if (targetContext && !(imported.typeOnly && to?.segments[0] === 'presentation' && 'rest' === to.segments[1])) report('[presentation/react] imports a context other than `import type` from presentation/rest:', imported);
711
+ if (targetContext || forbidden.includes(area)) report('react', inside(uiKitFolder, file) ? '[presentation/react/ui-kit] imports a bounded context, widget or page:' : '[presentation/react/hooks] a shared hook imports a bounded context, UI-kit, widget or page:', imported);
712
+ } else if (targetContext && !(imported.typeOnly && to?.segments[0] === 'presentation' && 'rest' === to.segments[1])) report('react', '[presentation/react] imports a context other than `import type` from presentation/rest:', imported);
585
713
  const ownWidget = widgetOf(file);
586
714
  const targetWidget = widgetOf(target);
587
- if (ownWidget && targetWidget && targetWidget !== ownWidget) report('[presentation/react/widgets] a widget imports another widget:', imported);
715
+ if (ownWidget && targetWidget && targetWidget !== ownWidget) report('react', '[presentation/react/widgets] a widget imports another widget:', imported);
588
716
  if (!from || !to) continue;
589
- if (to.owner === from.owner && isKindFile(from.segments, 'queries') && isKindFile(to.segments, 'commands')) report(`[${from.owner}] a query imports a command (queries only read):`, imported);
717
+ if (isSpec(file)) continue;
718
+ const fromKind = fileModuleKind(from.segments);
719
+ const toKind = fileModuleKind(to.segments);
720
+ if (fromKind && toKind) {
721
+ if (!rules[fromKind].has(toKind) && !(fromKind === toKind && isOwnContract(file, target))) report('dependencies', `[${from.owner}] ${fromKind} may not use ${toKind} (dependency rules):`, imported);
722
+ if ('infrastructure' !== to.segments[0]) continue;
723
+ }
590
724
  const layerRule = layerImportRules[from.segments[0]];
591
- if (layerRule && !isSpec(file) && !layerRule.allows(to.segments)) report(`[${from.owner}] ${layerRule.rule}`, imported);
725
+ if (layerRule && !layerRule.allows(to.segments)) report('layers', `[${from.owner}] ${layerRule.rule}`, imported);
592
726
  }
593
727
  }
594
728
  return violations;
595
729
  };
596
- const wiringViolations = (projectRoot, rootFolder)=>{
730
+ const wiringViolations = (projectRoot, rootFolder, rules)=>{
597
731
  const root = external_node_path_default().resolve(projectRoot, rootFolder);
598
732
  const sharedFolder = external_node_path_default().join(root, 'shared');
599
733
  const contextsFolder = external_node_path_default().join(root, 'bounded-contexts');
@@ -631,13 +765,14 @@ const wiringViolations = (projectRoot, rootFolder)=>{
631
765
  const listStart = source.search(new RegExp(`wireClass\\(\\s*${implementation.className}\\b`));
632
766
  for (const dependency of dependencies){
633
767
  const candidate = visible.get(dependency);
634
- if (!candidate || canDependOn(consumer, candidate)) continue;
768
+ if (!candidate || canDependOn(consumer, candidate, rules)) continue;
635
769
  const index = source.indexOf(dependency, listStart);
636
770
  violations.push({
637
- rule: `[${name}] wiring: a dependency the CLI never offers (layer or kind rules):`,
771
+ check: 'dependencies',
772
+ rule: `[${name}] wiring: a dependency the dependency rules don't allow:`,
638
773
  file: consumer.wireFile,
639
774
  line: lineAt(source, index),
640
- text: `${implementation.className} ← ${candidate.typeName} (${candidate.kind})`
775
+ text: `${implementation.className} (${moduleKindOf(consumer) ?? consumer.kind}) ← ${candidate.typeName} (${moduleKindOf(candidate) ?? candidate.kind})`
641
776
  });
642
777
  }
643
778
  }
@@ -659,6 +794,7 @@ const clockViolations = (projectRoot, rootFolder)=>{
659
794
  return [
660
795
  ...source.matchAll(/\bnew\s+Date\s*\(\s*\)|\bDate\.now\s*\(/g)
661
796
  ].map((match)=>({
797
+ check: 'clock',
662
798
  rule: 'domain or application reads the current time directly (use the clock port):',
663
799
  file,
664
800
  line: lineAt(source, match.index),
@@ -666,11 +802,11 @@ const clockViolations = (projectRoot, rootFolder)=>{
666
802
  }));
667
803
  });
668
804
  };
669
- const lintProject = (projectRoot, rootFolder)=>[
670
- ...importViolations(projectRoot, rootFolder),
671
- ...wiringViolations(projectRoot, rootFolder),
805
+ const lintProject = (projectRoot, rootFolder, { rules = defaultDependencyRules, checks = {} } = {})=>[
806
+ ...importViolations(projectRoot, rootFolder, rules),
807
+ ...wiringViolations(projectRoot, rootFolder, rules),
672
808
  ...clockViolations(projectRoot, rootFolder)
673
- ];
809
+ ].filter((x)=>false !== checks[x.check]);
674
810
  const formatViolations = (violations, projectRoot)=>{
675
811
  const groups = new Map();
676
812
  for (const { rule, file, line, text } of violations)groups.set(rule, [
@@ -687,9 +823,10 @@ const formatViolations = (violations, projectRoot)=>{
687
823
  const help = `Usage: df-lint [rootFolder]
688
824
 
689
825
  Reports what breaks the Domain-First rules in the project:
690
- bounded context isolation, layers, wiring dependencies, React modules,
691
- queries using commands, and reading the time without the clock port.
692
- rootFolder defaults to the one in domain-first.project-structure.config.json.
826
+ bounded context isolation, layers, dependency rules (imports and wiring),
827
+ React modules, and reading the time without the clock port.
828
+ rootFolder defaults to the one in domain-first.project-structure.config.json,
829
+ whose optional \`rules\` change the dependency rules and turn checks off.
693
830
  Exits with 1 when something is found.
694
831
 
695
832
  Options:
@@ -709,8 +846,12 @@ if (values.help) {
709
846
  process.exit(0);
710
847
  }
711
848
  const lint_projectRoot = new ProjectRoot().path;
712
- const lint_rootFolder = positionals[0] ?? (ConfigFile.exists ? ConfigFile.Instance.data.rootFolder : 'src');
713
- const lint_violations = lintProject(lint_projectRoot, lint_rootFolder);
849
+ const lint_config = ConfigFile.exists ? ConfigFile.Instance.data : void 0;
850
+ const lint_rootFolder = positionals[0] ?? lint_config?.rootFolder ?? 'src';
851
+ const lint_violations = lintProject(lint_projectRoot, lint_rootFolder, {
852
+ rules: config_file_configuredDependencyRules(),
853
+ checks: lint_config?.rules?.lint
854
+ });
714
855
  if (lint_violations.length) {
715
856
  console.log(formatViolations(lint_violations, lint_projectRoot));
716
857
  console.log(`\n${lint_violations.length} problem(s) found.`);
package/dist/lint.js CHANGED
@@ -2,7 +2,7 @@
2
2
  import { parseArgs } from "node:util";
3
3
  import node_fs from "node:fs";
4
4
  import node_path from "node:path";
5
- import { ConfigFile, canDependOn, ProjectRoot, findWiredModules, compilerOption, wiredDependencyNames } from "./533.js";
5
+ import { defaultDependencyRules, fileModuleKind, canDependOn, moduleKindOf, findWiredModules, configuredDependencyRules, ConfigFile, ProjectRoot, compilerOption, wiredDependencyNames } from "./201.js";
6
6
  const readAliases = (projectRoot)=>{
7
7
  const tsconfig = node_path.join(projectRoot, 'tsconfig.json');
8
8
  const paths = compilerOption(tsconfig, 'paths');
@@ -67,12 +67,9 @@ const layerImportRules = {
67
67
  rule: 'presentation imports infrastructure (only wiring knows concrete classes):'
68
68
  }
69
69
  };
70
- const isKindFile = (segments, kind)=>Boolean(segments && [
71
- 'application',
72
- 'infrastructure',
73
- 'wiring'
74
- ].includes(segments[0]) && segments[1] === kind);
75
- const importViolations = (projectRoot, rootFolder)=>{
70
+ const baseName = (file)=>node_path.basename(file).replace(/\.[^.]+$/, '');
71
+ const isOwnContract = (file, target)=>baseName(file).endsWith(`-${baseName(target)}`);
72
+ const importViolations = (projectRoot, rootFolder, rules)=>{
76
73
  const root = node_path.resolve(projectRoot, rootFolder);
77
74
  const contextsFolder = node_path.join(root, 'bounded-contexts');
78
75
  const sharedFolder = node_path.join(root, 'shared');
@@ -120,7 +117,8 @@ const importViolations = (projectRoot, rootFolder)=>{
120
117
  const source = node_fs.readFileSync(file, 'utf8');
121
118
  const from = locate(file);
122
119
  const ownContext = inside(contextsFolder, file)?.[0];
123
- const report = (rule, imported)=>violations.push({
120
+ const report = (check, rule, imported)=>violations.push({
121
+ check,
124
122
  rule,
125
123
  file,
126
124
  line: imported.line,
@@ -132,10 +130,10 @@ const importViolations = (projectRoot, rootFolder)=>{
132
130
  const to = locate(target);
133
131
  const targetContext = inside(contextsFolder, target)?.[0];
134
132
  if (ownContext) {
135
- if (targetContext && targetContext !== ownContext) report(`[${ownContext}] imports another context:`, imported);
133
+ if (targetContext && targetContext !== ownContext) report('context-isolation', `[${ownContext}] imports another context:`, imported);
136
134
  } else if (inside(sharedFolder, file)) {
137
135
  const allowed = !to || 'shared' === to.owner || 'domain' === to.segments[0] && 'errors' === to.segments[1] || file === inMemoryDbFile && isDomainModel(to.segments, target);
138
- if (!allowed) report('[shared] imports a bounded context outside its domain/errors (and domain models for the in-memory DB):', imported);
136
+ if (!allowed) report('shared-layer', '[shared] imports a bounded context outside its domain/errors (and domain models for the in-memory DB):', imported);
139
137
  } else if (inside(uiKitFolder, file) || inside(hooksFolder, file)) {
140
138
  const [area] = inside(reactFolder, target) ?? [];
141
139
  const forbidden = inside(uiKitFolder, file) ? [
@@ -146,20 +144,26 @@ const importViolations = (projectRoot, rootFolder)=>{
146
144
  'widgets',
147
145
  'pages'
148
146
  ];
149
- if (targetContext || forbidden.includes(area)) report(inside(uiKitFolder, file) ? '[presentation/react/ui-kit] imports a bounded context, widget or page:' : '[presentation/react/hooks] a shared hook imports a bounded context, UI-kit, widget or page:', imported);
150
- } else if (targetContext && !(imported.typeOnly && to?.segments[0] === 'presentation' && 'rest' === to.segments[1])) report('[presentation/react] imports a context other than `import type` from presentation/rest:', imported);
147
+ if (targetContext || forbidden.includes(area)) report('react', inside(uiKitFolder, file) ? '[presentation/react/ui-kit] imports a bounded context, widget or page:' : '[presentation/react/hooks] a shared hook imports a bounded context, UI-kit, widget or page:', imported);
148
+ } else if (targetContext && !(imported.typeOnly && to?.segments[0] === 'presentation' && 'rest' === to.segments[1])) report('react', '[presentation/react] imports a context other than `import type` from presentation/rest:', imported);
151
149
  const ownWidget = widgetOf(file);
152
150
  const targetWidget = widgetOf(target);
153
- if (ownWidget && targetWidget && targetWidget !== ownWidget) report('[presentation/react/widgets] a widget imports another widget:', imported);
151
+ if (ownWidget && targetWidget && targetWidget !== ownWidget) report('react', '[presentation/react/widgets] a widget imports another widget:', imported);
154
152
  if (!from || !to) continue;
155
- if (to.owner === from.owner && isKindFile(from.segments, 'queries') && isKindFile(to.segments, 'commands')) report(`[${from.owner}] a query imports a command (queries only read):`, imported);
153
+ if (isSpec(file)) continue;
154
+ const fromKind = fileModuleKind(from.segments);
155
+ const toKind = fileModuleKind(to.segments);
156
+ if (fromKind && toKind) {
157
+ if (!rules[fromKind].has(toKind) && !(fromKind === toKind && isOwnContract(file, target))) report('dependencies', `[${from.owner}] ${fromKind} may not use ${toKind} (dependency rules):`, imported);
158
+ if ('infrastructure' !== to.segments[0]) continue;
159
+ }
156
160
  const layerRule = layerImportRules[from.segments[0]];
157
- if (layerRule && !isSpec(file) && !layerRule.allows(to.segments)) report(`[${from.owner}] ${layerRule.rule}`, imported);
161
+ if (layerRule && !layerRule.allows(to.segments)) report('layers', `[${from.owner}] ${layerRule.rule}`, imported);
158
162
  }
159
163
  }
160
164
  return violations;
161
165
  };
162
- const wiringViolations = (projectRoot, rootFolder)=>{
166
+ const wiringViolations = (projectRoot, rootFolder, rules)=>{
163
167
  const root = node_path.resolve(projectRoot, rootFolder);
164
168
  const sharedFolder = node_path.join(root, 'shared');
165
169
  const contextsFolder = node_path.join(root, 'bounded-contexts');
@@ -197,13 +201,14 @@ const wiringViolations = (projectRoot, rootFolder)=>{
197
201
  const listStart = source.search(new RegExp(`wireClass\\(\\s*${implementation.className}\\b`));
198
202
  for (const dependency of dependencies){
199
203
  const candidate = visible.get(dependency);
200
- if (!candidate || canDependOn(consumer, candidate)) continue;
204
+ if (!candidate || canDependOn(consumer, candidate, rules)) continue;
201
205
  const index = source.indexOf(dependency, listStart);
202
206
  violations.push({
203
- rule: `[${name}] wiring: a dependency the CLI never offers (layer or kind rules):`,
207
+ check: 'dependencies',
208
+ rule: `[${name}] wiring: a dependency the dependency rules don't allow:`,
204
209
  file: consumer.wireFile,
205
210
  line: lineAt(source, index),
206
- text: `${implementation.className} ← ${candidate.typeName} (${candidate.kind})`
211
+ text: `${implementation.className} (${moduleKindOf(consumer) ?? consumer.kind}) ← ${candidate.typeName} (${moduleKindOf(candidate) ?? candidate.kind})`
207
212
  });
208
213
  }
209
214
  }
@@ -225,6 +230,7 @@ const clockViolations = (projectRoot, rootFolder)=>{
225
230
  return [
226
231
  ...source.matchAll(/\bnew\s+Date\s*\(\s*\)|\bDate\.now\s*\(/g)
227
232
  ].map((match)=>({
233
+ check: 'clock',
228
234
  rule: 'domain or application reads the current time directly (use the clock port):',
229
235
  file,
230
236
  line: lineAt(source, match.index),
@@ -232,11 +238,11 @@ const clockViolations = (projectRoot, rootFolder)=>{
232
238
  }));
233
239
  });
234
240
  };
235
- const lintProject = (projectRoot, rootFolder)=>[
236
- ...importViolations(projectRoot, rootFolder),
237
- ...wiringViolations(projectRoot, rootFolder),
241
+ const lintProject = (projectRoot, rootFolder, { rules = defaultDependencyRules, checks = {} } = {})=>[
242
+ ...importViolations(projectRoot, rootFolder, rules),
243
+ ...wiringViolations(projectRoot, rootFolder, rules),
238
244
  ...clockViolations(projectRoot, rootFolder)
239
- ];
245
+ ].filter((x)=>false !== checks[x.check]);
240
246
  const formatViolations = (violations, projectRoot)=>{
241
247
  const groups = new Map();
242
248
  for (const { rule, file, line, text } of violations)groups.set(rule, [
@@ -253,9 +259,10 @@ const formatViolations = (violations, projectRoot)=>{
253
259
  const help = `Usage: df-lint [rootFolder]
254
260
 
255
261
  Reports what breaks the Domain-First rules in the project:
256
- bounded context isolation, layers, wiring dependencies, React modules,
257
- queries using commands, and reading the time without the clock port.
258
- rootFolder defaults to the one in domain-first.project-structure.config.json.
262
+ bounded context isolation, layers, dependency rules (imports and wiring),
263
+ React modules, and reading the time without the clock port.
264
+ rootFolder defaults to the one in domain-first.project-structure.config.json,
265
+ whose optional \`rules\` change the dependency rules and turn checks off.
259
266
  Exits with 1 when something is found.
260
267
 
261
268
  Options:
@@ -275,8 +282,12 @@ if (values.help) {
275
282
  process.exit(0);
276
283
  }
277
284
  const lint_projectRoot = new ProjectRoot().path;
278
- const lint_rootFolder = positionals[0] ?? (ConfigFile.exists ? ConfigFile.Instance.data.rootFolder : 'src');
279
- const lint_violations = lintProject(lint_projectRoot, lint_rootFolder);
285
+ const config = ConfigFile.exists ? ConfigFile.Instance.data : void 0;
286
+ const lint_rootFolder = positionals[0] ?? config?.rootFolder ?? 'src';
287
+ const lint_violations = lintProject(lint_projectRoot, lint_rootFolder, {
288
+ rules: configuredDependencyRules(),
289
+ checks: config?.rules?.lint
290
+ });
280
291
  if (lint_violations.length) {
281
292
  console.log(formatViolations(lint_violations, lint_projectRoot));
282
293
  console.log(`\n${lint_violations.length} problem(s) found.`);
@@ -1,4 +1,10 @@
1
+ import type { LintCheck } from './config-file';
2
+ import { type DependencyRules } from './dependency-rules';
1
3
  export type Violation = {
4
+ /**
5
+ * The check that found it, which `rules.lint` can turn off.
6
+ */
7
+ check: LintCheck;
2
8
  /**
3
9
  * The broken rule, as printed above its violations.
4
10
  */
@@ -7,7 +13,14 @@ export type Violation = {
7
13
  line: number;
8
14
  text: string;
9
15
  };
10
- export declare const lintProject: (projectRoot: string, rootFolder: string) => Violation[];
16
+ export type LintOptions = {
17
+ rules?: DependencyRules;
18
+ /**
19
+ * Checks turned off with `false`; the others run.
20
+ */
21
+ checks?: Partial<Record<LintCheck, boolean>>;
22
+ };
23
+ export declare const lintProject: (projectRoot: string, rootFolder: string, { rules, checks }?: LintOptions) => Violation[];
11
24
  /**
12
25
  * Violations grouped under their rules, with paths from the project root.
13
26
  */
package/dist/wiring.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import { type DependencyRules } from './dependency-rules';
1
2
  export declare const layers: readonly ["domain", "application", "infrastructure", "presentation"];
2
3
  export type Layer = (typeof layers)[number];
3
4
  /**
@@ -43,6 +44,10 @@ export type WiredModule = {
43
44
  };
44
45
  export declare const readWiredModule: (wireFile: string, contextPath: string) => WiredModule | undefined;
45
46
  export declare const findWiredModules: (contextPath: string) => WiredModule[];
47
+ /**
48
+ * The kind a module has in the dependency rules.
49
+ */
50
+ export declare const moduleKindOf: (module: WiredModule) => "repositories" | "domain-services" | "application-ports" | "application-services" | "use-cases" | "execution-commands" | "execution-queries" | "orchestration-commands" | "orchestration-queries" | "infrastructure-services" | "presentation-services" | undefined;
46
51
  /**
47
52
  * The implementation label of a branched wire's class, taken from its
48
53
  * folder: `infrastructure/repositories/prisma/…` → `prisma`.
@@ -53,13 +58,13 @@ export declare const implementationType: (consumer: WiredModule, implementation:
53
58
  * as whole words: `in-memory-db-infrastructure-service` for `in-memory`.
54
59
  */
55
60
  export declare const isSuggestedFor: (candidate: WiredModule, implementation: string) => boolean;
56
- export declare const canDependOn: (consumer: WiredModule, candidate: WiredModule) => boolean;
61
+ export declare const canDependOn: (consumer: WiredModule, candidate: WiredModule, rules?: DependencyRules) => boolean;
57
62
  /**
58
- * What an implementation of the consumer can depend on: modules of the
59
- * visible layers, except the consumer and what this implementation
60
- * already depends on.
63
+ * What an implementation of the consumer can depend on by the project's
64
+ * rules, except the consumer and what this implementation already
65
+ * depends on.
61
66
  */
62
- export declare const availableDependencies: (consumer: WiredModule, implementation: WiredClass, candidates: WiredModule[]) => WiredModule[];
67
+ export declare const availableDependencies: (consumer: WiredModule, implementation: WiredClass, candidates: WiredModule[], rules?: DependencyRules) => WiredModule[];
63
68
  /**
64
69
  * Import path without extension, always starting with `./` or `../`.
65
70
  */
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": "4.1.0",
4
+ "version": "4.2.0",
5
5
  "type": "module",
6
6
  "repository": {
7
7
  "type": "git",
@@ -15,6 +15,7 @@ Generated files contain placeholders: empty classes, `{}` schemas, `[]` dependen
15
15
  - Constructors take abstractions (`OrderRepository`, abstract `PlaceOrderCommand`, port `PaymentGateway`), never `PrismaOrderRepository`.
16
16
  - Implementation order: domain → application → schema tool runs (migrations, only if infrastructure needs data the database lacks) → infrastructure (repositories, execution commands/queries, adapters) → endpoints → other tool runs (OpenAPI, API client) → React. Widgets need the regenerated client. How to run tools and handle their output: the project's scripts skill (`project-scripts`), if there is one.
17
17
  - Run the project's tsc/lint/tests after each component.
18
+ - What each kind of module may use follows the defaults in these skills unless `rules.dependencies` in the config changes them; then follow the config, in imports as well as in wiring.
18
19
 
19
20
  ## Bounded context isolation
20
21
 
@@ -38,12 +39,11 @@ Run it from the project root; `rootFolder` defaults to the config's. It resolves
38
39
 
39
40
  - imports across contexts, and from `shared/` or React outside the exceptions above;
40
41
  - imports against the layers ("Ground rules"; specs excluded);
42
+ - module files importing kinds the project's dependency rules don't allow (a use case importing a use case, a query importing a command, …), and wired dependencies they don't allow ("Wiring" below, `df-ps-scaffold` rule 3); an implementation importing its own contract is fine;
41
43
  - a widget importing another widget (a widget = the nearest folder under `presentation/react/widgets/` with a `*-widget.tsx`, nested widgets included), UI-kit importing widgets, pages or contexts, shared hooks importing UI-kit, widgets, pages or contexts;
42
- - a query importing a command of its context (`application/`, `infrastructure/` or `wiring/` `queries/` → `commands/`);
43
- - wired dependencies the CLI would never offer ("Wiring" below, `df-ps-scaffold` rule 3);
44
44
  - `new Date()` / `Date.now()` in domain or application (use the `clock` port).
45
45
 
46
- It exits with 1 when anything is found.
46
+ It exits with 1 when anything is found. Checks turned off in the config (`rules.lint`) aren't reported; don't turn checks off yourself.
47
47
 
48
48
  ## Domain
49
49
 
@@ -9,7 +9,7 @@ description: Generate Domain-First components with the `df-ps` CLI (@domain-firs
9
9
 
10
10
  Follow this order for every request:
11
11
 
12
- 1. Read `domain-first.project-structure.config.json` (beside the nearest `package.json`). If missing, stop and tell the user to initialize the project with `npx df-ps` first.
12
+ 1. Read `domain-first.project-structure.config.json` (beside the nearest `package.json`). If missing, stop and tell the user to initialize the project with `npx df-ps` first. Its optional `rules.dependencies` changes what each kind of module may depend on; where it differs from the defaults in these skills, the config wins.
13
13
  2. Feature request without named contexts/components → `df-ps-plan-feature` (it covers steps 3–5).
14
14
  3. Choose a component for each piece of logic with `references/choosing-components.md`.
15
15
  4. Prepare the run details ("Preparing runs" below).
@@ -82,7 +82,7 @@ Moving or renaming a page or widget is a df-ps run too (`Move or rename page` /
82
82
  With `@domain-first/wire`, every new dependency of a wired class (a constructor parameter plus its wire) is added by `df-ps`: the generator's `Dependencies:` step for a new module, `Wire dependency` for an existing one, and the `Handler:` pick for an endpoint (its generator is added automatically). Don't add constructor parameters or wire entries by hand, and don't reorder or remove the ones `df-ps` added.
83
83
 
84
84
  - List each module's dependencies in the plan as run options (`deps: OrderRepository`), with a `Wire dependency` run for existing modules.
85
- - A dependency the CLI doesn't offer is forbidden by the wiring rules (layer, kind, or another context): change the design (a port, an execution query or command, an infrastructure service) instead of adding it by hand.
85
+ - A dependency the CLI doesn't offer is forbidden by the project's dependency rules (the defaults, changed by `rules.dependencies` in the config) or by context isolation: change the design (a port, an execution query or command, an infrastructure service) instead of adding it by hand.
86
86
  - A value that isn't a wired module (a database or SDK client, a config value) lives in an infrastructure service named after the implementation label (`prisma`, `in-memory-db`, `stripe`): the service creates or reads it itself (`readonly client = new PrismaClient()`), with no constructor parameter for it. Implementations get the service through `df-ps`, where it shows up under `Suggested`. Wrap the service's wire in `memoWire(...)` when one instance must be shared (a connection pool, an in-memory store). No `wireValue(...)`. A domain or application module never gets such a value directly: it depends on a port whose adapter uses the service.
87
87
  - An endpoint generated with `handler: never` gets its handler by re-running the endpoint generator once the handler exists, as an approved overwrite.
88
88
 
@@ -1,6 +1,6 @@
1
1
  # Choosing the component for a piece of logic
2
2
 
3
- The only place where these rules live.
3
+ The only place where these rules live. What each kind of module may depend on is the default; `rules.dependencies` in the project's config can change it (e.g. let use cases call each other), and then the config wins.
4
4
 
5
5
  Split the request into pieces of logic (one responsibility each). For each piece, go through the steps **in order**: the first "yes" decides. A name the user used ("service", "gateway") is not a decision.
6
6
 
@@ -6,7 +6,7 @@ Every step list starts with `"pick:Bounded Context: <ctx>"` or `"pick:Shared Lay
6
6
 
7
7
  Any generator: if the run would replace existing files, the last prompt is the confirm `Overwrite them?` (the files are listed above it). Without it, nothing extra is asked. Added lines (barrels, errors, wiring indexes) never trigger it.
8
8
 
9
- {wire} Generators that create a wire (all below except endpoints, which ask their own two selects) then ask the checkbox `Dependencies:`, before `Overwrite them?`. It lists wired modules of `<C>` and of the Shared Layer (`(shared)` suffix), grouped under headers in this order: Repositories, Domain services, Ports, Application services, Queries, Commands, Use cases, Infrastructure services, Presentation services. Inside a group: by type name, `<C>` first. Headers are not counted: `toggle:<n,..>` numbers only modules, top to bottom. Answer `toggle:<n,..>` or `none`. It is skipped when nothing fits, so check `<C>/wiring/` and `<rootFolder>/shared/wiring/` before counting steps. What fits depends on the layer of the class the wire builds: domain → domain; application → domain, application; infrastructure (repository, execution command/query, and port implementations, infrastructure services) → domain, application ports (of `<C>` and the Shared Layer; no other application modules), infrastructure; presentation → application, presentation. On top of that, application services see only ports from application, use cases never see use cases, repository implementations never see repositories, execution command/query implementations never see commands or queries, orchestration commands see only execution commands and queries from application, and orchestration queries only execution queries (repositories from domain stay available; they call only reading methods). Endpoints are never listed. Each chosen module goes into the wire (`wireClass(X, [wireUserRepository])`) and the constructor (`private readonly userRepository: UserRepository`, with `import type`), in the same order. An env-branched wire (repository, execution command/query, port) wires each implementation in isolation: instead of `Dependencies:` it asks `Dependencies for <Implementation>:` once per implementation, in the order of the wire (main, then test). Each list leaves out only what that implementation already has, and a list with nothing to choose is skipped. It may start with a `Suggested` group: infrastructure modules whose file name has the implementation label (its folder, e.g. `prisma`, `in-memory`) as whole words, such as `in-memory-db-infrastructure-service` for `in-memory`. They are listed there only, so numbering starts with them, and they are **checked**: `none` keeps them, `toggle:<n>` on one of them unchecks it.
9
+ {wire} Generators that create a wire (all below except endpoints, which ask their own two selects) then ask the checkbox `Dependencies:`, before `Overwrite them?`. It lists wired modules of `<C>` and of the Shared Layer (`(shared)` suffix), grouped under headers in this order: Repositories, Domain services, Ports, Application services, Queries, Commands, Use cases, Infrastructure services, Presentation services. Inside a group: by type name, `<C>` first. Headers are not counted: `toggle:<n,..>` numbers only modules, top to bottom. Answer `toggle:<n,..>` or `none`. It is skipped when nothing fits, so check `<C>/wiring/` and `<rootFolder>/shared/wiring/` before counting steps. What fits depends on the layer of the class the wire builds: domain → domain; application → domain, application; infrastructure (repository, execution command/query, and port implementations, infrastructure services) → domain, application ports (of `<C>` and the Shared Layer; no other application modules), infrastructure; presentation → application, presentation. On top of that, application services see only ports from application, use cases never see use cases, repository implementations never see repositories, execution command/query implementations never see commands or queries, orchestration commands see only execution commands and queries from application, and orchestration queries only execution queries (repositories from domain stay available; they call only reading methods). These are the defaults: `rules.dependencies` in the config changes them per kind (`use-cases`, `orchestration-queries`, …), so count items from what the project's rules allow. Endpoints are never listed. Each chosen module goes into the wire (`wireClass(X, [wireUserRepository])`) and the constructor (`private readonly userRepository: UserRepository`, with `import type`), in the same order. An env-branched wire (repository, execution command/query, port) wires each implementation in isolation: instead of `Dependencies:` it asks `Dependencies for <Implementation>:` once per implementation, in the order of the wire (main, then test). Each list leaves out only what that implementation already has, and a list with nothing to choose is skipped. It may start with a `Suggested` group: infrastructure modules whose file name has the implementation label (its folder, e.g. `prisma`, `in-memory`) as whole words, such as `in-memory-db-infrastructure-service` for `in-memory`. They are listed there only, so numbering starts with them, and they are **checked**: `none` keeps them, `toggle:<n>` on one of them unchecks it.
10
10
 
11
11
  ## Bounded context
12
12