@ai-content-space/loopx 0.2.8 → 0.2.10
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/README.md +26 -9
- package/README.zh-CN.md +26 -9
- package/docs/loopx/design/loopx-skill-suite-v1-design.md +12 -0
- package/docs/loopx/plans/2026-06-14-loopx-spec-memory-context-loading.md +948 -0
- package/docs/loopx/plans/2026-06-15-support-lens-skills-migration.md +1153 -0
- package/package.json +6 -1
- package/plugins/loopx/.codex-plugin/plugin.json +1 -1
- package/plugins/loopx/skills/api-designer/SKILL.md +232 -0
- package/plugins/loopx/skills/api-designer/references/error-handling.md +541 -0
- package/plugins/loopx/skills/api-designer/references/openapi.md +824 -0
- package/plugins/loopx/skills/api-designer/references/pagination.md +494 -0
- package/plugins/loopx/skills/api-designer/references/rest-patterns.md +335 -0
- package/plugins/loopx/skills/api-designer/references/versioning.md +391 -0
- package/plugins/loopx/skills/architecture-designer/SKILL.md +117 -0
- package/plugins/loopx/skills/architecture-designer/references/adr-template.md +116 -0
- package/plugins/loopx/skills/architecture-designer/references/architecture-patterns.md +346 -0
- package/plugins/loopx/skills/architecture-designer/references/database-selection.md +102 -0
- package/plugins/loopx/skills/architecture-designer/references/nfr-checklist.md +212 -0
- package/plugins/loopx/skills/architecture-designer/references/system-design.md +313 -0
- package/plugins/loopx/skills/clarify/SKILL.md +12 -1
- package/plugins/loopx/skills/cli-developer/SKILL.md +124 -0
- package/plugins/loopx/skills/cli-developer/references/design-patterns.md +221 -0
- package/plugins/loopx/skills/cli-developer/references/go-cli.md +540 -0
- package/plugins/loopx/skills/cli-developer/references/node-cli.md +383 -0
- package/plugins/loopx/skills/cli-developer/references/python-cli.md +422 -0
- package/plugins/loopx/skills/cli-developer/references/ux-patterns.md +448 -0
- package/plugins/loopx/skills/debug/SKILL.md +1 -1
- package/plugins/loopx/skills/doc-readability/SKILL.md +1 -1
- package/plugins/loopx/skills/exec/SKILL.md +1 -1
- package/plugins/loopx/skills/final-review/SKILL.md +1 -1
- package/plugins/loopx/skills/finish/SKILL.md +1 -1
- package/plugins/loopx/skills/fix-review/SKILL.md +1 -1
- package/plugins/loopx/skills/go-style/SKILL.md +1 -1
- package/plugins/loopx/skills/kratos/SKILL.md +2 -1
- package/plugins/loopx/skills/plan-to-exec/SKILL.md +12 -1
- package/plugins/loopx/skills/refactor-plan/SKILL.md +1 -1
- package/plugins/loopx/skills/requirement-analyzer/SKILL.md +161 -0
- package/plugins/loopx/skills/requirement-analyzer/references/example-reports.md +170 -0
- package/plugins/loopx/skills/requirement-analyzer/references/prd-gap-checklist.md +167 -0
- package/plugins/loopx/skills/requirement-analyzer/references/readiness-rubric.md +70 -0
- package/plugins/loopx/skills/requirement-analyzer/references/report-template.md +83 -0
- package/plugins/loopx/skills/review/SKILL.md +1 -1
- package/plugins/loopx/skills/spec/SKILL.md +12 -1
- package/plugins/loopx/skills/sql-style/SKILL.md +108 -0
- package/plugins/loopx/skills/sql-style/references/database-design.md +402 -0
- package/plugins/loopx/skills/sql-style/references/dialect-differences.md +419 -0
- package/plugins/loopx/skills/sql-style/references/optimization.md +384 -0
- package/plugins/loopx/skills/sql-style/references/query-patterns.md +285 -0
- package/plugins/loopx/skills/sql-style/references/window-functions.md +328 -0
- package/plugins/loopx/skills/subagent-exec/SKILL.md +1 -1
- package/plugins/loopx/skills/tdd/SKILL.md +1 -1
- package/plugins/loopx/skills/verify/SKILL.md +1 -1
- package/scripts/verify-skills.mjs +0 -2
- package/skills/RESOLVER.md +8 -1
- package/skills/api-designer/SKILL.md +232 -0
- package/skills/api-designer/references/error-handling.md +541 -0
- package/skills/api-designer/references/openapi.md +824 -0
- package/skills/api-designer/references/pagination.md +494 -0
- package/skills/api-designer/references/rest-patterns.md +335 -0
- package/skills/api-designer/references/versioning.md +391 -0
- package/skills/architecture-designer/SKILL.md +117 -0
- package/skills/architecture-designer/references/adr-template.md +116 -0
- package/skills/architecture-designer/references/architecture-patterns.md +346 -0
- package/skills/architecture-designer/references/database-selection.md +102 -0
- package/skills/architecture-designer/references/nfr-checklist.md +212 -0
- package/skills/architecture-designer/references/system-design.md +313 -0
- package/skills/clarify/SKILL.md +12 -1
- package/skills/cli-developer/SKILL.md +124 -0
- package/skills/cli-developer/references/design-patterns.md +221 -0
- package/skills/cli-developer/references/go-cli.md +540 -0
- package/skills/cli-developer/references/node-cli.md +383 -0
- package/skills/cli-developer/references/python-cli.md +422 -0
- package/skills/cli-developer/references/ux-patterns.md +448 -0
- package/skills/debug/SKILL.md +1 -1
- package/skills/doc-readability/SKILL.md +1 -1
- package/skills/exec/SKILL.md +1 -1
- package/skills/final-review/SKILL.md +1 -1
- package/skills/finish/SKILL.md +1 -1
- package/skills/fix-review/SKILL.md +1 -1
- package/skills/go-style/SKILL.md +1 -1
- package/skills/kratos/SKILL.md +2 -1
- package/skills/plan-to-exec/SKILL.md +12 -1
- package/skills/refactor-plan/SKILL.md +1 -1
- package/skills/requirement-analyzer/SKILL.md +161 -0
- package/skills/requirement-analyzer/references/example-reports.md +170 -0
- package/skills/requirement-analyzer/references/prd-gap-checklist.md +167 -0
- package/skills/requirement-analyzer/references/readiness-rubric.md +70 -0
- package/skills/requirement-analyzer/references/report-template.md +83 -0
- package/skills/review/SKILL.md +1 -1
- package/skills/spec/SKILL.md +12 -1
- package/skills/sql-style/SKILL.md +108 -0
- package/skills/sql-style/references/database-design.md +402 -0
- package/skills/sql-style/references/dialect-differences.md +419 -0
- package/skills/sql-style/references/optimization.md +384 -0
- package/skills/sql-style/references/query-patterns.md +285 -0
- package/skills/sql-style/references/window-functions.md +328 -0
- package/skills/subagent-exec/SKILL.md +1 -1
- package/skills/tdd/SKILL.md +1 -1
- package/skills/verify/SKILL.md +1 -1
- package/src/cli.mjs +4 -1
- package/src/context-manifest.mjs +51 -1
- package/src/install-discovery.mjs +114 -0
- package/src/loopx-context-artifacts.mjs +114 -0
- package/src/project-discovery.mjs +1 -0
- package/src/workflow.mjs +47 -3
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: architecture-designer
|
|
3
|
+
description: "Applies loopx architecture discipline for system boundaries, ADRs, NFRs, scalability, failure modes, operability, and technology tradeoffs. Not for replacing clarify, spec, implementation planning, code review, or workflow state transitions."
|
|
4
|
+
when_to_use: "architecture-designer, architecture, system design, ADR, NFR, scalability, failure modes, technology tradeoff, 架构设计"
|
|
5
|
+
license: MIT
|
|
6
|
+
metadata:
|
|
7
|
+
version: "0.2.10"
|
|
8
|
+
forked_from: https://github.com/Jeffallan/claude-skills/tree/main/skills/architecture-designer
|
|
9
|
+
maintained_by: loopx
|
|
10
|
+
---
|
|
11
|
+
|
|
12
|
+
# Architecture Designer
|
|
13
|
+
|
|
14
|
+
## loopx Boundary
|
|
15
|
+
|
|
16
|
+
`architecture-designer` is a support lens, not a workflow state. Use it directly for architecture review or system design discussion, and use it from `spec`, `review`, or `final-review` when changes affect system boundaries, operational behavior, or long-lived design decisions.
|
|
17
|
+
|
|
18
|
+
This skill does not replace `clarify`, `spec`, `plan-to-exec`, `review`, or `final-review`. If architecture decisions are not yet approved, produce options and route the work through `spec`.
|
|
19
|
+
|
|
20
|
+
When database technology, ownership, schema, migration, or query performance is part of the architecture decision, also use `sql-style`.
|
|
21
|
+
|
|
22
|
+
## When to Use
|
|
23
|
+
|
|
24
|
+
Use this lens when work involves:
|
|
25
|
+
|
|
26
|
+
- Defining system boundaries, service boundaries, ownership, or integration contracts.
|
|
27
|
+
- Choosing between architectural patterns such as modular monolith, microservices, event-driven, layered, or hexagonal architecture.
|
|
28
|
+
- Evaluating scalability, availability, latency, consistency, durability, security, operability, or cost requirements.
|
|
29
|
+
- Documenting Architecture Decision Records (ADRs) for decisions that will outlive the current implementation task.
|
|
30
|
+
- Reviewing failure modes, operational complexity, deployment topology, infrastructure patterns, or technology tradeoffs.
|
|
31
|
+
- Selecting database or storage technology as part of a broader architecture decision.
|
|
32
|
+
|
|
33
|
+
Do not use it for code-level refactoring, API shape alone, issue triage, task planning, or workflow state transitions unless those activities expose architecture decisions.
|
|
34
|
+
|
|
35
|
+
## Architecture Discipline
|
|
36
|
+
|
|
37
|
+
Before recommending a design, establish:
|
|
38
|
+
|
|
39
|
+
1. Functional goals and excluded goals.
|
|
40
|
+
2. Non-functional requirements and their priority order.
|
|
41
|
+
3. Current constraints: team skills, migration limits, budget, compliance, deployment environment, and operational ownership.
|
|
42
|
+
4. Data ownership, consistency needs, read/write access patterns, retention, and migration constraints.
|
|
43
|
+
5. Failure modes, recovery expectations, observability needs, and operational runbooks.
|
|
44
|
+
|
|
45
|
+
Treat architecture as tradeoff management. For each major decision, state the decision, alternatives considered, why the chosen option fits the constraints, and what it makes harder.
|
|
46
|
+
|
|
47
|
+
## Reference Guide
|
|
48
|
+
|
|
49
|
+
Load detailed guidance only when the context needs it:
|
|
50
|
+
|
|
51
|
+
| Topic | Reference | Load When |
|
|
52
|
+
| --- | --- | --- |
|
|
53
|
+
| Architecture patterns | `references/architecture-patterns.md` | Choosing architectural style or service boundaries |
|
|
54
|
+
| ADR template | `references/adr-template.md` | Recording a long-lived decision |
|
|
55
|
+
| System design | `references/system-design.md` | Producing a full architecture design |
|
|
56
|
+
| Database selection | `references/database-selection.md` | Comparing storage technologies |
|
|
57
|
+
| NFR checklist | `references/nfr-checklist.md` | Eliciting or reviewing quality attributes |
|
|
58
|
+
|
|
59
|
+
## Core Checks
|
|
60
|
+
|
|
61
|
+
### Must Cover
|
|
62
|
+
|
|
63
|
+
- System boundaries and ownership.
|
|
64
|
+
- Functional and non-functional requirements.
|
|
65
|
+
- Architecture options and explicit tradeoffs.
|
|
66
|
+
- Data model, storage, consistency, and migration implications when relevant.
|
|
67
|
+
- Failure modes, degradation behavior, backup/restore, and recovery path.
|
|
68
|
+
- Security, privacy, compliance, and access control concerns.
|
|
69
|
+
- Observability, deployment, operability, and maintenance cost.
|
|
70
|
+
- Risks, mitigations, and open questions.
|
|
71
|
+
|
|
72
|
+
### Avoid
|
|
73
|
+
|
|
74
|
+
- Choosing technology before requirements and constraints are clear.
|
|
75
|
+
- Over-engineering for hypothetical scale.
|
|
76
|
+
- Ignoring operational cost or team ownership.
|
|
77
|
+
- Treating diagrams as proof of a good design.
|
|
78
|
+
- Hiding tradeoffs behind generic "scalable" or "cloud-native" claims.
|
|
79
|
+
- Finalizing unapproved architecture decisions outside the `spec` flow.
|
|
80
|
+
|
|
81
|
+
## Output Shape
|
|
82
|
+
|
|
83
|
+
For architecture discussion or review, produce the smallest useful artifact:
|
|
84
|
+
|
|
85
|
+
1. Requirements and constraints summary.
|
|
86
|
+
2. Options considered.
|
|
87
|
+
3. Recommended architecture with a concise rationale.
|
|
88
|
+
4. Major tradeoffs and rejected alternatives.
|
|
89
|
+
5. Failure modes, operability concerns, and NFR coverage.
|
|
90
|
+
6. ADR drafts for decisions that should be preserved.
|
|
91
|
+
7. Open questions or decisions that must route through `spec`.
|
|
92
|
+
|
|
93
|
+
Use Mermaid diagrams when they clarify component boundaries, data flow, ownership, or deployment topology.
|
|
94
|
+
|
|
95
|
+
### ADR Skeleton
|
|
96
|
+
|
|
97
|
+
```markdown
|
|
98
|
+
# ADR-000: Decision Title
|
|
99
|
+
|
|
100
|
+
## Status
|
|
101
|
+
Proposed
|
|
102
|
+
|
|
103
|
+
## Context
|
|
104
|
+
What problem, constraints, requirements, and forces make this decision necessary?
|
|
105
|
+
|
|
106
|
+
## Decision
|
|
107
|
+
What option is selected?
|
|
108
|
+
|
|
109
|
+
## Alternatives Considered
|
|
110
|
+
- Option A: benefits, costs, and why rejected.
|
|
111
|
+
- Option B: benefits, costs, and why rejected.
|
|
112
|
+
|
|
113
|
+
## Consequences
|
|
114
|
+
- Positive outcomes.
|
|
115
|
+
- Negative outcomes.
|
|
116
|
+
- Follow-up work, migration needs, or monitoring obligations.
|
|
117
|
+
```
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
# ADR Template
|
|
2
|
+
|
|
3
|
+
## ADR Format
|
|
4
|
+
|
|
5
|
+
```markdown
|
|
6
|
+
# ADR-{number}: {Title}
|
|
7
|
+
|
|
8
|
+
## Status
|
|
9
|
+
[Proposed | Accepted | Deprecated | Superseded by ADR-XXX]
|
|
10
|
+
|
|
11
|
+
## Context
|
|
12
|
+
[Describe the situation and forces at play. What is the problem?
|
|
13
|
+
What constraints exist? What are we trying to achieve?]
|
|
14
|
+
|
|
15
|
+
## Decision
|
|
16
|
+
[State the decision clearly. What are we going to do?]
|
|
17
|
+
|
|
18
|
+
## Consequences
|
|
19
|
+
|
|
20
|
+
### Positive
|
|
21
|
+
- [Benefit 1]
|
|
22
|
+
- [Benefit 2]
|
|
23
|
+
|
|
24
|
+
### Negative
|
|
25
|
+
- [Drawback 1]
|
|
26
|
+
- [Drawback 2]
|
|
27
|
+
|
|
28
|
+
### Neutral
|
|
29
|
+
- [Side effect that is neither good nor bad]
|
|
30
|
+
|
|
31
|
+
## Alternatives Considered
|
|
32
|
+
[What other options were evaluated and why were they rejected?]
|
|
33
|
+
|
|
34
|
+
## References
|
|
35
|
+
- [Link to relevant documentation]
|
|
36
|
+
- [Link to discussion/RFC]
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
## Example: Database Selection
|
|
40
|
+
|
|
41
|
+
```markdown
|
|
42
|
+
# ADR-001: Use PostgreSQL for primary database
|
|
43
|
+
|
|
44
|
+
## Status
|
|
45
|
+
Accepted
|
|
46
|
+
|
|
47
|
+
## Context
|
|
48
|
+
We need a relational database for our e-commerce platform that:
|
|
49
|
+
- Handles complex transactions with strong consistency
|
|
50
|
+
- Supports JSON for flexible product attributes
|
|
51
|
+
- Scales to millions of products and orders
|
|
52
|
+
- Works well with our existing Python/Node stack
|
|
53
|
+
|
|
54
|
+
Team has experience with PostgreSQL and MySQL.
|
|
55
|
+
Budget allows for managed database service.
|
|
56
|
+
|
|
57
|
+
## Decision
|
|
58
|
+
Use PostgreSQL as the primary database, hosted on AWS RDS.
|
|
59
|
+
|
|
60
|
+
## Consequences
|
|
61
|
+
|
|
62
|
+
### Positive
|
|
63
|
+
- ACID compliance for financial transactions
|
|
64
|
+
- Rich feature set (JSON, full-text search, CTEs)
|
|
65
|
+
- Strong community and tooling
|
|
66
|
+
- Excellent performance with proper indexing
|
|
67
|
+
- Free and open source
|
|
68
|
+
|
|
69
|
+
### Negative
|
|
70
|
+
- Vertical scaling has limits (addressed with read replicas)
|
|
71
|
+
- Requires DBA expertise for optimization
|
|
72
|
+
- AWS RDS costs for high availability
|
|
73
|
+
|
|
74
|
+
### Neutral
|
|
75
|
+
- Team will need to learn PostgreSQL-specific features
|
|
76
|
+
- Migration from current SQLite dev database needed
|
|
77
|
+
|
|
78
|
+
## Alternatives Considered
|
|
79
|
+
|
|
80
|
+
**MySQL**
|
|
81
|
+
- Rejected: Less feature-rich for JSON operations
|
|
82
|
+
- Considered: Similar cost, familiar to team
|
|
83
|
+
|
|
84
|
+
**MongoDB**
|
|
85
|
+
- Rejected: Relational data model needed for orders/inventory
|
|
86
|
+
- Considered: Great for product catalog flexibility
|
|
87
|
+
|
|
88
|
+
**CockroachDB**
|
|
89
|
+
- Rejected: Higher cost, team unfamiliar
|
|
90
|
+
- Considered: Better horizontal scaling
|
|
91
|
+
|
|
92
|
+
## References
|
|
93
|
+
- https://www.postgresql.org/docs/current/
|
|
94
|
+
- Internal RFC: Database Selection for E-commerce Platform
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
## ADR Naming Convention
|
|
98
|
+
|
|
99
|
+
```
|
|
100
|
+
docs/
|
|
101
|
+
└── adr/
|
|
102
|
+
├── 0001-use-postgresql-database.md
|
|
103
|
+
├── 0002-adopt-microservices.md
|
|
104
|
+
├── 0003-implement-event-sourcing.md
|
|
105
|
+
└── README.md
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
## Quick Reference
|
|
109
|
+
|
|
110
|
+
| Section | Purpose | Key Question |
|
|
111
|
+
|---------|---------|--------------|
|
|
112
|
+
| Status | Current state | Is this active? |
|
|
113
|
+
| Context | Background | Why are we deciding? |
|
|
114
|
+
| Decision | The choice | What did we choose? |
|
|
115
|
+
| Consequences | Impact | What happens now? |
|
|
116
|
+
| Alternatives | Options | What else was considered? |
|
|
@@ -0,0 +1,346 @@
|
|
|
1
|
+
# Architecture Patterns
|
|
2
|
+
|
|
3
|
+
## Pattern Comparison
|
|
4
|
+
|
|
5
|
+
| Pattern | Best For | Team Size | Trade-offs |
|
|
6
|
+
|---------|----------|-----------|------------|
|
|
7
|
+
| **Monolith** | Simple domain, small team | 1-10 | Simple deploy; hard to scale parts |
|
|
8
|
+
| **Modular Monolith** | Growing complexity | 5-20 | Module boundaries; still single deploy |
|
|
9
|
+
| **Microservices** | Complex domain, large org | 20+ | Independent scale; operational complexity |
|
|
10
|
+
| **Serverless** | Variable load, event-driven | Any | Auto-scale; cold starts, vendor lock |
|
|
11
|
+
| **Event-Driven** | Async processing | 10+ | Loose coupling; debugging complexity |
|
|
12
|
+
| **Hexagonal** | Testability, port swapping | Any | Clean boundaries; more indirection |
|
|
13
|
+
| **CQRS** | Read-heavy, complex queries | 10+ | Optimized reads; eventual consistency |
|
|
14
|
+
|
|
15
|
+
## Monolith
|
|
16
|
+
|
|
17
|
+
```
|
|
18
|
+
┌─────────────────────────────────────┐
|
|
19
|
+
│ Application │
|
|
20
|
+
│ ┌─────┐ ┌─────┐ ┌─────┐ │
|
|
21
|
+
│ │Users│ │Orders│ │Products│ │
|
|
22
|
+
│ └─────┘ └─────┘ └─────┘ │
|
|
23
|
+
│ └──────────┬──────────────┘ │
|
|
24
|
+
│ Database │
|
|
25
|
+
└─────────────────────────────────────┘
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
**When to Use**:
|
|
29
|
+
- Starting a new project
|
|
30
|
+
- Small team (< 10 developers)
|
|
31
|
+
- Simple domain
|
|
32
|
+
- Rapid iteration needed
|
|
33
|
+
|
|
34
|
+
**Pros**: Simple deployment, easy debugging, no network latency
|
|
35
|
+
**Cons**: Hard to scale independently, technology locked, deployment risk
|
|
36
|
+
|
|
37
|
+
## Modular Monolith
|
|
38
|
+
|
|
39
|
+
```
|
|
40
|
+
┌───────────────────────────────────────────────┐
|
|
41
|
+
│ Application │
|
|
42
|
+
│ ┌───────────┐ ┌───────────┐ ┌───────────┐ │
|
|
43
|
+
│ │ Users │ │ Orders │ │ Products │ │
|
|
44
|
+
│ │ Module │ │ Module │ │ Module │ │
|
|
45
|
+
│ │ ┌───────┐ │ │ ┌───────┐ │ │ ┌───────┐ │ │
|
|
46
|
+
│ │ │ API │ │ │ │ API │ │ │ │ API │ │ │
|
|
47
|
+
│ │ │Domain │ │ │ │Domain │ │ │ │Domain │ │ │
|
|
48
|
+
│ │ │ Data │ │ │ │ Data │ │ │ │ Data │ │ │
|
|
49
|
+
│ │ └───────┘ │ │ └───────┘ │ │ └───────┘ │ │
|
|
50
|
+
│ └─────┬─────┘ └─────┬─────┘ └─────┬─────┘ │
|
|
51
|
+
│ └───────────────┼───────────────┘ │
|
|
52
|
+
│ Shared DB │
|
|
53
|
+
└───────────────────────────────────────────────┘
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
**When to Use**:
|
|
57
|
+
- Team is growing but not ready for distributed systems
|
|
58
|
+
- Domain boundaries are emerging but service split is premature
|
|
59
|
+
- Need independent module development with single deployment
|
|
60
|
+
- Want to prepare for future microservices extraction
|
|
61
|
+
|
|
62
|
+
**Key Principles**:
|
|
63
|
+
- Each module owns its domain logic, data access, and public API
|
|
64
|
+
- Modules communicate through explicit interfaces, not shared tables
|
|
65
|
+
- Database schema is logically separated per module (separate schemas or table prefixes)
|
|
66
|
+
- Cross-module calls go through published interfaces, never direct data access
|
|
67
|
+
|
|
68
|
+
**Boundary Enforcement**:
|
|
69
|
+
- Compile-time: package visibility, internal packages (Go), module systems
|
|
70
|
+
- Runtime: integration tests that verify no cross-module direct DB access
|
|
71
|
+
- Review-time: ADR for any new cross-module dependency
|
|
72
|
+
|
|
73
|
+
**Pros**: Module autonomy, single deploy, easy extraction to services later
|
|
74
|
+
**Cons**: Still coupled at deploy, shared DB can leak, requires discipline
|
|
75
|
+
|
|
76
|
+
**Migration Path to Microservices**:
|
|
77
|
+
1. Identify the module with the most independent scaling/deployment need
|
|
78
|
+
2. Extract its data into a separate database
|
|
79
|
+
3. Replace in-process calls with API/event calls
|
|
80
|
+
4. Deploy independently
|
|
81
|
+
5. Repeat for next module
|
|
82
|
+
|
|
83
|
+
## Microservices
|
|
84
|
+
|
|
85
|
+
```
|
|
86
|
+
┌──────────┐ ┌──────────┐ ┌──────────┐
|
|
87
|
+
│ Users │ │ Orders │ │ Products │
|
|
88
|
+
│ Service │ │ Service │ │ Service │
|
|
89
|
+
└────┬─────┘ └────┬─────┘ └────┬─────┘
|
|
90
|
+
│ │ │
|
|
91
|
+
┌────▼────┐ ┌────▼────┐ ┌────▼────┐
|
|
92
|
+
│ User DB │ │Order DB │ │ Prod DB │
|
|
93
|
+
└─────────┘ └─────────┘ └─────────┘
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
**When to Use**:
|
|
97
|
+
- Large team (20+ developers)
|
|
98
|
+
- Complex domain with clear boundaries
|
|
99
|
+
- Different scaling requirements per service
|
|
100
|
+
- Polyglot technology needs
|
|
101
|
+
|
|
102
|
+
**Pros**: Independent scaling, team autonomy, fault isolation
|
|
103
|
+
**Cons**: Distributed system complexity, eventual consistency, operational overhead
|
|
104
|
+
|
|
105
|
+
**Prerequisites (Do Not Skip)**:
|
|
106
|
+
- Automated CI/CD pipeline per service
|
|
107
|
+
- Centralized logging and distributed tracing
|
|
108
|
+
- Service discovery and load balancing
|
|
109
|
+
- Health checks and circuit breakers
|
|
110
|
+
- Clear ownership model (one team per service)
|
|
111
|
+
|
|
112
|
+
## Hexagonal Architecture (Ports and Adapters)
|
|
113
|
+
|
|
114
|
+
```
|
|
115
|
+
┌─────────────────────────────────┐
|
|
116
|
+
│ Application │
|
|
117
|
+
┌─────────┐ │ ┌───────────────────────────┐ │ ┌─────────┐
|
|
118
|
+
│ HTTP │──Port──│ │ │ │──Port──│Database │
|
|
119
|
+
│ Adapter │ (in) │ │ Domain Core │ │ (out) │ Adapter │
|
|
120
|
+
└─────────┘ │ │ │ │ └─────────┘
|
|
121
|
+
│ │ - Entities │ │
|
|
122
|
+
┌─────────┐ │ │ - Value Objects │ │ ┌─────────┐
|
|
123
|
+
│ gRPC │──Port──│ │ - Domain Services │ │──Port──│ Queue │
|
|
124
|
+
│ Adapter │ (in) │ │ - Repository Interfaces │ │ (out) │ Adapter │
|
|
125
|
+
└─────────┘ │ │ │ │ └─────────┘
|
|
126
|
+
│ └───────────────────────────┘ │
|
|
127
|
+
┌─────────┐ │ │ ┌─────────┐
|
|
128
|
+
│ CLI │──Port──│ │──Port──│ Cache │
|
|
129
|
+
│ Adapter │ (in) │ │ (out) │ Adapter │
|
|
130
|
+
└─────────┘ └─────────────────────────────────┘ └─────────┘
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
**When to Use**:
|
|
134
|
+
- Domain logic is complex and must be tested without infrastructure
|
|
135
|
+
- Multiple entry points (HTTP, gRPC, CLI, events) drive the same logic
|
|
136
|
+
- Infrastructure may change (swap databases, message queues, providers)
|
|
137
|
+
- Long-lived system where maintainability is more important than speed-to-first-deploy
|
|
138
|
+
|
|
139
|
+
**Key Principles**:
|
|
140
|
+
- Domain core has zero dependencies on frameworks, databases, or transport
|
|
141
|
+
- Ports are interfaces defined by the domain (what it needs, what it offers)
|
|
142
|
+
- Adapters implement ports and live outside the core
|
|
143
|
+
- Dependency direction always points inward (adapters depend on ports, never reverse)
|
|
144
|
+
|
|
145
|
+
**Inbound Ports** (Driving): Define use cases the outside world can trigger
|
|
146
|
+
```
|
|
147
|
+
type OrderService interface {
|
|
148
|
+
PlaceOrder(ctx context.Context, cmd PlaceOrderCmd) (OrderID, error)
|
|
149
|
+
CancelOrder(ctx context.Context, id OrderID) error
|
|
150
|
+
}
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
**Outbound Ports** (Driven): Define what the domain needs from infrastructure
|
|
154
|
+
```
|
|
155
|
+
type OrderRepository interface {
|
|
156
|
+
Save(ctx context.Context, order *Order) error
|
|
157
|
+
FindByID(ctx context.Context, id OrderID) (*Order, error)
|
|
158
|
+
}
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
**Testing Benefits**:
|
|
162
|
+
- Unit test domain logic with in-memory adapters
|
|
163
|
+
- Integration test adapters against real infrastructure
|
|
164
|
+
- E2E test through inbound adapters against the full stack
|
|
165
|
+
|
|
166
|
+
**Pros**: Testable, swappable infrastructure, clear boundaries, long-term maintainability
|
|
167
|
+
**Cons**: More indirection, initial boilerplate, over-engineering risk for simple CRUD
|
|
168
|
+
|
|
169
|
+
## Event-Driven
|
|
170
|
+
|
|
171
|
+
```
|
|
172
|
+
┌──────────┐ ┌─────────────┐ ┌──────────┐
|
|
173
|
+
│ Producer │────▶│ Message Bus │────▶│ Consumer │
|
|
174
|
+
└──────────┘ │ (Kafka) │ └──────────┘
|
|
175
|
+
└─────────────┘
|
|
176
|
+
│
|
|
177
|
+
▼
|
|
178
|
+
┌──────────┐
|
|
179
|
+
│ Consumer │
|
|
180
|
+
└──────────┘
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
**When to Use**:
|
|
184
|
+
- Async processing required
|
|
185
|
+
- Loose coupling between services
|
|
186
|
+
- Event sourcing needs
|
|
187
|
+
- High throughput messaging
|
|
188
|
+
|
|
189
|
+
**Pros**: Decoupled services, scalable, audit trail
|
|
190
|
+
**Cons**: Eventual consistency, debugging complexity, message ordering
|
|
191
|
+
|
|
192
|
+
## CQRS (Command Query Responsibility Segregation)
|
|
193
|
+
|
|
194
|
+
```
|
|
195
|
+
┌─────────┐ ┌─────────────┐
|
|
196
|
+
│ Commands│────────▶│ Write Model │──┐
|
|
197
|
+
└─────────┘ └─────────────┘ │
|
|
198
|
+
▼
|
|
199
|
+
┌──────────┐
|
|
200
|
+
│ Events │
|
|
201
|
+
└──────────┘
|
|
202
|
+
│
|
|
203
|
+
┌─────────┐ ┌─────────────┐ │
|
|
204
|
+
│ Queries │◀────────│ Read Model │◀─┘
|
|
205
|
+
└─────────┘ └─────────────┘
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
**When to Use**:
|
|
209
|
+
- Read/write ratio heavily skewed (10:1 or more)
|
|
210
|
+
- Complex read queries that don't map to the write model
|
|
211
|
+
- Event sourcing architecture
|
|
212
|
+
- Different optimization needs for reads vs writes
|
|
213
|
+
|
|
214
|
+
**CQRS + Event Sourcing Detail**:
|
|
215
|
+
|
|
216
|
+
```
|
|
217
|
+
Command ──▶ Aggregate ──▶ Events ──▶ Event Store
|
|
218
|
+
│
|
|
219
|
+
┌────┴────┐
|
|
220
|
+
▼ ▼
|
|
221
|
+
┌─────────┐ ┌─────────┐
|
|
222
|
+
│Read DB 1│ │Read DB 2│
|
|
223
|
+
│(search) │ │(reports)│
|
|
224
|
+
└─────────┘ └─────────┘
|
|
225
|
+
```
|
|
226
|
+
|
|
227
|
+
**Event Sourcing Principles**:
|
|
228
|
+
- Store events as the source of truth, not current state
|
|
229
|
+
- Rebuild current state by replaying events
|
|
230
|
+
- Events are immutable and append-only
|
|
231
|
+
- Snapshots optimize replay for aggregates with many events
|
|
232
|
+
|
|
233
|
+
**When NOT to Use CQRS**:
|
|
234
|
+
- Simple CRUD with balanced read/write
|
|
235
|
+
- Small team without event-driven experience
|
|
236
|
+
- Strong consistency requirements everywhere (CQRS introduces eventual consistency)
|
|
237
|
+
|
|
238
|
+
**Pros**: Optimized reads, audit trail, temporal queries, scalable
|
|
239
|
+
**Cons**: Eventual consistency, complexity, event versioning, debugging difficulty
|
|
240
|
+
|
|
241
|
+
## Saga Pattern
|
|
242
|
+
|
|
243
|
+
Use Sagas to coordinate multi-service transactions without distributed locks.
|
|
244
|
+
|
|
245
|
+
```
|
|
246
|
+
┌─────────┐ ┌─────────┐ ┌─────────┐ ┌─────────┐
|
|
247
|
+
│ Order │───▶│ Payment │───▶│ Stock │───▶│Shipping │
|
|
248
|
+
│ Service │ │ Service │ │ Service │ │ Service │
|
|
249
|
+
└─────────┘ └─────────┘ └─────────┘ └─────────┘
|
|
250
|
+
│ │ │ │
|
|
251
|
+
▼ ▼ ▼ ▼
|
|
252
|
+
T1: Create T2: Charge T3: Reserve T4: Ship
|
|
253
|
+
Order Payment Stock Package
|
|
254
|
+
│ │ │ │
|
|
255
|
+
▼ ▼ ▼ ▼
|
|
256
|
+
C1: Cancel C2: Refund C3: Release C4: Cancel
|
|
257
|
+
Order Payment Stock Shipment
|
|
258
|
+
```
|
|
259
|
+
|
|
260
|
+
### Choreography vs Orchestration
|
|
261
|
+
|
|
262
|
+
| Aspect | Choreography | Orchestration |
|
|
263
|
+
|--------|-------------|---------------|
|
|
264
|
+
| Coordination | Event-driven, no central control | Central orchestrator directs steps |
|
|
265
|
+
| Coupling | Loose; services react to events | Orchestrator knows all participants |
|
|
266
|
+
| Visibility | Hard to trace full flow | Single place shows entire flow |
|
|
267
|
+
| Complexity | Grows with participant count | Grows with flow logic |
|
|
268
|
+
| Best for | Simple flows (2-4 steps) | Complex flows (5+ steps, conditions) |
|
|
269
|
+
|
|
270
|
+
### Choreography Example
|
|
271
|
+
|
|
272
|
+
```
|
|
273
|
+
OrderService publishes: OrderCreated
|
|
274
|
+
→ PaymentService listens, charges, publishes: PaymentCompleted
|
|
275
|
+
→ StockService listens, reserves, publishes: StockReserved
|
|
276
|
+
→ ShippingService listens, ships, publishes: ShipmentCreated
|
|
277
|
+
|
|
278
|
+
On failure at any step:
|
|
279
|
+
Service publishes compensation event (e.g., PaymentFailed)
|
|
280
|
+
→ Upstream services listen and execute compensating transactions
|
|
281
|
+
```
|
|
282
|
+
|
|
283
|
+
### Orchestration Example
|
|
284
|
+
|
|
285
|
+
```
|
|
286
|
+
OrderSaga (orchestrator):
|
|
287
|
+
1. Call PaymentService.Charge()
|
|
288
|
+
- On success → step 2
|
|
289
|
+
- On failure → Cancel Order
|
|
290
|
+
2. Call StockService.Reserve()
|
|
291
|
+
- On success → step 3
|
|
292
|
+
- On failure → Refund Payment, Cancel Order
|
|
293
|
+
3. Call ShippingService.Ship()
|
|
294
|
+
- On success → Complete
|
|
295
|
+
- On failure → Release Stock, Refund Payment, Cancel Order
|
|
296
|
+
```
|
|
297
|
+
|
|
298
|
+
### Saga Design Rules
|
|
299
|
+
|
|
300
|
+
- Each step must have a compensating transaction
|
|
301
|
+
- Compensating transactions must be idempotent (retries are safe)
|
|
302
|
+
- Design for partial failure: any step can fail at any time
|
|
303
|
+
- Use timeouts with compensation for steps that may hang
|
|
304
|
+
- Store saga state for recovery after crashes
|
|
305
|
+
- Prefer orchestration for flows with complex branching or conditional logic
|
|
306
|
+
- Prefer choreography for simple linear flows with few participants
|
|
307
|
+
|
|
308
|
+
## Serverless
|
|
309
|
+
|
|
310
|
+
**When to Use**:
|
|
311
|
+
- Variable or unpredictable load
|
|
312
|
+
- Event-driven processing (file uploads, webhooks, schedules)
|
|
313
|
+
- Cost optimization for low-traffic workloads
|
|
314
|
+
- Rapid prototyping without infrastructure management
|
|
315
|
+
|
|
316
|
+
**Considerations**:
|
|
317
|
+
- Cold start latency (100ms–3s depending on runtime and dependencies)
|
|
318
|
+
- Execution time limits (15 min for AWS Lambda)
|
|
319
|
+
- Stateless by design; external state in DB/cache/queue
|
|
320
|
+
- Vendor lock-in risk; abstract business logic from provider APIs
|
|
321
|
+
- Monitoring and debugging is harder than traditional servers
|
|
322
|
+
|
|
323
|
+
## Quick Decision Guide
|
|
324
|
+
|
|
325
|
+
| Requirement | Recommended Pattern |
|
|
326
|
+
|-------------|---------------------|
|
|
327
|
+
| Simple CRUD app | Monolith |
|
|
328
|
+
| Growing startup | Modular Monolith |
|
|
329
|
+
| Enterprise scale | Microservices |
|
|
330
|
+
| Variable load | Serverless |
|
|
331
|
+
| Async processing | Event-Driven |
|
|
332
|
+
| Read-heavy | CQRS |
|
|
333
|
+
| Complex domain, testability | Hexagonal |
|
|
334
|
+
| Multi-service transactions | Saga |
|
|
335
|
+
| Complex domain + team autonomy | Microservices + Event-Driven |
|
|
336
|
+
|
|
337
|
+
## Anti-Patterns
|
|
338
|
+
|
|
339
|
+
| Anti-Pattern | Symptom | Fix |
|
|
340
|
+
|---|---|---|
|
|
341
|
+
| Distributed Monolith | Services share DB or deploy together | Enforce data ownership, async communication |
|
|
342
|
+
| Shared Nothing Fallacy | Every service duplicates infrastructure | Shared platform services (logging, auth, config) |
|
|
343
|
+
| Premature Microservices | < 10 devs, unclear boundaries | Start monolith, extract when boundaries are proven |
|
|
344
|
+
| CQRS Everywhere | Simple CRUD with CQRS complexity | Use CQRS only for genuinely asymmetric read/write |
|
|
345
|
+
| Event Soup | Everything is an event, no clear flow | Define event categories: domain, integration, notification |
|
|
346
|
+
| Saga Without Compensation | Distributed flow without rollback plan | Design compensation for every step before building |
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
# Database Selection
|
|
2
|
+
|
|
3
|
+
## Database Types
|
|
4
|
+
|
|
5
|
+
| Type | Examples | Best For |
|
|
6
|
+
|------|----------|----------|
|
|
7
|
+
| **Relational** | PostgreSQL, MySQL | Transactions, complex queries, relationships |
|
|
8
|
+
| **Document** | MongoDB, Firestore | Flexible schemas, rapid iteration |
|
|
9
|
+
| **Key-Value** | Redis, DynamoDB | Caching, sessions, high throughput |
|
|
10
|
+
| **Time-Series** | TimescaleDB, InfluxDB | Metrics, IoT, analytics |
|
|
11
|
+
| **Graph** | Neo4j, Neptune | Relationships, social networks |
|
|
12
|
+
| **Search** | Elasticsearch, Meilisearch | Full-text search, logs |
|
|
13
|
+
|
|
14
|
+
## Relational (PostgreSQL, MySQL)
|
|
15
|
+
|
|
16
|
+
```
|
|
17
|
+
Best For:
|
|
18
|
+
- Financial transactions (ACID compliance)
|
|
19
|
+
- Complex queries with joins
|
|
20
|
+
- Data integrity requirements
|
|
21
|
+
- Structured, predictable schemas
|
|
22
|
+
|
|
23
|
+
When to Avoid:
|
|
24
|
+
- Highly variable schemas
|
|
25
|
+
- Massive horizontal scaling needs
|
|
26
|
+
- Simple key-value access patterns
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
| Feature | PostgreSQL | MySQL |
|
|
30
|
+
|---------|------------|-------|
|
|
31
|
+
| JSON support | Excellent (JSONB) | Good (JSON) |
|
|
32
|
+
| Full-text search | Built-in | Basic |
|
|
33
|
+
| Extensions | Rich ecosystem | Limited |
|
|
34
|
+
| Replication | Streaming, logical | Statement, row-based |
|
|
35
|
+
|
|
36
|
+
## Document (MongoDB, Firestore)
|
|
37
|
+
|
|
38
|
+
```
|
|
39
|
+
Best For:
|
|
40
|
+
- Flexible, evolving schemas
|
|
41
|
+
- Hierarchical data (nested documents)
|
|
42
|
+
- Rapid prototyping
|
|
43
|
+
- Content management
|
|
44
|
+
|
|
45
|
+
When to Avoid:
|
|
46
|
+
- Complex transactions across documents
|
|
47
|
+
- Heavy relational queries
|
|
48
|
+
- Strict schema requirements
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
## Key-Value (Redis, DynamoDB)
|
|
52
|
+
|
|
53
|
+
```
|
|
54
|
+
Best For:
|
|
55
|
+
- Session storage
|
|
56
|
+
- Caching layer
|
|
57
|
+
- Real-time leaderboards
|
|
58
|
+
- Rate limiting counters
|
|
59
|
+
|
|
60
|
+
When to Avoid:
|
|
61
|
+
- Complex queries
|
|
62
|
+
- Relational data
|
|
63
|
+
- Large value sizes (>1MB)
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
## Time-Series (TimescaleDB, InfluxDB)
|
|
67
|
+
|
|
68
|
+
```
|
|
69
|
+
Best For:
|
|
70
|
+
- Metrics and monitoring
|
|
71
|
+
- IoT sensor data
|
|
72
|
+
- Financial tick data
|
|
73
|
+
- Event logging with timestamps
|
|
74
|
+
|
|
75
|
+
When to Avoid:
|
|
76
|
+
- Frequent updates to existing records
|
|
77
|
+
- Complex relational queries
|
|
78
|
+
- Non-time-based access patterns
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
## Decision Matrix
|
|
82
|
+
|
|
83
|
+
| Requirement | Recommended |
|
|
84
|
+
|-------------|-------------|
|
|
85
|
+
| ACID transactions | PostgreSQL, MySQL |
|
|
86
|
+
| Flexible schema | MongoDB, Firestore |
|
|
87
|
+
| High-speed caching | Redis |
|
|
88
|
+
| Time-series data | TimescaleDB, InfluxDB |
|
|
89
|
+
| Social relationships | Neo4j |
|
|
90
|
+
| Full-text search | Elasticsearch |
|
|
91
|
+
| Serverless scale | DynamoDB, Firestore |
|
|
92
|
+
|
|
93
|
+
## Quick Reference
|
|
94
|
+
|
|
95
|
+
| Question | If Yes → |
|
|
96
|
+
|----------|----------|
|
|
97
|
+
| Need ACID transactions? | Relational (PostgreSQL) |
|
|
98
|
+
| Schema changes frequently? | Document (MongoDB) |
|
|
99
|
+
| Sub-millisecond reads? | Key-Value (Redis) |
|
|
100
|
+
| Time-based queries? | Time-Series |
|
|
101
|
+
| Traversing relationships? | Graph (Neo4j) |
|
|
102
|
+
| Full-text search primary? | Elasticsearch |
|