projection-patterns – skill Lập trình cho agent AI
Xây dựng read model và projection từ event stream. Dùng khi triển khai phía đọc CQRS, xây dựng materialized view hoặc tối ưu hiệu năng truy vấn trong hệ thống event-sourced.
Cài skill projection-patterns bằng một lệnh
Chọn công cụ bạn đang dùng, copy lệnh và dán vào terminal. Skill sẽ nằm trong thư mục skills của công cụ đó và sẵn sàng dùng ở phiên làm việc tiếp theo.
Claude Code
mkdir -p ~/.claude/skills && curl -fsSL https://skill.dn1nguoi.com/z/projection-patterns-fe020.tgz | tar xz -C ~/.claude/skills
Gọi trong Claude Code: /projection-patterns – rồi mô tả công việc bạn muốn làm.
Codex
mkdir -p ~/.codex/skills && curl -fsSL https://skill.dn1nguoi.com/z/projection-patterns-fe020.tgz | tar xz -C ~/.codex/skills
Gọi trong Codex: $projection-patterns – rồi mô tả công việc bạn muốn làm.
Hermes Agent
mkdir -p ~/.hermes/skills && curl -fsSL https://skill.dn1nguoi.com/z/projection-patterns-fe020.tgz | tar xz -C ~/.hermes/skills
Gọi trong Hermes Agent: /projection-patterns – rồi mô tả công việc bạn muốn làm.
DeepSeek
mkdir -p ~/.deepcode/skills && curl -fsSL https://skill.dn1nguoi.com/z/projection-patterns-fe020.tgz | tar xz -C ~/.deepcode/skills
Gọi trong DeepSeek: /projection-patterns – rồi mô tả công việc bạn muốn làm.
Nội dung SKILL.md
Nội dung SKILL.md gốc bằng tiếng Anh.
Projection Patterns
Comprehensive guide to building projections and read models for event-sourced systems.
When to Use This Skill
- Building CQRS read models
- Creating materialized views from events
- Optimizing query performance
- Implementing real-time dashboards
- Building search indexes from events
- Aggregating data across streams
Core Concepts
1. Projection Architecture
┌─────────────┐ ┌─────────────┐ ┌─────────────┐
│ Event Store │────►│ Projector │────►│ Read Model │
│ │ │ │ │ (Database) │
│ ┌─────────┐ │ │ ┌─────────┐ │ │ ┌─────────┐ │
│ │ Events │ │ │ │ Handler │ │ │ │ Tables │ │
│ └─────────┘ │ │ │ Logic │ │ │ │ Views │ │
│ │ │ └─────────┘ │ │ │ Cache │ │
└─────────────┘ └─────────────┘ └─────────────┘2. Projection Types
| Type | Description | Use Case |
| -------------- | --------------------------- | ---------------------- |
| Live | Real-time from subscription | Current state queries |
| Catchup | Process historical events | Rebuilding read models |
| Persistent | Stores checkpoint | Resume after restart |
| Inline | Same transaction as write | Strong consistency |
Templates and detailed worked examples
Full template library and detailed worked examples live in references/details.md. Read that file when you need the concrete templates.
Best Practices
Do's
- Make projections idempotent - Safe to replay
- Use transactions - For multi-table updates
- Store checkpoints - Resume after failures
- Monitor lag - Alert on projection delays
- Plan for rebuilds - Design for reconstruction
Don'ts
- Don't couple projections - Each is independent
- Don't skip error handling - Log and alert on failures
- Don't ignore ordering - Events must be processed in order
- Don't over-normalize - Denormalize for query patterns
Skill liên quan
- feature-flags-architect – Dùng khi thêm, gỡ bỏ hoặc kiểm tra feature flag. Kích hoạt với “add a flag”, “ship…
- feature-flags-architect – Dùng khi thêm, gỡ bỏ hoặc kiểm tra feature flag. Kích hoạt với “add a flag”, “ship…
- brainstorming – Dùng trước khi thực hiện công việc sáng tạo hoặc xây dựng (tính năng, kiến trúc, hành…
- fix – Sửa các test Playwright bị lỗi hoặc chập chờn. Dùng khi người dùng nói "fix test"…
- focused-fix – Dùng khi người dùng yêu cầu sửa, gỡ lỗi hoặc làm cho một tính năng/module/khu vực cụ thể…
- peer-review – Chuẩn bị bản nháp phản biện khoa học mang tính xây dựng, dựa trên bằng chứng, và đánh…
- break-ai-fix-loops – Chặn các vòng lặp sửa lỗi không hiệu quả của AI coding bằng dấu vân tay lỗi ổn định…
- brooks-debt – Đánh giá nợ kỹ thuật: xác định, phân loại và ưu tiên các vấn đề khó bảo trì, giúp nhóm…