@tailor-platform/erp-kit 0.0.1 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +7 -0
- package/LICENSE +21 -0
- package/README.md +196 -28
- package/dist/cli.js +914 -0
- package/package.json +67 -8
- package/schemas/app-compose/actors.yml +34 -0
- package/schemas/app-compose/business-flow.yml +50 -0
- package/schemas/app-compose/requirements.yml +33 -0
- package/schemas/app-compose/resolver.yml +47 -0
- package/schemas/app-compose/screen.yml +81 -0
- package/schemas/app-compose/story.yml +67 -0
- package/schemas/module/command.yml +52 -0
- package/schemas/module/feature.yml +58 -0
- package/schemas/module/model.yml +70 -0
- package/schemas/module/module.yml +50 -0
- package/skills/1-module-docs/SKILL.md +111 -0
- package/skills/1-module-docs/references/structure.md +22 -0
- package/skills/2-module-feature-breakdown/SKILL.md +72 -0
- package/skills/2-module-feature-breakdown/references/commands.md +48 -0
- package/skills/2-module-feature-breakdown/references/models.md +29 -0
- package/skills/2-module-feature-breakdown/references/structure.md +22 -0
- package/skills/3-module-doc-review/SKILL.md +236 -0
- package/skills/3-module-doc-review/references/commands.md +54 -0
- package/skills/3-module-doc-review/references/models.md +29 -0
- package/skills/3-module-doc-review/references/testing.md +37 -0
- package/skills/4-module-tdd-implementation/SKILL.md +74 -0
- package/skills/4-module-tdd-implementation/references/commands.md +45 -0
- package/skills/4-module-tdd-implementation/references/db-relations.md +69 -0
- package/skills/4-module-tdd-implementation/references/errors.md +7 -0
- package/skills/4-module-tdd-implementation/references/exports.md +8 -0
- package/skills/4-module-tdd-implementation/references/models.md +30 -0
- package/skills/4-module-tdd-implementation/references/structure.md +22 -0
- package/skills/4-module-tdd-implementation/references/testing.md +37 -0
- package/skills/5-module-implementation-review/SKILL.md +408 -0
- package/skills/5-module-implementation-review/references/commands.md +45 -0
- package/skills/5-module-implementation-review/references/errors.md +7 -0
- package/skills/5-module-implementation-review/references/exports.md +8 -0
- package/skills/5-module-implementation-review/references/models.md +30 -0
- package/skills/5-module-implementation-review/references/testing.md +29 -0
- package/skills/app-compose-1-requirement-analysis/SKILL.md +89 -0
- package/skills/app-compose-1-requirement-analysis/references/structure.md +27 -0
- package/skills/app-compose-2-requirements-breakdown/SKILL.md +95 -0
- package/skills/app-compose-2-requirements-breakdown/references/screen-detailview.md +106 -0
- package/skills/app-compose-2-requirements-breakdown/references/screen-form.md +139 -0
- package/skills/app-compose-2-requirements-breakdown/references/screen-listview.md +153 -0
- package/skills/app-compose-2-requirements-breakdown/references/structure.md +27 -0
- package/skills/app-compose-3-doc-review/SKILL.md +116 -0
- package/skills/app-compose-3-doc-review/references/structure.md +27 -0
- package/skills/app-compose-4-design-mock/SKILL.md +256 -0
- package/skills/app-compose-4-design-mock/references/component.md +50 -0
- package/skills/app-compose-4-design-mock/references/screen-detailview.md +106 -0
- package/skills/app-compose-4-design-mock/references/screen-form.md +139 -0
- package/skills/app-compose-4-design-mock/references/screen-listview.md +153 -0
- package/skills/app-compose-4-design-mock/references/structure.md +27 -0
- package/skills/app-compose-5-design-mock-review/SKILL.md +290 -0
- package/skills/app-compose-5-design-mock-review/references/component.md +50 -0
- package/skills/app-compose-5-design-mock-review/references/screen-detailview.md +106 -0
- package/skills/app-compose-5-design-mock-review/references/screen-form.md +139 -0
- package/skills/app-compose-5-design-mock-review/references/screen-listview.md +153 -0
- package/skills/app-compose-6-implementation-spec/SKILL.md +127 -0
- package/skills/app-compose-6-implementation-spec/references/auth.md +72 -0
- package/skills/app-compose-6-implementation-spec/references/structure.md +27 -0
- package/skills/mock-scenario/SKILL.md +118 -0
- package/src/app.ts +1 -0
- package/src/cli.ts +120 -0
- package/src/commands/check.test.ts +30 -0
- package/src/commands/check.ts +66 -0
- package/src/commands/init.test.ts +88 -0
- package/src/commands/init.ts +120 -0
- package/src/commands/mock/index.ts +53 -0
- package/src/commands/mock/start.ts +179 -0
- package/src/commands/mock/validate.test.ts +185 -0
- package/src/commands/mock/validate.ts +198 -0
- package/src/commands/scaffold.test.ts +76 -0
- package/src/commands/scaffold.ts +119 -0
- package/src/commands/sync-check.test.ts +125 -0
- package/src/commands/sync-check.ts +182 -0
- package/src/integration.test.ts +63 -0
- package/src/mdschema.ts +48 -0
- package/src/mockServer.ts +55 -0
- package/src/module.ts +86 -0
- package/src/modules/accounting/.gitkeep +0 -0
- package/src/modules/coa-management/.gitkeep +0 -0
- package/src/modules/inventory/.gitkeep +0 -0
- package/src/modules/manufacturing/.gitkeep +0 -0
- package/src/modules/primitives/README.md +39 -0
- package/src/modules/primitives/command/activateCategory.test.ts +75 -0
- package/src/modules/primitives/command/activateCategory.ts +50 -0
- package/src/modules/primitives/command/activateCurrency.test.ts +70 -0
- package/src/modules/primitives/command/activateCurrency.ts +50 -0
- package/src/modules/primitives/command/activateUnit.test.ts +53 -0
- package/src/modules/primitives/command/activateUnit.ts +50 -0
- package/src/modules/primitives/command/convertAmount.test.ts +275 -0
- package/src/modules/primitives/command/convertAmount.ts +126 -0
- package/src/modules/primitives/command/convertQuantity.test.ts +219 -0
- package/src/modules/primitives/command/convertQuantity.ts +73 -0
- package/src/modules/primitives/command/createCategory.test.ts +126 -0
- package/src/modules/primitives/command/createCategory.ts +89 -0
- package/src/modules/primitives/command/createCurrency.test.ts +191 -0
- package/src/modules/primitives/command/createCurrency.ts +77 -0
- package/src/modules/primitives/command/createExchangeRate.test.ts +216 -0
- package/src/modules/primitives/command/createExchangeRate.ts +91 -0
- package/src/modules/primitives/command/createUnit.test.ts +214 -0
- package/src/modules/primitives/command/createUnit.ts +88 -0
- package/src/modules/primitives/command/deactivateCategory.test.ts +97 -0
- package/src/modules/primitives/command/deactivateCategory.ts +62 -0
- package/src/modules/primitives/command/deactivateCurrency.test.ts +85 -0
- package/src/modules/primitives/command/deactivateCurrency.ts +55 -0
- package/src/modules/primitives/command/deactivateUnit.test.ts +78 -0
- package/src/modules/primitives/command/deactivateUnit.ts +62 -0
- package/src/modules/primitives/command/setBaseCurrency.test.ts +98 -0
- package/src/modules/primitives/command/setBaseCurrency.ts +74 -0
- package/src/modules/primitives/command/setReferenceUnit.test.ts +108 -0
- package/src/modules/primitives/command/setReferenceUnit.ts +84 -0
- package/src/modules/primitives/db/currency.ts +30 -0
- package/src/modules/primitives/db/exchangeRate.ts +28 -0
- package/src/modules/primitives/db/unit.ts +32 -0
- package/src/modules/primitives/db/uomCategory.ts +32 -0
- package/src/modules/primitives/docs/commands/ActivateCategory.md +34 -0
- package/src/modules/primitives/docs/commands/ActivateCurrency.md +33 -0
- package/src/modules/primitives/docs/commands/ActivateUnit.md +34 -0
- package/src/modules/primitives/docs/commands/ConvertAmount.md +50 -0
- package/src/modules/primitives/docs/commands/ConvertQuantity.md +43 -0
- package/src/modules/primitives/docs/commands/CreateCategory.md +44 -0
- package/src/modules/primitives/docs/commands/CreateCurrency.md +47 -0
- package/src/modules/primitives/docs/commands/CreateExchangeRate.md +48 -0
- package/src/modules/primitives/docs/commands/CreateUnit.md +48 -0
- package/src/modules/primitives/docs/commands/DeactivateCategory.md +38 -0
- package/src/modules/primitives/docs/commands/DeactivateCurrency.md +38 -0
- package/src/modules/primitives/docs/commands/DeactivateUnit.md +38 -0
- package/src/modules/primitives/docs/commands/SetBaseCurrency.md +39 -0
- package/src/modules/primitives/docs/commands/SetReferenceUnit.md +43 -0
- package/src/modules/primitives/docs/features/currency-definitions.md +55 -0
- package/src/modules/primitives/docs/features/exchange-rates.md +61 -0
- package/src/modules/primitives/docs/features/unit-conversion.md +66 -0
- package/src/modules/primitives/docs/features/uom-categories.md +52 -0
- package/src/modules/primitives/docs/models/Currency.md +45 -0
- package/src/modules/primitives/docs/models/ExchangeRate.md +33 -0
- package/src/modules/primitives/docs/models/Unit.md +46 -0
- package/src/modules/primitives/docs/models/UoMCategory.md +44 -0
- package/src/modules/primitives/generated/kysely-tailordb.ts +95 -0
- package/src/modules/primitives/index.ts +40 -0
- package/src/modules/primitives/lib/errors.ts +138 -0
- package/src/modules/primitives/lib/types.ts +20 -0
- package/src/modules/primitives/module.ts +66 -0
- package/src/modules/primitives/permissions.ts +18 -0
- package/src/modules/primitives/tailor.config.ts +11 -0
- package/src/modules/primitives/testing/fixtures.ts +161 -0
- package/src/modules/product-management/.gitkeep +0 -0
- package/src/modules/purchase/.gitkeep +0 -0
- package/src/modules/sales/.gitkeep +0 -0
- package/src/modules/shared/createContext.test.ts +39 -0
- package/src/modules/shared/createContext.ts +15 -0
- package/src/modules/shared/defineCommand.test.ts +42 -0
- package/src/modules/shared/defineCommand.ts +19 -0
- package/src/modules/shared/definePermissions.test.ts +146 -0
- package/src/modules/shared/definePermissions.ts +94 -0
- package/src/modules/shared/entityTypes.ts +15 -0
- package/src/modules/shared/errors.ts +22 -0
- package/src/modules/shared/index.ts +1 -0
- package/src/modules/shared/internal.ts +13 -0
- package/src/modules/shared/requirePermission.test.ts +47 -0
- package/src/modules/shared/requirePermission.ts +8 -0
- package/src/modules/shared/types.ts +4 -0
- package/src/modules/supplier-management/.gitkeep +0 -0
- package/src/modules/supplier-portal/.gitkeep +0 -0
- package/src/modules/testing/index.ts +120 -0
- package/src/modules/user-management/README.md +38 -0
- package/src/modules/user-management/command/activateUser.test.ts +112 -0
- package/src/modules/user-management/command/activateUser.ts +67 -0
- package/src/modules/user-management/command/assignPermissionToRole.test.ts +119 -0
- package/src/modules/user-management/command/assignPermissionToRole.ts +87 -0
- package/src/modules/user-management/command/assignRoleToUser.test.ts +162 -0
- package/src/modules/user-management/command/assignRoleToUser.ts +93 -0
- package/src/modules/user-management/command/createPermission.test.ts +143 -0
- package/src/modules/user-management/command/createPermission.ts +66 -0
- package/src/modules/user-management/command/createRole.test.ts +115 -0
- package/src/modules/user-management/command/createRole.ts +52 -0
- package/src/modules/user-management/command/createUser.test.ts +198 -0
- package/src/modules/user-management/command/createUser.ts +85 -0
- package/src/modules/user-management/command/deactivateUser.test.ts +112 -0
- package/src/modules/user-management/command/deactivateUser.ts +67 -0
- package/src/modules/user-management/command/logAuditEvent.test.ts +179 -0
- package/src/modules/user-management/command/logAuditEvent.ts +59 -0
- package/src/modules/user-management/command/reactivateUser.test.ts +115 -0
- package/src/modules/user-management/command/reactivateUser.ts +67 -0
- package/src/modules/user-management/command/revokePermissionFromRole.test.ts +112 -0
- package/src/modules/user-management/command/revokePermissionFromRole.ts +81 -0
- package/src/modules/user-management/command/revokeRoleFromUser.test.ts +112 -0
- package/src/modules/user-management/command/revokeRoleFromUser.ts +81 -0
- package/src/modules/user-management/db/auditEvent.ts +47 -0
- package/src/modules/user-management/db/permission.ts +31 -0
- package/src/modules/user-management/db/role.ts +28 -0
- package/src/modules/user-management/db/rolePermission.ts +44 -0
- package/src/modules/user-management/db/user.ts +38 -0
- package/src/modules/user-management/db/userRole.ts +44 -0
- package/src/modules/user-management/docs/commands/ActivateUser.md +36 -0
- package/src/modules/user-management/docs/commands/AssignPermissionToRole.md +39 -0
- package/src/modules/user-management/docs/commands/AssignRoleToUser.md +43 -0
- package/src/modules/user-management/docs/commands/CreatePermission.md +35 -0
- package/src/modules/user-management/docs/commands/CreateRole.md +35 -0
- package/src/modules/user-management/docs/commands/CreateUser.md +41 -0
- package/src/modules/user-management/docs/commands/DeactivateUser.md +38 -0
- package/src/modules/user-management/docs/commands/LogAuditEvent.md +37 -0
- package/src/modules/user-management/docs/commands/ReactivateUser.md +37 -0
- package/src/modules/user-management/docs/commands/RevokePermissionFromRole.md +40 -0
- package/src/modules/user-management/docs/commands/RevokeRoleFromUser.md +40 -0
- package/src/modules/user-management/docs/features/audit-trail.md +80 -0
- package/src/modules/user-management/docs/features/role-based-access-control.md +76 -0
- package/src/modules/user-management/docs/features/user-account-management.md +64 -0
- package/src/modules/user-management/docs/models/AuditEvent.md +34 -0
- package/src/modules/user-management/docs/models/Permission.md +31 -0
- package/src/modules/user-management/docs/models/Role.md +31 -0
- package/src/modules/user-management/docs/models/RolePermission.md +33 -0
- package/src/modules/user-management/docs/models/User.md +47 -0
- package/src/modules/user-management/docs/models/UserRole.md +34 -0
- package/src/modules/user-management/docs/plans/2026-01-30-flattened-permissions-design.md +52 -0
- package/src/modules/user-management/executor/recomputeOnRolePermissionChange.ts +61 -0
- package/src/modules/user-management/generated/enums.ts +24 -0
- package/src/modules/user-management/generated/kysely-tailordb.ts +112 -0
- package/src/modules/user-management/index.ts +32 -0
- package/src/modules/user-management/lib/errors.ts +81 -0
- package/src/modules/user-management/lib/recomputeUserPermissions.ts +53 -0
- package/src/modules/user-management/lib/types.ts +31 -0
- package/src/modules/user-management/module.ts +77 -0
- package/src/modules/user-management/permissions.ts +15 -0
- package/src/modules/user-management/tailor.config.ts +11 -0
- package/src/modules/user-management/testing/fixtures.ts +98 -0
- package/src/schemas.ts +25 -0
- package/src/testing.ts +10 -0
- package/src/util.ts +3 -0
|
@@ -0,0 +1,408 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: 5-module-implementation-review
|
|
3
|
+
description: Review implementation parity between documentation and code. Use when validating that TDD implementation (step 4) matches model docs, command docs, and test coverage requirements.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Implementation Parity Review Workflow
|
|
7
|
+
|
|
8
|
+
Review **implementation consistency** between documentation and actual code.
|
|
9
|
+
|
|
10
|
+
## Purpose
|
|
11
|
+
|
|
12
|
+
Verify that TDD implementation (models, commands, tests) properly implements what's documented in model docs and command docs.
|
|
13
|
+
|
|
14
|
+
```
|
|
15
|
+
Model Docs (Schema) → src/db/*.ts (Implementation)
|
|
16
|
+
↓ ↓
|
|
17
|
+
Fields createEntityType()
|
|
18
|
+
Relationships Foreign keys
|
|
19
|
+
State Transitions Status enums
|
|
20
|
+
|
|
21
|
+
Command Docs (Spec) → src/command/*.ts (Implementation)
|
|
22
|
+
↓ ↓
|
|
23
|
+
Business Rules Validation logic
|
|
24
|
+
Error Scenarios Error classes
|
|
25
|
+
Process Flows Branching logic
|
|
26
|
+
|
|
27
|
+
Command Docs (Spec) → src/command/*.test.ts (Tests)
|
|
28
|
+
↓ ↓
|
|
29
|
+
Process Flow branches Test cases
|
|
30
|
+
Error scenarios Error assertions
|
|
31
|
+
Idempotent paths Return existing tests
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
## When to Use
|
|
35
|
+
|
|
36
|
+
- After TDD implementation (step 4), verify it matches documentation
|
|
37
|
+
- Before merging feature branches
|
|
38
|
+
- Quality check during code review
|
|
39
|
+
|
|
40
|
+
## Workflow
|
|
41
|
+
|
|
42
|
+
```
|
|
43
|
+
MODEL DOCS → MODEL CODE → COMMAND DOCS → COMMAND CODE → TESTS → COMPARE → REPORT
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
## Step-by-Step
|
|
47
|
+
|
|
48
|
+
### 1. Read Model Documentation
|
|
49
|
+
|
|
50
|
+
Read ALL model docs:
|
|
51
|
+
|
|
52
|
+
```
|
|
53
|
+
modules/<module-name>/docs/models/*.md
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
Extract for each model:
|
|
57
|
+
|
|
58
|
+
- Field names and types
|
|
59
|
+
- Required vs optional fields
|
|
60
|
+
- Relationships (foreign keys)
|
|
61
|
+
- State transitions (if stateful)
|
|
62
|
+
- Constraints
|
|
63
|
+
|
|
64
|
+
### 2. Read Model Implementation
|
|
65
|
+
|
|
66
|
+
Read ALL model files:
|
|
67
|
+
|
|
68
|
+
```
|
|
69
|
+
modules/<module-name>/src/db/*.ts
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
Extract for each model:
|
|
73
|
+
|
|
74
|
+
- Fields in `createEntityType()`
|
|
75
|
+
- Status enums (base + additional)
|
|
76
|
+
- Foreign key references
|
|
77
|
+
- Field descriptions
|
|
78
|
+
|
|
79
|
+
### 3. Read Command Documentation
|
|
80
|
+
|
|
81
|
+
Read ALL command docs:
|
|
82
|
+
|
|
83
|
+
```
|
|
84
|
+
modules/<module-name>/docs/commands/*.md
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
Extract for each command:
|
|
88
|
+
|
|
89
|
+
- Business rules
|
|
90
|
+
- Error scenarios (with codes)
|
|
91
|
+
- Process flow branches
|
|
92
|
+
- Input/output types
|
|
93
|
+
|
|
94
|
+
### 4. Read Command Implementation
|
|
95
|
+
|
|
96
|
+
Read ALL command files:
|
|
97
|
+
|
|
98
|
+
```
|
|
99
|
+
modules/<module-name>/src/command/*.ts
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
Extract for each command:
|
|
103
|
+
|
|
104
|
+
- Validation logic implemented
|
|
105
|
+
- Error classes thrown
|
|
106
|
+
- Branching paths (if/else, early returns)
|
|
107
|
+
- Input interface fields
|
|
108
|
+
- Return type structure
|
|
109
|
+
|
|
110
|
+
### 5. Read Error Implementation
|
|
111
|
+
|
|
112
|
+
Read error definitions:
|
|
113
|
+
|
|
114
|
+
```
|
|
115
|
+
modules/<module-name>/src/lib/errors.ts
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
Extract:
|
|
119
|
+
|
|
120
|
+
- Error class names
|
|
121
|
+
- Error codes
|
|
122
|
+
- Error message patterns
|
|
123
|
+
|
|
124
|
+
### 6. Read Test Implementation
|
|
125
|
+
|
|
126
|
+
Read ALL test files:
|
|
127
|
+
|
|
128
|
+
```
|
|
129
|
+
modules/<module-name>/src/command/*.test.ts
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
Extract for each command:
|
|
133
|
+
|
|
134
|
+
- Test case descriptions
|
|
135
|
+
- Error assertions
|
|
136
|
+
- Happy path coverage
|
|
137
|
+
- Edge case coverage
|
|
138
|
+
|
|
139
|
+
### 7. Model Doc → Model Code Parity Check
|
|
140
|
+
|
|
141
|
+
| Check Item | Question |
|
|
142
|
+
| ------------------ | ---------------------------------------------------------------- |
|
|
143
|
+
| Field coverage | Does code include all fields from model doc? |
|
|
144
|
+
| Type accuracy | Do field types match doc specification? |
|
|
145
|
+
| Required fields | Are required fields enforced (no default, not nullable)? |
|
|
146
|
+
| Relationship impl | Are foreign key fields implemented for documented relationships? |
|
|
147
|
+
| State transitions | Does status enum include all documented states? |
|
|
148
|
+
| Field descriptions | Do `.description()` calls match doc field descriptions? |
|
|
149
|
+
|
|
150
|
+
### 8. Command Doc → Command Code Parity Check
|
|
151
|
+
|
|
152
|
+
| Check Item | Question |
|
|
153
|
+
| ----------------------- | ---------------------------------------------------------- |
|
|
154
|
+
| Business rule impl | Is each documented business rule implemented in code? |
|
|
155
|
+
| Error scenario coverage | Does code throw errors for all documented error scenarios? |
|
|
156
|
+
| Error code accuracy | Do error codes in code match documented codes? |
|
|
157
|
+
| Process flow alignment | Do code branches match documented process flow? |
|
|
158
|
+
| Input type coverage | Does input interface include all documented inputs? |
|
|
159
|
+
| Return type accuracy | Does return type match documented output? |
|
|
160
|
+
| Dual function pattern | Does command follow `_fn` internal / `fn` public pattern? |
|
|
161
|
+
|
|
162
|
+
### 9. Command Doc → Test Coverage Check
|
|
163
|
+
|
|
164
|
+
| Check Item | Question |
|
|
165
|
+
| --------------------- | ---------------------------------------------------------- |
|
|
166
|
+
| Process flow coverage | Does each branch in process flow have a test case? |
|
|
167
|
+
| Error scenario tests | Does each documented error scenario have a test assertion? |
|
|
168
|
+
| Happy path tests | Are success paths tested? |
|
|
169
|
+
| Idempotent path tests | If doc shows "already exists → return", is this tested? |
|
|
170
|
+
|
|
171
|
+
### 10. Report Findings
|
|
172
|
+
|
|
173
|
+
```markdown
|
|
174
|
+
## Implementation Parity Review Report
|
|
175
|
+
|
|
176
|
+
**Module:** <module-name>
|
|
177
|
+
|
|
178
|
+
---
|
|
179
|
+
|
|
180
|
+
### 1. Model Doc → Model Code Coverage
|
|
181
|
+
|
|
182
|
+
| Model Doc | Fields Documented | Fields Implemented | Gap |
|
|
183
|
+
| --------- | ----------------- | ------------------ | ------------------- |
|
|
184
|
+
| <Model-A> | N fields | N fields | ✅ |
|
|
185
|
+
| <Model-B> | N fields | N-1 fields | ❌ `fieldX` missing |
|
|
186
|
+
|
|
187
|
+
---
|
|
188
|
+
|
|
189
|
+
### 2. Model State Transitions
|
|
190
|
+
|
|
191
|
+
| Model | Documented States | Implemented States | Gap |
|
|
192
|
+
| --------- | ------------------------ | ------------------ | ------------------ |
|
|
193
|
+
| <Model-A> | PENDING, ACTIVE, REMOVED | PENDING, ACTIVE | ❌ REMOVED missing |
|
|
194
|
+
| <Model-B> | ACTIVE, INACTIVE | ACTIVE, INACTIVE | ✅ |
|
|
195
|
+
|
|
196
|
+
---
|
|
197
|
+
|
|
198
|
+
### 3. Command Doc → Command Code Coverage
|
|
199
|
+
|
|
200
|
+
| Command Doc | Business Rules | Implemented | Gap |
|
|
201
|
+
| ----------- | -------------- | ----------- | -------------------------------- |
|
|
202
|
+
| <cmd-a> | 3 rules | 3 rules | ✅ |
|
|
203
|
+
| <cmd-b> | 4 rules | 3 rules | ❌ "rule X validation" not found |
|
|
204
|
+
|
|
205
|
+
---
|
|
206
|
+
|
|
207
|
+
### 4. Error Scenario Implementation
|
|
208
|
+
|
|
209
|
+
| Command Doc | Error Code | Implemented in errors.ts | Thrown in command | Test assertion |
|
|
210
|
+
| ----------- | ---------------- | ------------------------ | ----------------- | -------------- |
|
|
211
|
+
| <cmd-a> | ENTITY_NOT_FOUND | ✅ EntityNotFoundError | ✅ | ✅ |
|
|
212
|
+
| <cmd-a> | INVALID_STATE | ❌ Not defined | ❌ | ❌ |
|
|
213
|
+
| <cmd-b> | DUPLICATE_ENTRY | ✅ DuplicateEntryError | ✅ | ❌ No test |
|
|
214
|
+
|
|
215
|
+
---
|
|
216
|
+
|
|
217
|
+
### 5. Process Flow → Test Coverage
|
|
218
|
+
|
|
219
|
+
| Command Doc | Process Flow Branches | Test Cases | Gap |
|
|
220
|
+
| ----------- | --------------------- | ---------- | -------------------------------- |
|
|
221
|
+
| <cmd-a> | 3 branches | 3 tests | ✅ |
|
|
222
|
+
| <cmd-b> | 4 branches | 2 tests | ❌ Missing "already exists" test |
|
|
223
|
+
|
|
224
|
+
---
|
|
225
|
+
|
|
226
|
+
### 6. Implementation Pattern Compliance
|
|
227
|
+
|
|
228
|
+
| Command | Dual Function Pattern | Input Interface Exported | JSDoc Present |
|
|
229
|
+
| ------- | --------------------- | ------------------------ | ------------- |
|
|
230
|
+
| <cmd-a> | ✅ `_cmdA` + `cmdA` | ✅ | ✅ |
|
|
231
|
+
| <cmd-b> | ❌ Only `cmdB` | ✅ | ❌ |
|
|
232
|
+
|
|
233
|
+
---
|
|
234
|
+
|
|
235
|
+
### 7. Missing Implementation
|
|
236
|
+
|
|
237
|
+
#### Missing in Model Code
|
|
238
|
+
|
|
239
|
+
| Model Doc | Missing Item | Type | Doc Reference |
|
|
240
|
+
| --------- | ------------ | ------ | --------------------------- |
|
|
241
|
+
| <Model-A> | `fieldX` | Field | "fieldX: uuid, required" |
|
|
242
|
+
| <Model-A> | `REMOVED` | Status | State diagram shows REMOVED |
|
|
243
|
+
|
|
244
|
+
#### Missing in Command Code
|
|
245
|
+
|
|
246
|
+
| Command Doc | Missing Item | Type | Doc Reference |
|
|
247
|
+
| ----------- | ---------------- | ------------- | ------------------------ |
|
|
248
|
+
| <cmd-b> | validation for X | Business rule | "Rule: X must be unique" |
|
|
249
|
+
|
|
250
|
+
#### Missing Error Classes
|
|
251
|
+
|
|
252
|
+
| Command Doc | Error Code | Expected Class |
|
|
253
|
+
| ----------- | ------------- | ----------------- |
|
|
254
|
+
| <cmd-a> | INVALID_STATE | InvalidStateError |
|
|
255
|
+
|
|
256
|
+
#### Missing Tests
|
|
257
|
+
|
|
258
|
+
| Command Doc | Missing Test Case | Doc Reference |
|
|
259
|
+
| ----------- | -------------------------------- | --------------------- |
|
|
260
|
+
| <cmd-b> | "entity already exists → return" | Process flow branch 2 |
|
|
261
|
+
| <cmd-b> | "throws DUPLICATE_ENTRY" | Error scenario 3 |
|
|
262
|
+
|
|
263
|
+
---
|
|
264
|
+
|
|
265
|
+
### 8. Inconsistencies
|
|
266
|
+
|
|
267
|
+
| Type | Location | Issue |
|
|
268
|
+
| ------------------- | -------------- | ------------------------------------------- |
|
|
269
|
+
| Type mismatch | Model-A.fieldX | Doc: string, Code: number |
|
|
270
|
+
| Error code mismatch | cmd-a | Doc: USER_NOT_FOUND, Code: ENTITY_NOT_FOUND |
|
|
271
|
+
| Missing description | Model-B.fieldY | No `.description()` but doc has description |
|
|
272
|
+
|
|
273
|
+
---
|
|
274
|
+
|
|
275
|
+
### 9. Summary
|
|
276
|
+
|
|
277
|
+
| Aspect | Status | Details |
|
|
278
|
+
| ----------------------------- | ------ | --------------------------------- |
|
|
279
|
+
| Model Doc → Code Coverage | ⚠️ | X/Y models fully implemented |
|
|
280
|
+
| Command Doc → Code Coverage | ⚠️ | X/Y commands fully implemented |
|
|
281
|
+
| Error Scenario Implementation | ❌ | X/Y errors defined and thrown |
|
|
282
|
+
| Test Coverage | ⚠️ | X/Y process branches have tests |
|
|
283
|
+
| Pattern Compliance | ✅ | All commands follow dual function |
|
|
284
|
+
|
|
285
|
+
### 10. Recommendations
|
|
286
|
+
|
|
287
|
+
1. **Add missing model fields:**
|
|
288
|
+
- Model-A: add `fieldX` field
|
|
289
|
+
|
|
290
|
+
2. **Add missing status values:**
|
|
291
|
+
- Model-A: add `REMOVED` to status enum
|
|
292
|
+
|
|
293
|
+
3. **Implement missing business rules:**
|
|
294
|
+
- cmd-b: add validation for "X must be unique"
|
|
295
|
+
|
|
296
|
+
4. **Define missing error classes:**
|
|
297
|
+
- Add `InvalidStateError` in errors.ts
|
|
298
|
+
|
|
299
|
+
5. **Add missing test cases:**
|
|
300
|
+
- cmd-b: test "entity already exists → return existing"
|
|
301
|
+
- cmd-b: test "throws DUPLICATE_ENTRY on duplicate"
|
|
302
|
+
|
|
303
|
+
6. **Fix inconsistencies:**
|
|
304
|
+
- Model-A.fieldX: change type to string per doc
|
|
305
|
+
```
|
|
306
|
+
|
|
307
|
+
## Common Gaps
|
|
308
|
+
|
|
309
|
+
### Model Doc → Model Code
|
|
310
|
+
|
|
311
|
+
- **Missing fields**: Doc specifies field but not in code
|
|
312
|
+
- **Type mismatches**: Doc says string, code uses number
|
|
313
|
+
- **Missing status values**: State diagram shows state not in enum
|
|
314
|
+
- **Missing relationships**: Doc shows FK but not implemented
|
|
315
|
+
- **Missing descriptions**: Doc has field description but no `.description()`
|
|
316
|
+
|
|
317
|
+
### Command Doc → Command Code
|
|
318
|
+
|
|
319
|
+
- **Unimplemented business rules**: Rule in doc but no validation code
|
|
320
|
+
- **Missing error throws**: Error scenario documented but not thrown
|
|
321
|
+
- **Wrong error codes**: Code and doc use different error codes
|
|
322
|
+
- **Missing process branches**: Flowchart branch not in code logic
|
|
323
|
+
- **Missing dual function**: Only public function, no internal `_fn`
|
|
324
|
+
|
|
325
|
+
### Command Doc → Tests
|
|
326
|
+
|
|
327
|
+
- **Uncovered process branches**: Flowchart branch has no test
|
|
328
|
+
- **Missing error tests**: Error scenario has no assertion
|
|
329
|
+
- **Missing idempotent tests**: "Return existing" path untested
|
|
330
|
+
- **Missing edge cases**: Boundary conditions not tested
|
|
331
|
+
|
|
332
|
+
## Quick Reference: Extraction Patterns
|
|
333
|
+
|
|
334
|
+
### From Model Docs
|
|
335
|
+
|
|
336
|
+
```markdown
|
|
337
|
+
## Fields
|
|
338
|
+
|
|
339
|
+
| Field | Type | Required |
|
|
340
|
+
| -------- | ------ | -------- | ---------------------------------------- |
|
|
341
|
+
| id | uuid | yes | → Check: field exists, type matches |
|
|
342
|
+
| name | string | yes | → Check: not nullable |
|
|
343
|
+
| status | enum | yes | → Check: enum values match state diagram |
|
|
344
|
+
| parentId | uuid | yes | → Check: foreign key implemented |
|
|
345
|
+
|
|
346
|
+
## State Diagram
|
|
347
|
+
|
|
348
|
+
PENDING → ACTIVE → REMOVED
|
|
349
|
+
→ Check: all states in enum
|
|
350
|
+
```
|
|
351
|
+
|
|
352
|
+
### From Command Docs
|
|
353
|
+
|
|
354
|
+
```markdown
|
|
355
|
+
## Business Rules
|
|
356
|
+
|
|
357
|
+
1. Entity must exist → Check: validation in code
|
|
358
|
+
2. Status must be ACTIVE → Check: status check in code
|
|
359
|
+
|
|
360
|
+
## Error Scenarios
|
|
361
|
+
|
|
362
|
+
| Code | Condition |
|
|
363
|
+
| -------------- | -------------- | ----------------------------------- |
|
|
364
|
+
| NOT_FOUND | Entity missing | → Check: error class + throw + test |
|
|
365
|
+
| INVALID_STATUS | Wrong status | → Check: error class + throw + test |
|
|
366
|
+
|
|
367
|
+
## Process Flow (mermaid)
|
|
368
|
+
|
|
369
|
+
graph TD
|
|
370
|
+
A[Start] --> B{Exists?}
|
|
371
|
+
B -->|Yes| C[Return] → Check: test for "already exists"
|
|
372
|
+
B -->|No| D[Create] → Check: test for "create new"
|
|
373
|
+
```
|
|
374
|
+
|
|
375
|
+
### From Implementation
|
|
376
|
+
|
|
377
|
+
```typescript
|
|
378
|
+
// Model: check fields match doc
|
|
379
|
+
export function createEntityType(params) {
|
|
380
|
+
return {
|
|
381
|
+
fields: {
|
|
382
|
+
/* verify each field */
|
|
383
|
+
},
|
|
384
|
+
};
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
// Command: check business rules
|
|
388
|
+
export async function _myCommand(db, input) {
|
|
389
|
+
// Check: validation for each business rule
|
|
390
|
+
if (!entity) throw new EntityNotFoundError(); // Check: matches doc error
|
|
391
|
+
// Check: each branch matches process flow
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
// Test: check coverage
|
|
395
|
+
describe("myCommand", () => {
|
|
396
|
+
it("creates entity when valid"); // Check: happy path
|
|
397
|
+
it("returns existing if found"); // Check: idempotent path
|
|
398
|
+
it("throws NOT_FOUND when missing"); // Check: error scenario
|
|
399
|
+
});
|
|
400
|
+
```
|
|
401
|
+
|
|
402
|
+
## References
|
|
403
|
+
|
|
404
|
+
- [Model patterns](references/models.md)
|
|
405
|
+
- [Command patterns](references/commands.md)
|
|
406
|
+
- [Error patterns](references/errors.md)
|
|
407
|
+
- [Testing patterns](references/testing.md)
|
|
408
|
+
- [Export order](references/exports.md)
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
# Command Implementation
|
|
2
|
+
|
|
3
|
+
## Dual Function Pattern
|
|
4
|
+
|
|
5
|
+
Two functions per operation: internal `_fn` and public `fn`.
|
|
6
|
+
|
|
7
|
+
**Internal function (`_myFunction`):**
|
|
8
|
+
|
|
9
|
+
- Takes concrete `DB` type from `generated/kysely-tailordb`
|
|
10
|
+
- Return type uses `Schema` from `lib/types`: `Promise<{ entity: Entity<Schema> }>`
|
|
11
|
+
- Contains actual implementation
|
|
12
|
+
|
|
13
|
+
**Public function (`myFunction`):**
|
|
14
|
+
|
|
15
|
+
- Generic signature: `<T extends { Entity: object }>(db: Kysely<T>, ...)`
|
|
16
|
+
- Return type uses generic `T`: `Promise<{ entity: Entity<T> }>`
|
|
17
|
+
- Delegates to internal with type casting: `_fn(db as unknown as DB, ...) as unknown as Result`
|
|
18
|
+
|
|
19
|
+
## Implementation Considerations
|
|
20
|
+
|
|
21
|
+
- **Validation**: Check referenced entities exist before operating
|
|
22
|
+
- **Idempotency**: For assign/revoke, return existing instead of throwing
|
|
23
|
+
- **Return format**: Wrap in object `{ entity }` not just `entity`
|
|
24
|
+
|
|
25
|
+
## Conventions
|
|
26
|
+
|
|
27
|
+
- Input types: exported interfaces (`export interface MyFunctionInput`)
|
|
28
|
+
- Use `.executeTakeFirst()` for single results
|
|
29
|
+
- Include JSDoc: `/** Function: name \n Description */`
|
|
30
|
+
|
|
31
|
+
## State Transitions
|
|
32
|
+
|
|
33
|
+
For commands that transition between statuses, accept `from?: string[]` with a default:
|
|
34
|
+
|
|
35
|
+
```typescript
|
|
36
|
+
from?: string[]; // Default: ["ACTIVE"]
|
|
37
|
+
|
|
38
|
+
const validFromStatuses = input.from ?? ["ACTIVE"];
|
|
39
|
+
if (!validFromStatuses.includes(user.status)) {
|
|
40
|
+
throw new InvalidStatusTransitionError(user.status, targetStatus);
|
|
41
|
+
}
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
- Default `from` contains the base valid source status
|
|
45
|
+
- Parent modules can override to allow transitions from additional statuses
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# Database Models
|
|
2
|
+
|
|
3
|
+
## Factory Function Pattern
|
|
4
|
+
|
|
5
|
+
```typescript
|
|
6
|
+
export function createEntityType(params: {
|
|
7
|
+
fields?: Record<string, unknown>;
|
|
8
|
+
additionalStatuses?: string[];
|
|
9
|
+
});
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
- Include `...db.fields.timestamps()`
|
|
13
|
+
- Use `.description()` for field docs
|
|
14
|
+
- Apply permissions at model level
|
|
15
|
+
|
|
16
|
+
## Stateful Model Enums
|
|
17
|
+
|
|
18
|
+
Status enums are tied to the module's state machine. Base module defines core statuses; parent callers can only **extend, not replace**.
|
|
19
|
+
|
|
20
|
+
```typescript
|
|
21
|
+
// Good: extension only
|
|
22
|
+
const BASE_STATUSES = ["PENDING", "ACTIVE", "INACTIVE"] as const;
|
|
23
|
+
const statuses = [...BASE_STATUSES, ...(params.additionalStatuses ?? [])];
|
|
24
|
+
|
|
25
|
+
// Bad: allows replacement
|
|
26
|
+
const statuses = params.statuses ?? ["PENDING", "ACTIVE", "INACTIVE"];
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
- Name parameter `additionalX` to signal extension-only
|
|
30
|
+
- Parent modules handle their additional status transitions
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# Testing Patterns
|
|
2
|
+
|
|
3
|
+
## Test Coverage Goal
|
|
4
|
+
|
|
5
|
+
Tests should cover all paths in the corresponding `docs/commands/*.md`:
|
|
6
|
+
|
|
7
|
+
- **Process Flow**: Each branch in the mermaid flowchart = one test case
|
|
8
|
+
- **Error Scenarios**: Each error code listed = one test case
|
|
9
|
+
- **Idempotent paths**: If flowchart shows "Already exists? → Return existing"
|
|
10
|
+
|
|
11
|
+
## Mock Database
|
|
12
|
+
|
|
13
|
+
```typescript
|
|
14
|
+
const { db, spies } = createMockDb<DB>();
|
|
15
|
+
|
|
16
|
+
// Single return
|
|
17
|
+
spies.select.mockReturnValue(entity);
|
|
18
|
+
|
|
19
|
+
// Sequential returns (in query execution order)
|
|
20
|
+
spies.select.mockReturnValueOnce(first).mockReturnValueOnce(second);
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## Fixtures (`src/testing/fixtures.ts`)
|
|
24
|
+
|
|
25
|
+
- Import `Schema` from `lib/types` (not `Namespace` from generated code)
|
|
26
|
+
- Pattern: `export const baseEntity = { ... } as const satisfies Entity<Schema>`
|
|
27
|
+
- Fixed IDs for traceability: `"entity-1"`
|
|
28
|
+
- Consistent timestamp: `new Date("2024-01-01T00:00:00.000Z")`
|
|
29
|
+
- `updatedAt: null` for base fixtures
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: app-compose-1-requirement-analysis
|
|
3
|
+
description: Create Tier 1-2 documentation (requirements, actors, business-flow) for examples/. Use when starting a new application or documenting high-level requirements and workflows.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Application Requirement Analysis Workflow
|
|
7
|
+
|
|
8
|
+
Create Tier 1-2 documentation: Requirements, Actors, and Business Flows.
|
|
9
|
+
|
|
10
|
+
## Workflow Phases
|
|
11
|
+
|
|
12
|
+
```
|
|
13
|
+
GATHER → CLARIFY → CREATE → VALIDATE
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
### Phase 1: Gather
|
|
17
|
+
|
|
18
|
+
Understand the application's purpose and scope:
|
|
19
|
+
|
|
20
|
+
1. **Identify** what the application does (business purpose)
|
|
21
|
+
2. **List** target users (actors) and their roles
|
|
22
|
+
3. **Understand** business goals and success criteria
|
|
23
|
+
4. **Capture** key workflows the application must support
|
|
24
|
+
|
|
25
|
+
Focus on "what" the application should do, not "how" it will be implemented.
|
|
26
|
+
|
|
27
|
+
### Phase 2: Clarify
|
|
28
|
+
|
|
29
|
+
Use AskUserQuestion to clarify undefined requirements:
|
|
30
|
+
|
|
31
|
+
| Category | Example Questions |
|
|
32
|
+
| ----------------- | ---------------------------------------------- |
|
|
33
|
+
| Authentication | External IdP / Password / Out of scope? |
|
|
34
|
+
| User Operations | Direct creation / Email invitation / Both? |
|
|
35
|
+
| Roles | Fixed roles (Admin/User) / Custom roles? |
|
|
36
|
+
| User Self-Service | View only / Profile edit / Password change? |
|
|
37
|
+
| Lifecycle | Create only / Full lifecycle (activate/deact)? |
|
|
38
|
+
|
|
39
|
+
Ask 3-4 questions at a time using multiSelect where appropriate.
|
|
40
|
+
|
|
41
|
+
### Phase 3: Create
|
|
42
|
+
|
|
43
|
+
Generate documentation using `erp-kit` CLI:
|
|
44
|
+
|
|
45
|
+
```bash
|
|
46
|
+
# Tier 1: Requirements
|
|
47
|
+
erp-kit scaffold --app-root examples requirements <app-name>
|
|
48
|
+
|
|
49
|
+
# Tier 2: Actors
|
|
50
|
+
erp-kit scaffold --app-root examples actors <app-name> <actor-name>
|
|
51
|
+
|
|
52
|
+
# Tier 2: Business Flows
|
|
53
|
+
erp-kit scaffold --app-root examples business-flow <app-name> <flow-name>
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
**Naming conventions:**
|
|
57
|
+
|
|
58
|
+
- Files: kebab-case (e.g., `sales-representative.md`)
|
|
59
|
+
- H1 heading slug must match filename slug
|
|
60
|
+
|
|
61
|
+
**Authorized Business Flows format (in actor docs):**
|
|
62
|
+
|
|
63
|
+
```markdown
|
|
64
|
+
- [Flow Name](../business-flow/<flow>/README.md) — role
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
Roles: `initiator`, `approver`, `viewer`
|
|
68
|
+
|
|
69
|
+
### Phase 4: Validate
|
|
70
|
+
|
|
71
|
+
```bash
|
|
72
|
+
pnpm run app:doc:check
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
## Schema Reference
|
|
76
|
+
|
|
77
|
+
| Schema | Tier | Output Path |
|
|
78
|
+
| ------------------- | ---- | ------------------------------------- |
|
|
79
|
+
| `requirements.yml` | 1 | `README.md` |
|
|
80
|
+
| `actors.yml` | 2 | `docs/actors/<name>.md` |
|
|
81
|
+
| `business-flow.yml` | 2 | `docs/business-flow/<flow>/README.md` |
|
|
82
|
+
|
|
83
|
+
## Next Step
|
|
84
|
+
|
|
85
|
+
After completing Tier 1-2, use `/app-compose-2-requirements-breakdown` to create Tier 3 documentation.
|
|
86
|
+
|
|
87
|
+
## References
|
|
88
|
+
|
|
89
|
+
- [Application structure](references/structure.md)
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# Application Directory Structure
|
|
2
|
+
|
|
3
|
+
```
|
|
4
|
+
{app_name}/
|
|
5
|
+
├── backend/
|
|
6
|
+
│ ├── src/
|
|
7
|
+
│ │ ├── modules.ts # Declaring module usage
|
|
8
|
+
│ │ ├── modules/
|
|
9
|
+
│ │ │ └── {module-name}/ # Module-specific directory
|
|
10
|
+
│ │ │ ├── resolvers/ # API Definition to expose graphql apis
|
|
11
|
+
│ │ │ └── executors/ # PubSub Automation (one file per declaration)
|
|
12
|
+
│ │ └── generated/ # Auto-generated code (do not edit)
|
|
13
|
+
│ └── tailor.config.ts # tailor application config
|
|
14
|
+
│
|
|
15
|
+
└── frontend/
|
|
16
|
+
└── src/
|
|
17
|
+
├── pages/ # File-based routing (auto-discovered by Vite plugin)
|
|
18
|
+
│ └── {page-path}/
|
|
19
|
+
│ ├── page.tsx
|
|
20
|
+
│ └── {page-path}/
|
|
21
|
+
│ ├── components/
|
|
22
|
+
│ └── page.tsx
|
|
23
|
+
├── components/
|
|
24
|
+
│ └── ui/ # Generic UI components
|
|
25
|
+
├── graphql/ # gql.tada settings
|
|
26
|
+
└── providers/ # react providers
|
|
27
|
+
```
|