tshex-cli 1.0.23 → 1.0.24

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.
@@ -1,12 +1,17 @@
1
1
  ### Context Ports
2
2
 
3
3
  Context ports define the communication available at a context boundary.
4
- They describe what data enters the context, what data leaves it, and which
5
- operation another system can invoke.
4
+ They describe which concrete capability a context exposes, what data enters
5
+ that capability, and what data it returns.
6
6
 
7
- Ports are used to keep communication contracts explicit. An adapter imports a
8
- port, implements that contract, and translates the external interaction into an
9
- application process.
7
+ In practice a port is usually not just an abstraction or a contract. It is a
8
+ specific boundary element of the system with identity: a command handler, a
9
+ query entry point, an event consumer, a published endpoint, or another concrete
10
+ interaction mechanism that exists because the running system exposes it.
11
+
12
+ Types and interfaces still matter, but they are secondary. Their role is to
13
+ make the port explicit. The main concern is the port as a real executable
14
+ surface that another actor can call or observe.
10
15
 
11
16
  > **Hint**
12
17
  > The generated `example-ports.ts` file is only a placeholder. Replace it when
@@ -22,12 +27,12 @@ export function example(): void {
22
27
  }
23
28
  ```
24
29
 
25
- This placeholder does not define a real contract yet. Its purpose is to mark
26
- the context root as the place where boundary-facing types and interfaces live.
30
+ This placeholder does not define a real port yet. Its purpose is to mark the
31
+ context root as the place where boundary-facing capabilities are declared.
27
32
 
28
- #### First Contract
33
+ #### First Port
29
34
 
30
- In the following example we replace the placeholder with a minimal contract for
35
+ In the following example we replace the placeholder with a concrete port for
31
36
  creating a user.
32
37
 
33
38
  ```ts title="users/example-ports.ts"
@@ -53,16 +58,17 @@ export interface CreateUserPort {
53
58
  ```
54
59
 
55
60
  `CreateUserRequest` defines the incoming payload. `CreateUserResponse` defines
56
- the outgoing payload. `CreateUserPort` exposes the operation available at the
57
- boundary.
61
+ the outgoing payload. `CreateUserPort` names the concrete capability exposed at
62
+ the boundary: creating a user.
58
63
 
59
- This contract says nothing about HTTP, queues, or databases. It only declares
60
- the shape of the communication.
64
+ This definition does not commit to HTTP, queues, or databases. It focuses on
65
+ the interaction the context makes available. The transport can vary, but the
66
+ port remains the same identifiable boundary capability.
61
67
 
62
68
  #### Adapter Implementation
63
69
 
64
- Now that the port exists, an adapter can implement it and delegate the work to
65
- an application service.
70
+ Now that the port exists, the system can materialize it through an adapter and
71
+ delegate the work to an application service.
66
72
 
67
73
  ```ts title="users/adapters/create-user.ts"
68
74
  import type {
@@ -96,22 +102,27 @@ export class CreateUserAdapter implements CreateUserPort {
96
102
  }
97
103
  ```
98
104
 
99
- The adapter implements `CreateUserPort`, so it must provide `create()`. Inside
100
- that method it translates the root-level request into the input expected by the
101
- application service.
105
+ The adapter implements `CreateUserPort`, so it materializes the boundary
106
+ capability and provides `create()`. Inside that method it translates the
107
+ root-level request into the input expected by the application service.
102
108
 
103
109
  This is the normal flow of the generated structure:
104
110
 
105
- ```text
106
- external system -> adapter -> application -> domain
111
+ ```mermaid
112
+ flowchart LR
113
+ external["External system"] --> adapter[Adapter]
114
+ adapter --> port[Port]
115
+ port --> application[Application]
116
+ application --> domain[Domain]
107
117
  ```
108
118
 
109
- The port belongs to the boundary. The adapter materializes the boundary. The
110
- application process executes the use case.
119
+ The port belongs to the boundary because it is part of what the context really
120
+ exposes. The adapter is one implementation path for that port. The application
121
+ process executes the use case and uses domain capabilities.
111
122
 
112
123
  #### Multiple Port Files
113
124
 
114
- As the context grows, you can keep several contracts at the context root.
125
+ As the context grows, you can keep several ports at the context root.
115
126
 
116
127
  ```ts title="users/list-users.ts"
117
128
  export type ListUsersRequest = {
@@ -131,35 +142,38 @@ export interface ListUsersPort {
131
142
  }
132
143
  ```
133
144
 
134
- An adapter can then import the contract from the file that owns it.
145
+ An adapter can then import the port definition from the file that owns it.
135
146
 
136
- This arrangement is useful when one context exposes several independent forms
137
- of communication. A single file works well for a small context. Separate files
138
- become easier to maintain when responsibilities start to diverge.
147
+ This arrangement is useful when one context exposes several independent
148
+ capabilities. A single file works well for a small context. Separate files
149
+ become easier to maintain when each port has its own identity and
150
+ responsibility.
139
151
 
140
152
  > **Warning**
141
- > A port should define communication, not domain behavior. Avoid moving entity
142
- > rules, repository logic, or infrastructure details into the port file.
153
+ > A port should define an exposed boundary capability, not domain internals.
154
+ > Avoid moving entity rules, repository logic, or infrastructure details into
155
+ > the port file.
143
156
 
144
157
  #### Example Layout
145
158
 
146
159
  The following structure keeps ports at the root while the implementation lives
147
160
  in the generated folders.
148
161
 
149
- ```text
150
- users/
151
- ├── example-ports.ts
152
- ├── list-users.ts
153
- ├── adapters/
154
- ├── application/
155
- └── domain/
162
+ ```mermaid
163
+ flowchart TD
164
+ users["users/"] --> examplePorts["example-ports.ts"]
165
+ users --> listUsers["list-users.ts"]
166
+ users --> adapters["adapters/"]
167
+ users --> application["application/"]
168
+ users --> domain["domain/"]
156
169
  ```
157
170
 
158
171
  This layout keeps the context boundary visible from the top level. It also
159
- reduces coupling between adapters because they all import the same contracts.
172
+ reduces coupling between adapters because they all import the same port
173
+ definitions for the capabilities the context exposes.
160
174
 
161
175
  #### Next Step
162
176
 
163
- After defining a port, implement the corresponding adapter and connect it to an
164
- application service. The surrounding structure is described in
165
- `library-structure.md`.
177
+ After defining a port, implement the corresponding executable path and connect
178
+ it to an application service. The surrounding structure is described in
179
+ `library-structure.md`.
@@ -13,11 +13,12 @@ language, rules, and operations.
13
13
 
14
14
  The root contains the entry points of the generated library.
15
15
 
16
- ```text
17
- index.d.ts
18
- main.ts
19
- shared/
20
- users/
16
+ ```mermaid
17
+ flowchart TD
18
+ root["Library root"] --> index["index.d.ts"]
19
+ root --> main["main.ts"]
20
+ root --> shared["shared/"]
21
+ root --> users["users/"]
21
22
  ```
22
23
 
23
24
  `index.d.ts` defines root-level types. `main.ts` starts as a placeholder for
@@ -29,10 +30,10 @@ or more context directories.
29
30
  The `shared` directory contains concepts that can be reused by multiple
30
31
  contexts.
31
32
 
32
- ```text
33
- shared/
34
- ├── application/
35
- └── domain/
33
+ ```mermaid
34
+ flowchart TD
35
+ shared["shared/"] --> application["application/"]
36
+ shared --> domain["domain/"]
36
37
  ```
37
38
 
38
39
  `shared/domain` contains modeling foundations such as value objects, entities,
@@ -47,11 +48,12 @@ Until then, keep it close to the context that owns the rule.
47
48
  A context groups the vocabulary, rules, and operations of one application
48
49
  capability.
49
50
 
50
- ```text
51
- users/
52
- billing/
53
- inventory/
54
- sales/
51
+ ```mermaid
52
+ flowchart TD
53
+ contexts["Contexts"] --> users["users/"]
54
+ contexts --> billing["billing/"]
55
+ contexts --> inventory["inventory/"]
56
+ contexts --> sales["sales/"]
55
57
  ```
56
58
 
57
59
  Each context can evolve independently while still reusing the abstractions from
@@ -62,12 +64,12 @@ the system.
62
64
 
63
65
  Every generated context starts with the same internal structure.
64
66
 
65
- ```text
66
- users/
67
- ├── example-ports.ts
68
- ├── adapters/
69
- ├── application/
70
- └── domain/
67
+ ```mermaid
68
+ flowchart TD
69
+ users["users/"] --> ports["example-ports.ts"]
70
+ users --> adapters["adapters/"]
71
+ users --> application["application/"]
72
+ users --> domain["domain/"]
71
73
  ```
72
74
 
73
75
  `example-ports.ts` is the root communication surface of the context.
@@ -123,14 +125,20 @@ split ports across several files. The detailed guidance for that layout lives in
123
125
 
124
126
  The normal dependency direction is the following:
125
127
 
126
- ```text
127
- adapter -> port
128
- adapter -> application
129
- application -> domain
128
+ ```mermaid
129
+ flowchart LR
130
+ adapter[Adapter] --> thirdParty["Third-party library"]
131
+ adapter --> port[Port]
132
+ port --> application[Application]
133
+ port --> domain[Domain]
134
+ application --> domain
130
135
  ```
131
136
 
132
137
  This direction keeps the core model isolated from transport and infrastructure
133
- details. The deeper a layer is, the less it should know about the outside.
138
+ details. Adapters integrate with external libraries and context ports. Ports
139
+ connect the context boundary to application processes or directly to domain
140
+ capabilities when no application orchestration is needed. The deeper a layer
141
+ is, the less it should know about the outside.
134
142
 
135
143
  > **Warning**
136
144
  > Avoid importing adapter-specific concerns into the domain layer. Once a domain
@@ -141,23 +149,23 @@ details. The deeper a layer is, the less it should know about the outside.
141
149
 
142
150
  The following diagram shows the runtime flow of a typical operation.
143
151
 
144
- ```text
145
- External system
146
- |
147
- v
148
- Port + adapter
149
- |
150
- v
151
- Application service
152
- |
153
- v
154
- Domain capability
152
+ ```mermaid
153
+ flowchart TD
154
+ main["main.ts"] --> system["Own system"]
155
+ system --> application["Application services"]
156
+ application --> domain["Domain capabilities"]
157
+ system --> adapter[Adapters]
158
+ adapter --> port[Port]
159
+ adapter --> thirdParty["Third-party libraries"]
160
+ thirdParty --> external["External systems"]
155
161
  ```
156
162
 
157
- The adapter receives the input, the application service coordinates the use
158
- case, and the domain provides the rules and behavior required by that use case.
163
+ `main.ts` is the runtime entry point into the own system. Inside that system,
164
+ application services use domain capabilities, while adapters can depend on
165
+ ports and third-party libraries. The port branch stops at the boundary because
166
+ what exists beyond that port depends on the system that implements it.
159
167
 
160
168
  #### Next Step
161
169
 
162
170
  Use this structure as the default layout for new code. When you need to inspect
163
- the purpose of a generated file, consult `generated-file-reference.md`.
171
+ the purpose of a generated file, consult `generated-file-reference.md`.
@@ -176,10 +176,15 @@ and the representation used by the context.
176
176
 
177
177
  The normal flow of the data abstractions is the following:
178
178
 
179
- ```text
180
- service -> repository -> driver -> data manager -> raw records
181
- service <- repository <- transformed records
179
+ ```mermaid
180
+ flowchart LR
181
+ service[Service] --> repository[Repository]
182
+ repository --> driver[Driver]
183
+ driver --> manager["Data manager"]
184
+ manager --> raw["Raw records"]
185
+ repository --> transformed["Transformed records"]
186
+ transformed --> service
182
187
  ```
183
188
 
184
189
  This separation keeps the application service focused on orchestration while
185
- the repository focuses on transformation.
190
+ the repository focuses on transformation.
@@ -135,10 +135,12 @@ registered or executed.
135
135
 
136
136
  The normal flow is the following:
137
137
 
138
- ```text
139
- service -> dispatch(event)
140
- dispatcher -> matching handlers
141
- handlers -> side effects
138
+ ```mermaid
139
+ flowchart LR
140
+ service[Service] --> dispatch["dispatch(event)"]
141
+ dispatch --> dispatcher[Dispatcher]
142
+ dispatcher --> handlers["Matching handlers"]
143
+ handlers --> effects["Side effects"]
142
144
  ```
143
145
 
144
- This keeps the main process separate from secondary reactions.
146
+ This keeps the main process separate from secondary reactions.
@@ -123,9 +123,12 @@ cross-cutting behavior belongs in the generated HTTP abstraction.
123
123
 
124
124
  #### Example Flow
125
125
 
126
- ```text
127
- request -> middleware -> handler -> response body
126
+ ```mermaid
127
+ flowchart LR
128
+ request[Request] --> middleware[Middleware]
129
+ middleware --> handler[Handler]
130
+ handler --> response["Response body"]
128
131
  ```
129
132
 
130
133
  This flow keeps the transport boundary explicit while leaving framework choices
131
- to the adapter layer.
134
+ to the adapter layer.
@@ -120,8 +120,11 @@ an external platform. It only depends on the application-level contract.
120
120
 
121
121
  #### Example Flow
122
122
 
123
- ```text
124
- service -> Logger contract -> adapter -> logging backend
123
+ ```mermaid
124
+ flowchart LR
125
+ service[Service] --> contract["Logger contract"]
126
+ contract --> adapter[Adapter]
127
+ adapter --> backend["Logging backend"]
125
128
  ```
126
129
 
127
- This flow keeps observability concerns outside the core process.
130
+ This flow keeps observability concerns outside the core process.
@@ -112,9 +112,13 @@ result, depending on the requirements of the use case.
112
112
 
113
113
  #### Example Flow
114
114
 
115
- ```text
116
- input -> service -> domain capabilities -> collaborators -> result
115
+ ```mermaid
116
+ flowchart LR
117
+ input[Input] --> service[Service]
118
+ service --> domain["Domain capabilities"]
119
+ domain --> collaborators[Collaborators]
120
+ collaborators --> result[Result]
117
121
  ```
118
122
 
119
123
  This flow keeps orchestration in the application layer and domain meaning in
120
- the domain layer.
124
+ the domain layer.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tshex-cli",
3
- "version": "1.0.23",
3
+ "version": "1.0.24",
4
4
  "author": "https://github.com/virtualitems/",
5
5
  "license": "MIT",
6
6
  "description": "Typescript Hexagonal Architecture CLI",