event-sourcing-knowledge
安装方式
先用 Prompt 核对来源与依赖。也可下载安装包。
用 AI 助手安装
复制提示词,让助手先核对固定版本和依赖。
查看 Prompt收起 Prompt
先检查当前 Agent 是否已安装 SkillPI Skill Finder。如果尚未安装,请按官方仓库的说明安装并启用:https://github.com/Findskills/skillpi。然后使用 Skill Finder 打开此 SkillPI 详情页并定位 "event-sourcing-knowledge":https://skillpi.com/zh/skills/deepskill-1a55f4cff1088d2bf2e11748f42c1150bb33b5855fc7930089851d63e18ffe47。安装前核对上游来源和版本:https://github.com/dykyi-roman/awesome-claude-code。来源不一致时停止并说明差异。核对通过后,用 Skill Finder 安装目标 Skill,并报告安装路径和来源版本。
来源与配置
github.com
配置方式待核实
请查看原始来源中的适用工具、依赖和权限要求。
安装实测待补充
事件溯源知识库。提供用于事件溯源架构审计的模式与反模式,并包含面向 PHP 的实践指导,以帮助评估与改进事件溯源实现。
介绍来源: third_party · dykyi-roman · 0.0.1 参考来源
SkillPi 解读
- 能完成的任务
- 翻译待完成,请参阅来源文档。
- 实测状态
- 未测试
文件浏览
Frontmatter
name: event-sourcing-knowledge
description: Event Sourcing knowledge base. Provides patterns, antipatterns, and PHP-specific guidelines for Event Sourcing architecture audits.Event Sourcing Knowledge Base
Quick reference for Event Sourcing architecture patterns and PHP implementation guidelines.
Core Principles
Event Sourcing Fundamentals
Traditional Storage: Event Sourcing:
┌─────────────────┐ ┌─────────────────┐
│ Current State │ │ Event Stream │
│ ───────────── │ │ ───────────── │
│ Order #123 │ │ 1. OrderCreated│
│ Status: Paid │ │ 2. ItemAdded │
│ Total: $150 │ │ 3. ItemAdded │
└─────────────────┘ │ 4. OrderPaid │
↓ └────────┬────────┘
Direct update │
▼
┌─────────────────┐
│ Current State │
│ (Rebuilt from │
│ events) │
└─────────────────┘
Rule: Store events, derive state. Never modify events.
Key Concepts
| Concept | Description |
|---|---|
| Event | Immutable record of something that happened |
| Event Store | Append-only storage for events |
| Event Stream | Ordered sequence of events for one aggregate |
| Aggregate | Consistency boundary, rebuilt from events |
| Projection | Read model built by processing events |
| Snapshot | Cached aggregate state for performance |
Quick Checklists
Event Checklist
- [ ] Named in past tense (OrderCreated, ItemAdded)
- [ ] Immutable (readonly class)
- [ ] Contains all data needed to apply change
- [ ] Has metadata (timestamp, causation, correlation IDs)
- [ ] No business logic
- [ ] Versioned for schema evolution
Aggregate Checklist
- [ ] State rebuilt from events only
- [ ] apply*() methods modify state from events
- [ ] record*() methods create and apply events
- [ ] No direct state modification
- [ ] Returns uncommitted events for persistence
Event Store Checklist
- [ ] Append-only (no updates, no deletes)
- [ ] Ordered within stream
- [ ] Supports optimistic concurrency
- [ ] Events never modified
- [ ] Stream position tracking
Projection Checklist
- [ ] Idempotent event handlers
- [ ] Can be rebuilt from scratch
- [ ] Handles event ordering
- [ ] Tracks processed position
Common Violations Quick Reference
| Violation | Where to Look | Severity |
|---|---|---|
| Mutable event | Event with setters | Critical |
| Direct state mutation | Aggregate bypassing events | Critical |
| Missing event data | Event without full state info | Critical |
| Event with logic | Event doing calculations | Warning |
| Non-idempotent projection | Projection with side effects | Warning |
| Missing metadata | Event without timestamp/IDs | Warning |
PHP 8.4 Event Sourcing Patterns
Domain Event
final readonly class OrderConfirmedEvent
{
public function __construct(
public string $orderId,
public int $totalCents,
public string $currency,
public DateTimeImmutable $confirmedAt,
public EventMetadata $metadata
) {}
}
final readonly class EventMetadata
{
public function __construct(
public string $eventId,
public DateTimeImmutable $occurredAt,
public ?string $causationId = null,
public ?string $correlationId = null,
public int $version = 1
) {}
}
Event-Sourced Aggregate
final class Order extends EventSourcedAggregate
{
private OrderStatus $status;
private Money $total;
public static function create(OrderId $id, CustomerId $customerId): self
{
$order = new self($id);
$order->recordThat(new OrderCreatedEvent(
orderId: $id->value,
customerId: $customerId->value,
createdAt: new DateTimeImmutable()
));
return $order;
}
public function confirm(): void
{
if ($this->status !== OrderStatus::Draft) {
throw new InvalidStateException();
}
$this->recordThat(new OrderConfirmedEvent(
orderId: $this->id->value,
totalCents: $this->total->cents(),
currency: $this->total->currency(),
confirmedAt: new DateTimeImmutable()
));
}
protected function applyOrderCreatedEvent(OrderCreatedEvent $event): void
{
$this->status = OrderStatus::Draft;
$this->total = Money::zero('USD');
}
protected function applyOrderConfirmedEvent(OrderConfirmedEvent $event): void
{
$this->status = OrderStatus::Confirmed;
}
}
Projection
final class OrderListProjection
{
public function __construct(
private Connection $connection
) {}
public function applyOrderCreatedEvent(OrderCreatedEvent $event): void
{
$this->connection->insert('order_list', [
'id' => $event->orderId,
'customer_id' => $event->customerId,
'status' => 'draft',
'created_at' => $event->createdAt->format('Y-m-d H:i:s'),
]);
}
public function applyOrderConfirmedEvent(OrderConfirmedEvent $event): void
{
$this->connection->update('order_list', [
'status' => 'confirmed',
'total_cents' => $event->totalCents,
'confirmed_at' => $event->confirmedAt->format('Y-m-d H:i:s'),
], ['id' => $event->orderId]);
}
}
References
For detailed information, load these reference files:
references/event-store-patterns.md— Event persistence, streams, concurrencyreferences/projection-patterns.md— Read model projectionsreferences/snapshot-patterns.md— Performance optimization with snapshotsreferences/versioning-patterns.md— Event schema evolutionreferences/antipatterns.md— Common violations with detection patterns
当前收录版本
0.0.1
质量评测
满分100 · 来自 SkillPi LAB 实验室的评测报告。
亮点
- 提供事件溯源架构审计的模式、反模式及 PHP 特定指南,具有明确的实用价值
- 内容涵盖核心原则、快速检查清单、常见违规快速参考等,适合广泛受众
亮点
- description 明确描述了 Skill 的功能和用途,触发词精准完整
- 覆盖多种变体,边界清晰,用户能准确理解 Skill 的适用范围
亮点
- 结构清晰,包含多个章节和详细的代码示例
- frontmatter 完整,单文件未超过 500 行,符合规范要求
亮点
- 提供了详细的 PHP 代码示例和最佳实践
- 工具来源明确,参数正确,覆盖主要异常,执行可靠性高
取前四项原始分值的算术平均,四舍五入取整。可通过收录报告核对各项评分与说明,运行记录需单独查证。
正文静态检测
100 / 100 · skillpi-20261123-no-r3-v1
正文未命中当前规则。
分数仅反映正文中的规则命中,供使用前参考。附件与运行行为不在此评分范围内。
权限与使用前检查
根据当前主文档自动整理,命中内容可能是示例或防护说明;不是实际权限声明,也未覆盖附件、外部依赖或运行行为。
未从主文档识别到上述常见操作,不能据此判断无需权限或没有风险。
安全评级与访问范围
safe · 静态证据核验,不代表运行安全保证。
使用前请由宿主核对并授权实际文件读写、外部服务和联网目的地;本站的核验不会授予任何运行权限。
用户讨论
还没有已核实的点评。