@polymorphism-tech/morph-spec 4.7.1 → 4.8.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/.morph/analytics/threads-log.jsonl +54 -0
- package/.morph/state.json +198 -0
- package/LICENSE +1 -2
- package/README.md +379 -414
- package/bin/morph-spec.js +57 -403
- package/bin/validate.js +2 -26
- package/claude-plugin.json +2 -2
- package/docs/ARCHITECTURE.md +43 -46
- package/docs/CHEATSHEET.md +203 -221
- package/docs/COMMAND-FLOWS.md +319 -289
- package/docs/QUICKSTART.md +2 -8
- package/docs/plans/2026-02-22-claude-docs-morph-alignment-analysis.md +2 -0
- package/docs/plans/2026-02-22-claude-settings.md +2 -0
- package/docs/plans/2026-02-22-morph-cc-alignment-impl.md +2 -0
- package/docs/plans/2026-02-22-morph-spec-next.md +2 -0
- package/docs/plans/2026-02-22-native-alignment-design.md +2 -0
- package/docs/plans/2026-02-22-native-alignment-impl.md +2 -0
- package/docs/plans/2026-02-22-native-enrichment-design.md +2 -0
- package/docs/plans/2026-02-22-native-enrichment.md +2 -0
- package/docs/plans/2026-02-23-ddd-architecture-refactor.md +2 -0
- package/docs/plans/2026-02-23-ddd-nextsteps.md +2 -0
- package/docs/plans/2026-02-23-infra-architect-refactor.md +2 -0
- package/docs/plans/2026-02-23-nextjs-code-review-design.md +2 -1
- package/docs/plans/2026-02-23-nextjs-code-review-impl.md +2 -0
- package/docs/plans/2026-02-23-nextjs-standards-design.md +2 -1
- package/docs/plans/2026-02-23-nextjs-standards-impl.md +2 -0
- package/docs/plans/2026-02-24-cli-radical-simplification.md +592 -0
- package/docs/plans/2026-02-24-framework-failure-points.md +125 -0
- package/docs/plans/2026-02-24-morph-init-design.md +337 -0
- package/docs/plans/2026-02-24-morph-init-impl.md +1269 -0
- package/docs/plans/2026-02-24-tutorial-command-design.md +71 -0
- package/docs/plans/2026-02-24-tutorial-command.md +298 -0
- package/framework/CLAUDE.md +2 -2
- package/framework/commands/morph-proposal.md +3 -3
- package/framework/hooks/README.md +11 -10
- package/framework/hooks/claude-code/notification/approval-reminder.js +2 -0
- package/framework/hooks/claude-code/post-tool-use/dispatch.js +1 -1
- package/framework/hooks/claude-code/pre-tool-use/protect-readonly-files.js +4 -55
- package/framework/hooks/claude-code/session-start/inject-morph-context.js +20 -5
- package/framework/hooks/claude-code/statusline.py +6 -1
- package/framework/hooks/claude-code/stop/validate-completion.js +1 -1
- package/framework/hooks/claude-code/user-prompt/enrich-prompt.js +1 -1
- package/framework/hooks/dev/check-sync-health.js +117 -0
- package/framework/hooks/dev/guard-version-numbers.js +57 -0
- package/framework/hooks/dev/sync-standards-registry.js +60 -0
- package/framework/hooks/dev/sync-template-registry.js +60 -0
- package/framework/hooks/dev/validate-skill-format.js +70 -0
- package/framework/hooks/dev/validate-standard-format.js +73 -0
- package/framework/hooks/shared/payload-utils.js +39 -0
- package/framework/hooks/shared/state-reader.js +25 -1
- package/framework/rules/morph-workflow.md +1 -1
- package/framework/skills/level-0-meta/morph-init/SKILL.md +216 -0
- package/framework/skills/level-0-meta/morph-replicate/SKILL.md +4 -4
- package/framework/skills/level-0-meta/tool-usage-guide/SKILL.md +4 -4
- package/framework/skills/level-0-meta/verification-before-completion/SKILL.md +1 -1
- package/framework/skills/level-1-workflows/phase-clarify/SKILL.md +192 -191
- package/framework/skills/level-1-workflows/phase-codebase-analysis/SKILL.md +181 -180
- package/framework/skills/level-1-workflows/phase-design/SKILL.md +339 -338
- package/framework/skills/level-1-workflows/phase-implement/SKILL.md +254 -253
- package/framework/skills/level-1-workflows/phase-setup/SKILL.md +168 -170
- package/framework/skills/level-1-workflows/phase-tasks/SKILL.md +284 -283
- package/framework/skills/level-1-workflows/phase-uiux/SKILL.md +246 -245
- package/framework/templates/examples/design-system-examples.md +1 -1
- package/framework/templates/ui/FluentDesignTheme.cs +1 -1
- package/framework/templates/ui/MudTheme.cs +1 -1
- package/framework/templates/ui/design-system.css +1 -1
- package/package.json +4 -2
- package/scripts/bump-version.js +248 -0
- package/scripts/install-dev-hooks.js +138 -0
- package/src/commands/agents/index.js +1 -2
- package/src/commands/index.js +13 -16
- package/src/commands/project/doctor.js +100 -14
- package/src/commands/project/index.js +7 -10
- package/src/commands/project/init.js +398 -555
- package/src/commands/project/install-plugin-cmd.js +28 -0
- package/src/commands/project/setup-infra-cmd.js +12 -0
- package/src/commands/project/tutorial.js +115 -0
- package/src/commands/project/update.js +22 -37
- package/src/commands/state/approve.js +213 -221
- package/src/commands/state/index.js +0 -1
- package/src/commands/state/state.js +337 -365
- package/src/commands/templates/index.js +0 -4
- package/src/commands/trust/trust.js +1 -93
- package/src/commands/utils/index.js +1 -5
- package/src/commands/validation/index.js +1 -5
- package/src/core/registry/command-registry.js +11 -285
- package/src/core/state/state-manager.js +5 -2
- package/src/lib/detectors/index.js +81 -87
- package/src/lib/detectors/structure-detector.js +275 -273
- package/src/lib/generators/recap-generator.js +232 -225
- package/src/lib/installers/mcp-installer.js +18 -3
- package/src/scripts/global-install.js +34 -0
- package/src/scripts/install-plugin.js +126 -0
- package/src/scripts/setup-infra.js +203 -0
- package/src/utils/agents-installer.js +10 -1
- package/src/utils/hooks-installer.js +70 -17
- package/CLAUDE.md +0 -77
- package/docs/claude-alignment-report.md +0 -137
- package/docs/examples/order-management/contracts.cs +0 -84
- package/docs/examples/order-management/proposal.md +0 -24
- package/docs/examples/order-management/spec.md +0 -162
- package/src/commands/feature/create-story.js +0 -362
- package/src/commands/feature/index.js +0 -6
- package/src/commands/feature/shard-spec.js +0 -225
- package/src/commands/feature/sprint-status.js +0 -250
- package/src/commands/generation/generate-onboarding.js +0 -169
- package/src/commands/generation/generate.js +0 -276
- package/src/commands/generation/index.js +0 -5
- package/src/commands/learning/capture-pattern.js +0 -121
- package/src/commands/learning/index.js +0 -5
- package/src/commands/learning/search-patterns.js +0 -126
- package/src/commands/mcp/mcp.js +0 -102
- package/src/commands/project/changes.js +0 -66
- package/src/commands/project/cost.js +0 -179
- package/src/commands/project/detect.js +0 -114
- package/src/commands/project/diff.js +0 -278
- package/src/commands/project/revert.js +0 -173
- package/src/commands/project/standards.js +0 -80
- package/src/commands/project/sync.js +0 -167
- package/src/commands/project/update-agents.js +0 -23
- package/src/commands/state/rollback-phase.js +0 -185
- package/src/commands/templates/template-customize.js +0 -87
- package/src/commands/templates/template-list.js +0 -114
- package/src/commands/templates/template-show.js +0 -129
- package/src/commands/templates/template-validate.js +0 -91
- package/src/commands/utils/troubleshoot.js +0 -222
- package/src/commands/validation/analyze-blazor-concurrency.js +0 -193
- package/src/commands/validation/lint-fluent.js +0 -352
- package/src/commands/validation/validate-blazor-state.js +0 -210
- package/src/commands/validation/validate-blazor.js +0 -156
- package/src/commands/validation/validate-css.js +0 -84
- package/src/lib/detectors/conversation-analyzer.js +0 -163
- package/src/lib/learning/index.js +0 -7
- package/src/lib/learning/learning-system.js +0 -520
- package/src/lib/troubleshooting/index.js +0 -8
- package/src/lib/troubleshooting/troubleshoot-grep.js +0 -198
- package/src/lib/troubleshooting/troubleshoot-index.js +0 -144
- package/src/llm/environment-detector.js +0 -43
|
@@ -1,137 +0,0 @@
|
|
|
1
|
-
# Claude Code Native Alignment Report — Round 2
|
|
2
|
-
|
|
3
|
-
> **Date:** 2026-02-22
|
|
4
|
-
> **Status:** Implemented
|
|
5
|
-
> **Scope:** Memory/rules layer — building on Round 1 (commit 8c806c2)
|
|
6
|
-
|
|
7
|
-
---
|
|
8
|
-
|
|
9
|
-
## Summary
|
|
10
|
-
|
|
11
|
-
Round 2 of Claude Code native alignment identifies and adopts two native patterns from the official Claude Code memory documentation that were missed in Round 1:
|
|
12
|
-
|
|
13
|
-
1. **`.claude/rules/*.md`** — Path-scoped, auto-loading instruction files
|
|
14
|
-
2. **`@import` in CLAUDE.md** — Auto-import external files into session context
|
|
15
|
-
|
|
16
|
-
---
|
|
17
|
-
|
|
18
|
-
## Native Patterns Now Adopted
|
|
19
|
-
|
|
20
|
-
### 1. Path-Scoped Rules (`.claude/rules/`)
|
|
21
|
-
|
|
22
|
-
**What it is:** Claude Code natively supports modular instruction files placed in `.claude/rules/`. Files without `paths:` frontmatter apply globally; files with `paths:` frontmatter auto-load only when Claude is working with matching files.
|
|
23
|
-
|
|
24
|
-
**What we implemented:**
|
|
25
|
-
|
|
26
|
-
| File | Scope | Paths |
|
|
27
|
-
|------|-------|-------|
|
|
28
|
-
| `morph-workflow.md` | Always active | (none — global) |
|
|
29
|
-
| `csharp-standards.md` | C# files | `**/*.cs`, `**/*.csproj` |
|
|
30
|
-
| `frontend-standards.md` | Blazor/TS/CSS | `**/*.razor`, `**/*.tsx`, `**/*.ts`, `**/*.css` |
|
|
31
|
-
| `testing-standards.md` | Test files | `tests/**`, `**/*.test.*`, `**/*.spec.*`, `**/*Tests.cs` |
|
|
32
|
-
| `infrastructure-standards.md` | Infra files | `**/*.bicep`, `**/Dockerfile`, `**/pipelines/**` |
|
|
33
|
-
|
|
34
|
-
**Source material:** Distilled from `framework/standards/` (core/coding.md, backend/dotnet/core.md, core/testing.md, frontend/blazor/pitfalls.md, infrastructure/azure/azure.md, frontend/nextjs/nextjs-patterns.md).
|
|
35
|
-
|
|
36
|
-
**Why it matters:** Previously, standards were buried in `.morph/framework/standards/` — Claude had to navigate deep paths to access them, and they were never automatically loaded. Path-scoped rules ensure Claude sees the right standards *automatically* when working on the right files, without any manual intervention.
|
|
37
|
-
|
|
38
|
-
**Installation:** `morph-spec init` copies `framework/rules/` → `.claude/rules/` (step 9a in `initCommand()`).
|
|
39
|
-
|
|
40
|
-
### 2. `@import` in CLAUDE.md
|
|
41
|
-
|
|
42
|
-
**What it is:** Claude Code supports `@path/to/file` syntax inside CLAUDE.md to auto-import external files into the session context at startup.
|
|
43
|
-
|
|
44
|
-
**What we implemented:** Added `@.morph/context/README.md` to `framework/CLAUDE.md`:
|
|
45
|
-
|
|
46
|
-
```markdown
|
|
47
|
-
## PROJECT CONTEXT
|
|
48
|
-
|
|
49
|
-
@.morph/context/README.md
|
|
50
|
-
```
|
|
51
|
-
|
|
52
|
-
**Why it matters:** Previously, `framework/CLAUDE.md` referenced `.morph/context/README.md` only in text (e.g., "run `morph-spec detect` to see your stack"). The file was never actually loaded. Now, every Claude Code session in a user project automatically starts with the project context (stack, architecture, technologies) pre-loaded — no manual reading required.
|
|
53
|
-
|
|
54
|
-
---
|
|
55
|
-
|
|
56
|
-
## What Remains Over-Engineered
|
|
57
|
-
|
|
58
|
-
### Partially Redundant: Session Context Injection vs Auto Memory
|
|
59
|
-
|
|
60
|
-
The `UserPromptSubmit` hook injects context into every session. This overlaps with:
|
|
61
|
-
- Auto memory (`~/.claude/projects/.../memory/`) — Claude Code's native persistent context layer
|
|
62
|
-
- The new `@import` in CLAUDE.md — project context auto-loaded at startup
|
|
63
|
-
|
|
64
|
-
**Verdict:** Keep the hook for now. It handles dynamic state (current feature, active phase) that auto memory doesn't cover. Revisit in Round 3 — the hook may be reducible to only inject feature-specific state, not static project context.
|
|
65
|
-
|
|
66
|
-
### Level 3–4 Skills Rarely Used
|
|
67
|
-
|
|
68
|
-
`framework/skills/level-3-technologies/` and `level-4-patterns/` contain 30+ files that are rarely invoked. They're installed to `.claude/skills/` via symlinks/copies during init.
|
|
69
|
-
|
|
70
|
-
**Verdict:** Keep for now — they're passive (loaded on-demand via `/skill-name`). Consider documenting them as "on-demand only" in the `morph-workflow.md` rule. Long-term, Level 3–4 could be removed from auto-install and accessed directly from `framework/skills/` when needed.
|
|
71
|
-
|
|
72
|
-
### 37 Agents in `agents.json`
|
|
73
|
-
|
|
74
|
-
The agent system has 37 agents across 4 tiers. For most projects, only 5–8 agents are active at any given time.
|
|
75
|
-
|
|
76
|
-
**Verdict:** Acceptable complexity. Agents drive spawn prompts and workflow orchestration — they can't be replaced by documentation. The activation-by-keyword system (Tier 3) already limits unnecessary activation.
|
|
77
|
-
|
|
78
|
-
---
|
|
79
|
-
|
|
80
|
-
## What Was Intentionally Kept (Justified)
|
|
81
|
-
|
|
82
|
-
| Feature | Justification |
|
|
83
|
-
|---------|--------------|
|
|
84
|
-
| `state.json` + state machine | Claude Code has no native feature-tracking equivalent; phase enforcement requires runtime state |
|
|
85
|
-
| `protect-spec-files.js` hook | Dynamically checks approval gate state before allowing spec file edits — cannot be replaced by static `permissions.deny` |
|
|
86
|
-
| All 12 Claude Code hooks | Context injection (dynamic), output tracking (direct JSON I/O), tool failure logging all provide value beyond native capabilities |
|
|
87
|
-
| `.morph/framework/standards/` | Deep reference library for agents; the rules layer distills it but doesn't replace it |
|
|
88
|
-
| `permissions.deny` for state.json + framework | Already replaced `protect-readonly-files.js` hook in Round 1 — this is the right native approach |
|
|
89
|
-
| Skills hierarchy (Level 0–2) | Level 0 (meta), Level 1 (phase workflows), Level 2 (domains) are actively invoked via `/skill-name` syntax |
|
|
90
|
-
|
|
91
|
-
---
|
|
92
|
-
|
|
93
|
-
## Roadmap: Round 3 Candidates
|
|
94
|
-
|
|
95
|
-
In priority order:
|
|
96
|
-
|
|
97
|
-
1. **Session context hook reduction** — Trim `UserPromptSubmit` hook to inject only feature-specific dynamic state, relying on `@import` + rules for static context. Reduces hook complexity.
|
|
98
|
-
|
|
99
|
-
2. **Level 3–4 skill audit** — Measure actual usage frequency. If consistently low, move these to a "pull-on-demand" model (reference from framework, not installed to `.claude/skills/`).
|
|
100
|
-
|
|
101
|
-
3. **`morph-workflow.md` rule enhancement** — Add current workflow/phase detection so the always-active rule provides live feature status context (currently requires `morph-spec status` command).
|
|
102
|
-
|
|
103
|
-
4. **User-level rules layer (`~/.claude/rules/`)** — A potential personal workflow preferences file for Polymorphism Tech developers (e.g., preferred stack defaults, commit message style). Not currently used.
|
|
104
|
-
|
|
105
|
-
5. **Rules auto-update on `morph-spec update`** — Currently rules are only installed during `init`. The `update` command should sync `.claude/rules/` when framework rules change.
|
|
106
|
-
|
|
107
|
-
---
|
|
108
|
-
|
|
109
|
-
## Files Changed in Round 2
|
|
110
|
-
|
|
111
|
-
| Action | File |
|
|
112
|
-
|--------|------|
|
|
113
|
-
| Created | `framework/rules/morph-workflow.md` |
|
|
114
|
-
| Created | `framework/rules/csharp-standards.md` |
|
|
115
|
-
| Created | `framework/rules/frontend-standards.md` |
|
|
116
|
-
| Created | `framework/rules/testing-standards.md` |
|
|
117
|
-
| Created | `framework/rules/infrastructure-standards.md` |
|
|
118
|
-
| Updated | `framework/CLAUDE.md` — added `@.morph/context/README.md` import |
|
|
119
|
-
| Updated | `src/commands/project/init.js` — added step 9a: rules copy to `.claude/rules/` |
|
|
120
|
-
| Created | `docs/claude-alignment-report.md` (this file) |
|
|
121
|
-
|
|
122
|
-
---
|
|
123
|
-
|
|
124
|
-
## Round 1 Reference (commit 8c806c2)
|
|
125
|
-
|
|
126
|
-
Round 1 implemented 7 tasks:
|
|
127
|
-
1. Fixed circular hook bug in `track-output-creation.js`
|
|
128
|
-
2. Native `permissions.deny` replaced `protect-readonly-files.js`
|
|
129
|
-
3. Skills installed to `.claude/skills/` (flat, with symlinks on non-Windows)
|
|
130
|
-
4. Global statusline installed to `~/.claude/`
|
|
131
|
-
5. `PostToolUseFailure` hook: `handle-tool-failure.js`
|
|
132
|
-
6. Standards registry: `framework/standards/STANDARDS.json` (74 entries)
|
|
133
|
-
7. `framework/phases.json` — canonical phase definitions
|
|
134
|
-
|
|
135
|
-
---
|
|
136
|
-
|
|
137
|
-
*MORPH-SPEC by Polymorphism Tech*
|
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
// ============================================================
|
|
2
|
-
// CONTRACTS: Order Management — Level 2 (Business Logic)
|
|
3
|
-
// Example of correctly filled contracts-level2.cs template
|
|
4
|
-
// Feature: order-management | Date: 2026-02-23
|
|
5
|
-
// ============================================================
|
|
6
|
-
|
|
7
|
-
using System;
|
|
8
|
-
using System.Collections.Generic;
|
|
9
|
-
using System.Threading;
|
|
10
|
-
using System.Threading.Tasks;
|
|
11
|
-
using MediatR;
|
|
12
|
-
|
|
13
|
-
// ===== AGGREGATE ROOT =====
|
|
14
|
-
// Implementado em: Domain/Orders/Aggregates/Order.cs
|
|
15
|
-
//
|
|
16
|
-
// Invariants (do spec.md > Aggregate Blueprint):
|
|
17
|
-
// - Confirm() só é válido se Status == Draft E Items.Any()
|
|
18
|
-
// - AddItem() lança DomainException se Status != Draft
|
|
19
|
-
// - Cancel() é válido de Draft ou Confirmed → Cancelled (terminal)
|
|
20
|
-
|
|
21
|
-
namespace ExampleApp.Domain.Orders.Events;
|
|
22
|
-
|
|
23
|
-
// ===== DOMAIN EVENTS =====
|
|
24
|
-
|
|
25
|
-
public record OrderCreatedEvent(Guid OrderId, Guid UserId) : DomainEvent;
|
|
26
|
-
public record OrderConfirmedEvent(Guid OrderId, Guid UserId, decimal Total) : DomainEvent; // Total as decimal for event serialization; Money value object lives inside the Aggregate
|
|
27
|
-
public record OrderCancelledEvent(Guid OrderId, string Reason) : DomainEvent;
|
|
28
|
-
|
|
29
|
-
namespace ExampleApp.Application.Orders.Commands;
|
|
30
|
-
|
|
31
|
-
// ===== COMMANDS (CQRS) =====
|
|
32
|
-
|
|
33
|
-
public record CreateOrderCommand(Guid UserId, List<CreateOrderItemRequest> Items)
|
|
34
|
-
: IRequest<CreateOrderResult>;
|
|
35
|
-
public record CreateOrderResult(Guid OrderId);
|
|
36
|
-
|
|
37
|
-
public record ConfirmOrderCommand(Guid OrderId) : IRequest;
|
|
38
|
-
public record CancelOrderCommand(Guid OrderId, string Reason) : IRequest;
|
|
39
|
-
|
|
40
|
-
namespace ExampleApp.Application.Orders.Queries;
|
|
41
|
-
|
|
42
|
-
// ===== QUERIES =====
|
|
43
|
-
|
|
44
|
-
public record GetOrderQuery(Guid OrderId) : IRequest<OrderDto?>;
|
|
45
|
-
|
|
46
|
-
// PagedResult<T> — defined in Shared/Common/PagedResult.cs (shared framework type)
|
|
47
|
-
public record ListOrdersByUserQuery(Guid UserId, int Page = 1, int PageSize = 20)
|
|
48
|
-
: IRequest<PagedResult<OrderDto>>;
|
|
49
|
-
|
|
50
|
-
namespace ExampleApp.Application.Orders;
|
|
51
|
-
|
|
52
|
-
// ===== DTOs (read models — nunca expõe o Aggregate diretamente) =====
|
|
53
|
-
|
|
54
|
-
public record OrderDto(
|
|
55
|
-
Guid Id,
|
|
56
|
-
Guid UserId,
|
|
57
|
-
string Status,
|
|
58
|
-
decimal Total,
|
|
59
|
-
List<OrderItemDto> Items,
|
|
60
|
-
DateTime CreatedAt,
|
|
61
|
-
DateTime? UpdatedAt
|
|
62
|
-
);
|
|
63
|
-
|
|
64
|
-
public record OrderItemDto(Guid ProductId, int Quantity, decimal UnitPrice, decimal Subtotal);
|
|
65
|
-
|
|
66
|
-
public record CreateOrderItemRequest(Guid ProductId, int Quantity, decimal UnitPrice);
|
|
67
|
-
|
|
68
|
-
namespace ExampleApp.Domain.Orders;
|
|
69
|
-
|
|
70
|
-
// ===== REPOSITORY (um por Aggregate Root) =====
|
|
71
|
-
|
|
72
|
-
public interface IOrderRepository
|
|
73
|
-
{
|
|
74
|
-
Task<Order?> GetAsync(Guid id, CancellationToken ct = default);
|
|
75
|
-
Task<List<Order>> GetByUserAsync(Guid userId, CancellationToken ct = default);
|
|
76
|
-
Task AddAsync(Order order, CancellationToken ct = default);
|
|
77
|
-
Task UpdateAsync(Order order, CancellationToken ct = default);
|
|
78
|
-
Task<bool> ExistsAsync(Guid id, CancellationToken ct = default);
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
// ===== EXCEPTIONS =====
|
|
82
|
-
|
|
83
|
-
public class OrderNotFoundException(Guid id) : DomainException($"Order '{id}' not found.");
|
|
84
|
-
public class OrderInvalidStateException(string message) : DomainException(message);
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
# Proposal: Order Management
|
|
2
|
-
|
|
3
|
-
**Feature:** order-management
|
|
4
|
-
**Type:** Business Logic (Level 2)
|
|
5
|
-
**Stack:** .NET 10 / C# 14, Blazor Server, EF Core, Azure SQL
|
|
6
|
-
|
|
7
|
-
## User Story
|
|
8
|
-
|
|
9
|
-
Como usuário autenticado, quero criar e gerenciar pedidos de compra para que eu possa
|
|
10
|
-
acompanhar o status dos meus pedidos e receber notificações de mudanças.
|
|
11
|
-
|
|
12
|
-
## Acceptance Criteria
|
|
13
|
-
|
|
14
|
-
- [ ] Usuário pode criar um pedido com 1+ itens
|
|
15
|
-
- [ ] Pedido começa no status Draft
|
|
16
|
-
- [ ] Pedido só pode ser Confirmado se tiver pelo menos 1 item
|
|
17
|
-
- [ ] Pedido Confirmado não pode receber mais itens
|
|
18
|
-
- [ ] Total do pedido é calculado automaticamente
|
|
19
|
-
- [ ] Sistema notifica quando pedido é Confirmado
|
|
20
|
-
|
|
21
|
-
## Out of Scope
|
|
22
|
-
|
|
23
|
-
- Pagamento (feature separada)
|
|
24
|
-
- Envio/logística
|
|
@@ -1,162 +0,0 @@
|
|
|
1
|
-
# Feature Specification: Order Management
|
|
2
|
-
|
|
3
|
-
| Field | Value |
|
|
4
|
-
|-------|-------|
|
|
5
|
-
| **ID** | order-management |
|
|
6
|
-
| **Status** | Approved |
|
|
7
|
-
| **Created** | 2026-02-23 |
|
|
8
|
-
| **Stack** | .NET 10 / Blazor Server / EF Core |
|
|
9
|
-
| **Complexity** | Medium |
|
|
10
|
-
| **Agents** | Core: All / Specialists: domain-architect, ef-modeler, event-architect |
|
|
11
|
-
|
|
12
|
-
---
|
|
13
|
-
|
|
14
|
-
## Overview
|
|
15
|
-
|
|
16
|
-
**Problem:** Usuários precisam criar e gerenciar pedidos com rastreamento de status.
|
|
17
|
-
|
|
18
|
-
**Solution:** Aggregate Order com factory method, invariants de estado, e Domain Events para notificações.
|
|
19
|
-
|
|
20
|
-
**Success Criteria:**
|
|
21
|
-
- [ ] Order CRUD com validações de negócio
|
|
22
|
-
- [ ] Status tracking com transições controladas
|
|
23
|
-
- [ ] Notificação ao confirmar pedido
|
|
24
|
-
|
|
25
|
-
---
|
|
26
|
-
|
|
27
|
-
## Requirements
|
|
28
|
-
|
|
29
|
-
**Functional:**
|
|
30
|
-
FR001: Criar pedido com mínimo 1 item | FR002: Confirmar pedido (Draft → Confirmed) | FR003: Cancelar pedido (Draft/Confirmed → Cancelled) | FR004: Calcular total automaticamente
|
|
31
|
-
|
|
32
|
-
**Non-Functional:**
|
|
33
|
-
NFR001: Performance - operações < 200ms | NFR002: Consistência - invariants garantidas em toda operação
|
|
34
|
-
|
|
35
|
-
---
|
|
36
|
-
|
|
37
|
-
## User Stories
|
|
38
|
-
|
|
39
|
-
### US001: Criar Pedido
|
|
40
|
-
**As** usuário autenticado **I want** criar um pedido com itens **so that** posso comprar produtos
|
|
41
|
-
|
|
42
|
-
**Acceptance Criteria:**
|
|
43
|
-
1. Pedido criado com status Draft
|
|
44
|
-
2. Total calculado na criação
|
|
45
|
-
|
|
46
|
-
**Edge Cases:** Lista de itens vazia → erro 400
|
|
47
|
-
|
|
48
|
-
---
|
|
49
|
-
|
|
50
|
-
## Technical Design
|
|
51
|
-
|
|
52
|
-
### Stack
|
|
53
|
-
| Component | Technology |
|
|
54
|
-
|-----------|------------|
|
|
55
|
-
| Frontend | Blazor Server |
|
|
56
|
-
| Backend | .NET 10 / C# 14 |
|
|
57
|
-
| Database | Azure SQL / EF Core |
|
|
58
|
-
|
|
59
|
-
### Data Model
|
|
60
|
-
|
|
61
|
-
#### Order
|
|
62
|
-
| Column | Type | Constraints |
|
|
63
|
-
|--------|------|-------------|
|
|
64
|
-
| Id | Guid | PK |
|
|
65
|
-
| UserId | Guid | FK (reference by ID — cross-aggregate) |
|
|
66
|
-
| Status | OrderStatus | Enum |
|
|
67
|
-
| CreatedAt | datetime2 | Default: GETUTCDATE() |
|
|
68
|
-
| UpdatedAt | datetime2 | Nullable |
|
|
69
|
-
|
|
70
|
-
#### OrderItem (owned entity)
|
|
71
|
-
| Column | Type | Constraints |
|
|
72
|
-
|--------|------|-------------|
|
|
73
|
-
| Id | Guid | PK |
|
|
74
|
-
| OrderId | Guid | FK |
|
|
75
|
-
| ProductId | Guid | Reference by ID |
|
|
76
|
-
| Quantity | int | > 0 |
|
|
77
|
-
| UnitPrice | decimal(18,2) | > 0 |
|
|
78
|
-
|
|
79
|
-
### Contracts
|
|
80
|
-
> **Ref:** `framework/templates/code/dotnet/contracts/contracts-level2.cs`
|
|
81
|
-
|
|
82
|
-
---
|
|
83
|
-
|
|
84
|
-
## Domain Complexity
|
|
85
|
-
|
|
86
|
-
**Nível:** 2 — Business Logic
|
|
87
|
-
|
|
88
|
-
**Justificativa:** Order tem estados com transições controladas (Draft → Confirmed → Cancelled),
|
|
89
|
-
invariants de negócio (não confirmar sem itens, não adicionar itens a pedido confirmado),
|
|
90
|
-
cálculo derivado (Total), e outros módulos precisam reagir (NotificationService ao OrderConfirmed).
|
|
91
|
-
|
|
92
|
-
**Padrões Aplicados:**
|
|
93
|
-
- AggregateRoot com factory method estático
|
|
94
|
-
- Value Objects: Money (UnitPrice, Total)
|
|
95
|
-
- Domain Events: OrderCreatedEvent, OrderConfirmedEvent, OrderCancelledEvent
|
|
96
|
-
- CQRS com MediatR
|
|
97
|
-
|
|
98
|
-
**Padrões Omitidos:**
|
|
99
|
-
- Bounded Contexts — sistema single-domain, desnecessário
|
|
100
|
-
|
|
101
|
-
---
|
|
102
|
-
|
|
103
|
-
## Aggregate Blueprint (Nível 2+ apenas)
|
|
104
|
-
|
|
105
|
-
### Aggregate Root: Order
|
|
106
|
-
|
|
107
|
-
**Invariants:**
|
|
108
|
-
- Order só pode ser Confirmado se Status == Draft E tiver pelo menos 1 item
|
|
109
|
-
- Order Confirmado não pode receber mais itens (AddItem lança DomainException)
|
|
110
|
-
- Order Cancelado não pode ser reativado (estado terminal)
|
|
111
|
-
|
|
112
|
-
**Estados e Transições:**
|
|
113
|
-
```
|
|
114
|
-
{Draft} → Confirm() → {Confirmed}
|
|
115
|
-
{Draft} → Cancel() → {Cancelled}
|
|
116
|
-
{Confirmed} → Cancel() → {Cancelled}
|
|
117
|
-
```
|
|
118
|
-
|
|
119
|
-
**Domain Events:**
|
|
120
|
-
- `OrderCreatedEvent` — publicado ao criar (Create factory method)
|
|
121
|
-
- `OrderConfirmedEvent` — publicado ao confirmar (Confirm method)
|
|
122
|
-
- `OrderCancelledEvent` — publicado ao cancelar (Cancel method)
|
|
123
|
-
|
|
124
|
-
**Value Objects:**
|
|
125
|
-
- `Money` — UnitPrice e Total não são decimals simples: têm validação (> 0) e operações (Add, Multiply)
|
|
126
|
-
|
|
127
|
-
**Referências Cross-Aggregate (por ID):**
|
|
128
|
-
- `UserId: Guid` — nunca `User User { get; }`
|
|
129
|
-
- `ProductId: Guid` em OrderItem — nunca `Product Product { get; }`
|
|
130
|
-
|
|
131
|
-
### Linguagem Ubíqua
|
|
132
|
-
|
|
133
|
-
| Termo | Definição | Código |
|
|
134
|
-
|-------|-----------|--------|
|
|
135
|
-
| Order | Pedido de compra de um usuário | `Order` (AggregateRoot) |
|
|
136
|
-
| Draft | Pedido criado, ainda editável | `OrderStatus.Draft` |
|
|
137
|
-
| Confirmed | Pedido submetido, não editável | `OrderStatus.Confirmed` |
|
|
138
|
-
| Cancelled | Pedido cancelado, estado terminal | `OrderStatus.Cancelled` |
|
|
139
|
-
| Confirm | Ato de finalizar e submeter um pedido | `Order.Confirm()` |
|
|
140
|
-
| OrderItem | Linha de produto dentro de um pedido | `OrderItem` (Entity owned) |
|
|
141
|
-
| Total | Soma calculada de todos os itens | `Order.Total` (property calculada) |
|
|
142
|
-
|
|
143
|
-
---
|
|
144
|
-
|
|
145
|
-
## Flows
|
|
146
|
-
|
|
147
|
-
### Confirmar Pedido
|
|
148
|
-
**Trigger:** Usuário clica "Confirmar Pedido"
|
|
149
|
-
1. Frontend → `POST /api/orders/{id}/confirm`
|
|
150
|
-
2. API → `ConfirmOrderCommand(OrderId)`
|
|
151
|
-
3. Handler → `repository.GetAsync(id)` → `order.Confirm()` → `repository.UpdateAsync(order)`
|
|
152
|
-
4. `OrderConfirmedEvent` publicado → NotificationService envia email
|
|
153
|
-
**End State:** Order.Status = Confirmed
|
|
154
|
-
|
|
155
|
-
---
|
|
156
|
-
|
|
157
|
-
## Definition of Done
|
|
158
|
-
- [ ] Aggregate implementado com todos os invariants
|
|
159
|
-
- [ ] Domain Events publicados e consumidos
|
|
160
|
-
- [ ] Testes unitários do Aggregate (sem EF)
|
|
161
|
-
- [ ] Testes de integração do Handler
|
|
162
|
-
- [ ] API endpoint documentado
|