@ryuenn3123/agentic-senior-core 1.8.0 → 1.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/.agent-context/blueprints/mobile-app.md +21 -0
- package/.agent-context/review-checklists/frontend-skill-parity.md +28 -0
- package/.agent-context/skills/README.md +63 -0
- package/.agent-context/skills/backend/README.md +68 -0
- package/.agent-context/skills/backend/architecture.md +361 -0
- package/.agent-context/skills/backend/data-access.md +231 -0
- package/.agent-context/skills/backend/errors.md +138 -0
- package/.agent-context/skills/backend/validation.md +117 -0
- package/.agent-context/skills/backend.md +29 -0
- package/.agent-context/skills/cli/README.md +50 -0
- package/.agent-context/skills/cli/init.md +38 -0
- package/.agent-context/skills/cli/output.md +36 -0
- package/.agent-context/skills/cli/upgrade.md +38 -0
- package/.agent-context/skills/cli.md +29 -0
- package/.agent-context/skills/distribution/README.md +19 -0
- package/.agent-context/skills/distribution/compatibility.md +32 -0
- package/.agent-context/skills/distribution/publish.md +37 -0
- package/.agent-context/skills/distribution/rollback.md +32 -0
- package/.agent-context/skills/distribution.md +29 -0
- package/.agent-context/skills/frontend/README.md +36 -0
- package/.agent-context/skills/frontend/accessibility.md +107 -0
- package/.agent-context/skills/frontend/motion.md +67 -0
- package/.agent-context/skills/frontend/performance.md +63 -0
- package/.agent-context/skills/frontend/ui-architecture.md +128 -0
- package/.agent-context/skills/frontend.md +30 -0
- package/.agent-context/skills/fullstack/README.md +19 -0
- package/.agent-context/skills/fullstack/contracts.md +53 -0
- package/.agent-context/skills/fullstack/end-to-end.md +42 -0
- package/.agent-context/skills/fullstack/feature-slicing.md +65 -0
- package/.agent-context/skills/fullstack.md +27 -0
- package/.agent-context/skills/index.json +107 -0
- package/.agent-context/skills/review-quality/README.md +19 -0
- package/.agent-context/skills/review-quality/benchmark.md +30 -0
- package/.agent-context/skills/review-quality/planning.md +38 -0
- package/.agent-context/skills/review-quality/security.md +34 -0
- package/.agent-context/skills/review-quality.md +28 -0
- package/.agent-context/stacks/flutter.md +16 -0
- package/.agent-context/stacks/react-native.md +16 -0
- package/.agent-context/state/benchmark-analysis.json +431 -0
- package/.agent-context/state/benchmark-thresholds.json +10 -0
- package/.agent-context/state/benchmark-watchlist.json +19 -0
- package/.agent-context/state/skill-platform.json +38 -0
- package/.cursorrules +1 -1
- package/.github/workflows/benchmark-intelligence.yml +50 -0
- package/.windsurfrules +1 -1
- package/README.md +81 -2
- package/bin/agentic-senior-core.js +412 -3
- package/package.json +4 -2
- package/scripts/benchmark-gate.mjs +121 -0
- package/scripts/benchmark-intelligence.mjs +140 -0
- package/scripts/skill-tier-policy.mjs +76 -0
- package/scripts/validate.mjs +82 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# Mobile App Blueprint
|
|
2
|
+
|
|
3
|
+
This blueprint defines the starter shape for a mobile product that needs a clean separation between UI, device integration, and backend contracts.
|
|
4
|
+
|
|
5
|
+
## Structure
|
|
6
|
+
|
|
7
|
+
- Transport: device events, navigation entry points, push notifications, and platform channels.
|
|
8
|
+
- Service: orchestration, screen-level state, validation, and user-facing workflows.
|
|
9
|
+
- Repository: remote API clients, local storage adapters, and persistence abstractions.
|
|
10
|
+
|
|
11
|
+
## Starter Rules
|
|
12
|
+
|
|
13
|
+
- Keep screens focused on rendering and user interaction only.
|
|
14
|
+
- Move API access, caching, and serialization into adapter layers.
|
|
15
|
+
- Use consistent error handling for offline, permission, and platform failures.
|
|
16
|
+
- Add release checks for signing, packaging, and crash telemetry before shipping.
|
|
17
|
+
|
|
18
|
+
## Recommended Stack Pairings
|
|
19
|
+
|
|
20
|
+
- React Native for teams that want JavaScript or TypeScript alignment.
|
|
21
|
+
- Flutter for teams that want a strongly structured UI toolkit.
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# Frontend Skill Parity Checklist
|
|
2
|
+
|
|
3
|
+
Use this checklist to enforce mandatory frontend parity aligned with benchmark-driven standards from `MiniMax-AI/skills` `frontend-dev` profile.
|
|
4
|
+
|
|
5
|
+
## Architecture and Composition
|
|
6
|
+
- [ ] Frontend structure follows feature-driven organization.
|
|
7
|
+
- [ ] Smart and dumb component separation is explicit and documented.
|
|
8
|
+
- [ ] Server state and client state boundaries are documented and enforced.
|
|
9
|
+
|
|
10
|
+
## Interaction and Motion
|
|
11
|
+
- [ ] Primary user journey includes intentional animation without motion overload.
|
|
12
|
+
- [ ] Reduced-motion fallback behavior is implemented and documented.
|
|
13
|
+
- [ ] Transition timing and easing are consistent across key screens.
|
|
14
|
+
|
|
15
|
+
## Accessibility and Responsiveness
|
|
16
|
+
- [ ] Keyboard navigation works on all critical flows.
|
|
17
|
+
- [ ] Contrast, typography scale, and focus visibility pass baseline checks.
|
|
18
|
+
- [ ] Layout behavior is validated across mobile and desktop breakpoints.
|
|
19
|
+
|
|
20
|
+
## UX Narrative and Conversion Clarity
|
|
21
|
+
- [ ] Page hierarchy communicates value proposition within first viewport.
|
|
22
|
+
- [ ] Primary calls to action are explicit and consistently placed.
|
|
23
|
+
- [ ] Error and empty states contain actionable guidance.
|
|
24
|
+
|
|
25
|
+
## Release Evidence
|
|
26
|
+
- [ ] Frontend parity checklist artifact is attached to release evidence.
|
|
27
|
+
- [ ] Frontend usability audit report is attached to release evidence.
|
|
28
|
+
- [ ] Any parity waiver includes owner, expiry, and risk statement.
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
# Skill Platform
|
|
2
|
+
|
|
3
|
+
The skill platform is the internal skill system for Agentic-Senior-Core.
|
|
4
|
+
|
|
5
|
+
## Design Goals
|
|
6
|
+
- Unify skill content from benchmark repositories into one governed platform.
|
|
7
|
+
- Make `advance` the default operating tier.
|
|
8
|
+
- Keep `standard` only as a compatibility fallback.
|
|
9
|
+
- Require evidence, validation, and release gates for every skill pack.
|
|
10
|
+
|
|
11
|
+
## Tier Model
|
|
12
|
+
|
|
13
|
+
### standard
|
|
14
|
+
- Compatibility mode only.
|
|
15
|
+
- Minimal guidance.
|
|
16
|
+
- No default status for new work.
|
|
17
|
+
|
|
18
|
+
### advance
|
|
19
|
+
- Default operating tier.
|
|
20
|
+
- Efficient, opinionated, and production-aware.
|
|
21
|
+
- Used for normal feature delivery.
|
|
22
|
+
|
|
23
|
+
### expert
|
|
24
|
+
- For complex architecture, integration, and critical refactors.
|
|
25
|
+
- Requires stronger evidence and review depth.
|
|
26
|
+
|
|
27
|
+
### above
|
|
28
|
+
- For release-critical, cross-domain, or enterprise governance work.
|
|
29
|
+
- Requires full evidence bundle and explicit owner signoff.
|
|
30
|
+
|
|
31
|
+
## Domain Packs
|
|
32
|
+
- [Frontend](frontend/README.md)
|
|
33
|
+
- [Backend](backend/README.md)
|
|
34
|
+
- [Fullstack](fullstack/README.md)
|
|
35
|
+
- [CLI](cli/README.md)
|
|
36
|
+
- [Distribution](distribution/README.md)
|
|
37
|
+
- [Review Quality](review-quality/README.md)
|
|
38
|
+
|
|
39
|
+
## Folder Structure
|
|
40
|
+
```text
|
|
41
|
+
.agent-context/skills/
|
|
42
|
+
├── README.md
|
|
43
|
+
├── index.json
|
|
44
|
+
├── frontend/
|
|
45
|
+
├── backend/
|
|
46
|
+
├── fullstack/
|
|
47
|
+
├── cli/
|
|
48
|
+
├── distribution/
|
|
49
|
+
└── review-quality/
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
Each domain folder has its own README plus topic-level docs so the platform can scale like a curated skills library.
|
|
53
|
+
|
|
54
|
+
## Benchmark Sources
|
|
55
|
+
- sickn33/antigravity-awesome-skills
|
|
56
|
+
- github/awesome-copilot
|
|
57
|
+
- MiniMax-AI/skills
|
|
58
|
+
|
|
59
|
+
## Platform Rules
|
|
60
|
+
- Every skill pack must define purpose, inputs, outputs, validation, evidence, and fallback.
|
|
61
|
+
- Every skill pack must state the default tier it targets.
|
|
62
|
+
- Every release must include a skill parity check for the configured tiers.
|
|
63
|
+
- Every deviation from the default tier must be justified in the evidence bundle.
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
# Backend Engineering Skills
|
|
2
|
+
|
|
3
|
+
The backend domain covers server-side architecture, business logic, data access patterns, error handling, and operational concerns. Content consolidated from **antigravity-awesome-skills**, **awesome-copilot**, and **MiniMax-AI/skills**, with supercharging improvements ("above the line" automation and enforcement).
|
|
4
|
+
|
|
5
|
+
## Topics
|
|
6
|
+
|
|
7
|
+
- **[architecture.md](architecture.md)** - Layered design (Transport->Service->Repository), monolith vs microservices, SoC patterns, dependency management, strangler fig migrations
|
|
8
|
+
- **[validation.md](validation.md)** - Input sanitization, schema validation at API boundary, parameterized queries, typed errors
|
|
9
|
+
- **[data-access.md](data-access.md)** - Database design (3NF), query optimization (N+1 detection), safe zero-downtime migrations, indexing strategy
|
|
10
|
+
- **[errors.md](errors.md)** - Typed error codes, recovery patterns, debugging protocols, logging + correlation IDs
|
|
11
|
+
|
|
12
|
+
## What Makes Ours Different
|
|
13
|
+
|
|
14
|
+
- Layered Architecture (awesome-copilot) + Microservices Decision Framework (antigravity) + Project Structure (minimax)
|
|
15
|
+
- Dependency Auditor (ABOVE LINE) - Detect circular dependencies and enforce Transport->Service->Repository direction
|
|
16
|
+
- Zero-Downtime Migration Validator (ABOVE LINE) - Scan migrations, flag risky patterns, and suggest remediation
|
|
17
|
+
- Secrets Detector (ABOVE LINE) - Static scan for hardcoded API keys and database passwords
|
|
18
|
+
|
|
19
|
+
## Recommended Reading Order
|
|
20
|
+
|
|
21
|
+
1. `architecture.md` - Understand mental models (EXPERT tier)
|
|
22
|
+
2. `validation.md` - Protect at boundaries (ADVANCE tier)
|
|
23
|
+
3. `data-access.md` - Query strategy (EXPERT tier)
|
|
24
|
+
4. `errors.md` - Error handling pipeline (ADVANCE tier)
|
|
25
|
+
|
|
26
|
+
Then run:
|
|
27
|
+
```bash
|
|
28
|
+
npm run validate # Ensure tier structure
|
|
29
|
+
npm test # Verify examples compile
|
|
30
|
+
agentic-senior-core skill backend --tier expert # See consolidated content
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## Tier Defaults per Topic
|
|
34
|
+
|
|
35
|
+
| Topic | Default Tier | Focus |
|
|
36
|
+
|-------|--------------|-------|
|
|
37
|
+
| architecture | EXPERT | Layering, dependencies, monolith->microservices migration |
|
|
38
|
+
| validation | ADVANCE | Boundary protection, Zod/Pydantic examples |
|
|
39
|
+
| data-access | EXPERT | 3NF design, N+1 patterns, safe migrations, indexed FKs |
|
|
40
|
+
| errors | ADVANCE | Typed codes, recovery, correlation IDs, logging |
|
|
41
|
+
|
|
42
|
+
## Comparative Coverage vs Benchmarks
|
|
43
|
+
|
|
44
|
+
| Aspect | antigravity | awesome-copilot | MiniMax | Ours |
|
|
45
|
+
|--------|-------------|-----------------|---------|------|
|
|
46
|
+
| Layered Architecture | Medium | High | Medium | High + policy enforcement |
|
|
47
|
+
| Monolith to Microservices | High | Medium | Medium | High + migration strategy |
|
|
48
|
+
| Database Design | Medium | High | Medium | High + guardrails |
|
|
49
|
+
| Error Handling | High | Medium | Medium | High + typed recovery path |
|
|
50
|
+
| Automation Tools | None | None | None | Dependency auditor, migration validator, secrets scanner |
|
|
51
|
+
|
|
52
|
+
## How to Use
|
|
53
|
+
|
|
54
|
+
**For init workflow:**
|
|
55
|
+
```bash
|
|
56
|
+
agentic-senior-core init --stack typescript --blueprint api-nextjs
|
|
57
|
+
# Activates: frontend, fullstack, backend, cli skills
|
|
58
|
+
# Default tier: advance
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
**For explicit skill selection:**
|
|
62
|
+
```bash
|
|
63
|
+
agentic-senior-core skill backend --tier expert
|
|
64
|
+
# Outputs: architecture + validation + data-access + errors at EXPERT level
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
**For skill reference in .cursorrules:**
|
|
68
|
+
Content from this domain automatically includes in `.cursorrules` when activated.
|
|
@@ -0,0 +1,361 @@
|
|
|
1
|
+
# Backend Architecture
|
|
2
|
+
|
|
3
|
+
**Tier:** EXPERT | **Source:** awesome-copilot (layering) + antigravity (microservices) + minimax (project structure)
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
Backend architecture defines how code is organized, how concerns separate, and how services scale. Three critical decisions:
|
|
8
|
+
1. **Layered separation** - Transport (HTTP) vs Service (logic) vs Repository (data)
|
|
9
|
+
2. **Monolith or microservices** - When to split, when to keep together
|
|
10
|
+
3. **Dependency direction** - Which layers can import which
|
|
11
|
+
|
|
12
|
+
Wrong choices here create spaghetti code, circular dependencies, and costly rewrites. Right choices enable independent scaling, testing, and team autonomy.
|
|
13
|
+
|
|
14
|
+
---
|
|
15
|
+
|
|
16
|
+
## Part 1: Layered Architecture (Transport -> Service -> Repository)
|
|
17
|
+
|
|
18
|
+
### The Model
|
|
19
|
+
|
|
20
|
+
Clean architecture separates concerns into independent layers:
|
|
21
|
+
|
|
22
|
+
```
|
|
23
|
+
┌─────────────────────────────────┐
|
|
24
|
+
│ HTTP / Handlers / Middleware │ <- TRANSPORT LAYER
|
|
25
|
+
├─────────────────────────────────┤
|
|
26
|
+
│ Business Logic / Orchestration │ <- SERVICE LAYER
|
|
27
|
+
├─────────────────────────────────┤
|
|
28
|
+
│ Data Access / Queries / Caching│ <- REPOSITORY LAYER
|
|
29
|
+
├─────────────────────────────────┤
|
|
30
|
+
│ External APIs / Databases │ <- INFRASTRUCTURE
|
|
31
|
+
└─────────────────────────────────┘
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
**Dependency Rule:** Layer below can NEVER import layer above.
|
|
35
|
+
- Transport CAN import Service
|
|
36
|
+
- Service CAN import Repository
|
|
37
|
+
- Repository can NEVER import Service
|
|
38
|
+
- Service can NEVER import Transport
|
|
39
|
+
|
|
40
|
+
### TRANSPORT LAYER (HTTP Handlers, Middleware)
|
|
41
|
+
|
|
42
|
+
**Responsibility:** Parse HTTP requests, serialize responses, handle authentication, logging middleware.
|
|
43
|
+
|
|
44
|
+
**What goes here:**
|
|
45
|
+
- Request validation (type, format checks)
|
|
46
|
+
- Middleware (auth, CORS, rate limiting, logging)
|
|
47
|
+
- Route handlers (receive request -> call service -> return response)
|
|
48
|
+
- Response serialization (JSON, XML, protobuf)
|
|
49
|
+
|
|
50
|
+
**What does NOT go here:**
|
|
51
|
+
- Business logic (validation rules, calculations, state transitions)
|
|
52
|
+
- Database queries
|
|
53
|
+
- Feature flags, configuration decisions
|
|
54
|
+
|
|
55
|
+
**Example (Node.js + Express):**
|
|
56
|
+
```javascript
|
|
57
|
+
// CORRECT: Transport layer
|
|
58
|
+
app.post('/payments/charge',
|
|
59
|
+
authenticate, // Middleware
|
|
60
|
+
validateRequest(chargeSchema), // Format check
|
|
61
|
+
async (req, res) => {
|
|
62
|
+
const result = await paymentService.charge({
|
|
63
|
+
amount: req.body.amount,
|
|
64
|
+
customerId: req.body.customerId,
|
|
65
|
+
idempotencyKey: req.headers['idempotency-key']
|
|
66
|
+
});
|
|
67
|
+
res.json(result);
|
|
68
|
+
}
|
|
69
|
+
);
|
|
70
|
+
|
|
71
|
+
// Service layer has business logic:
|
|
72
|
+
async function charge({ amount, customerId, idempotencyKey }) {
|
|
73
|
+
// Check customer credit, calculate fees, call repository
|
|
74
|
+
// NO HTTP HERE
|
|
75
|
+
}
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
**Anti-Pattern:** Business logic in handler
|
|
79
|
+
|
|
80
|
+
```javascript
|
|
81
|
+
// WRONG: Business logic in transport
|
|
82
|
+
app.post('/payments/charge', async (req, res) => {
|
|
83
|
+
const customer = await db.query('SELECT * FROM customers WHERE id = ?', customerId);
|
|
84
|
+
if (customer.balance < amount) throw new Error('Insufficient funds'); // <- Logic?
|
|
85
|
+
const fee = amount * 0.03 + 0.30; // <- Math in handler?
|
|
86
|
+
const charged = await db.query('UPDATE customers SET balance = balance - ?', amount + fee);
|
|
87
|
+
// ...
|
|
88
|
+
});
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
### SERVICE LAYER (Business Logic, Orchestration)
|
|
92
|
+
|
|
93
|
+
**Responsibility:** Business rules, data transformations, orchestration across repositories, feature flags, error handling.
|
|
94
|
+
|
|
95
|
+
**What goes here:**
|
|
96
|
+
- Validation rules (customer eligibility, amount limits)
|
|
97
|
+
- Business calculations (fees, commissions, discounts)
|
|
98
|
+
- Orchestration (call repo A, then repo B, handle failure)
|
|
99
|
+
- Idempotency keys for distributed transactions
|
|
100
|
+
- Feature flags / circuit breakers
|
|
101
|
+
|
|
102
|
+
**What does NOT go here:**
|
|
103
|
+
- Database queries (use Repository)
|
|
104
|
+
- HTTP parsing, serialization (use Transport)
|
|
105
|
+
- External API calls directly (wrap in Repository-like abstraction)
|
|
106
|
+
|
|
107
|
+
**Example:**
|
|
108
|
+
```javascript
|
|
109
|
+
class PaymentService {
|
|
110
|
+
constructor(customerRepo, paymentRepo, ledgerRepo) {
|
|
111
|
+
this.customerRepo = customerRepo;
|
|
112
|
+
this.paymentRepo = paymentRepo;
|
|
113
|
+
this.ledgerRepo = ledgerRepo;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
async charge({ amount, customerId, idempotencyKey }) {
|
|
117
|
+
// Check idempotency first (prevent double-charge)
|
|
118
|
+
const existing = await this.paymentRepo.findByIdempotencyKey(idempotencyKey);
|
|
119
|
+
if (existing) return existing; // Already charged
|
|
120
|
+
|
|
121
|
+
// Business validation
|
|
122
|
+
const customer = await this.customerRepo.findById(customerId);
|
|
123
|
+
if (!customer) throw new NotFoundError('Customer not found');
|
|
124
|
+
if (customer.status !== 'active') throw new BusinessError('Account inactive');
|
|
125
|
+
if (amount < 50 || amount > 100000) throw new ValidationError('Amount out of range');
|
|
126
|
+
|
|
127
|
+
// Calculate fees
|
|
128
|
+
const fee = this._calculateFee(amount, customer.tier);
|
|
129
|
+
const total = amount + fee;
|
|
130
|
+
|
|
131
|
+
// Orchestrate transaction
|
|
132
|
+
try {
|
|
133
|
+
const payment = await this.paymentRepo.create({
|
|
134
|
+
customerId,
|
|
135
|
+
amount,
|
|
136
|
+
fee,
|
|
137
|
+
total,
|
|
138
|
+
idempotencyKey,
|
|
139
|
+
status: 'pending'
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
await this.ledgerRepo.debit({
|
|
143
|
+
customerId,
|
|
144
|
+
amount: total,
|
|
145
|
+
reason: `Payment ${payment.id}`,
|
|
146
|
+
paymentId: payment.id
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
await this.paymentRepo.update(payment.id, { status: 'completed' });
|
|
150
|
+
return payment;
|
|
151
|
+
} catch (err) {
|
|
152
|
+
await this.paymentRepo.update(payment.id, { status: 'failed', error: err.message });
|
|
153
|
+
throw err;
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
_calculateFee(amount, tier) {
|
|
158
|
+
const baseRate = { silver: 0.029, gold: 0.019, platinum: 0.009 }[tier];
|
|
159
|
+
const flatFee = { silver: 0.50, gold: 0.30, platinum: 0 }[tier];
|
|
160
|
+
return Math.round(amount * baseRate * 100) / 100 + flatFee;
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
### REPOSITORY LAYER (Data Access, Queries)
|
|
166
|
+
|
|
167
|
+
**Responsibility:** Data retrieval, persistence, query optimization, caching, connection pooling.
|
|
168
|
+
|
|
169
|
+
**What goes here:**
|
|
170
|
+
- Database queries (SELECT, INSERT, UPDATE, DELETE)
|
|
171
|
+
- Prepared statements, parameterized queries
|
|
172
|
+
- Indexes, query optimization
|
|
173
|
+
- Batch operations
|
|
174
|
+
- Query caching (cache-aside, write-through)
|
|
175
|
+
- Connection pooling
|
|
176
|
+
|
|
177
|
+
**What does NOT go here:**
|
|
178
|
+
- Business logic (decisions based on data)
|
|
179
|
+
- HTTP handling
|
|
180
|
+
- External API calls (unless wrapping as data source)
|
|
181
|
+
|
|
182
|
+
**Example:**
|
|
183
|
+
```javascript
|
|
184
|
+
class PaymentRepository {
|
|
185
|
+
constructor(db) {
|
|
186
|
+
this.db = db;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
async findByIdempotencyKey(key) {
|
|
190
|
+
return this.db.one(
|
|
191
|
+
'SELECT * FROM payments WHERE idempotency_key = $1',
|
|
192
|
+
[key] // Parameterized query
|
|
193
|
+
);
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
async create(payment) {
|
|
197
|
+
return this.db.one(
|
|
198
|
+
`INSERT INTO payments
|
|
199
|
+
(customer_id, amount, fee, total, idempotency_key, status, created_at)
|
|
200
|
+
VALUES ($1, $2, $3, $4, $5, $6, NOW())
|
|
201
|
+
RETURNING *`,
|
|
202
|
+
[payment.customerId, payment.amount, payment.fee, payment.total,
|
|
203
|
+
payment.idempotencyKey, payment.status]
|
|
204
|
+
);
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
async update(id, updates) {
|
|
208
|
+
const fields = [];
|
|
209
|
+
const values = [];
|
|
210
|
+
let paramCount = 1;
|
|
211
|
+
for (const [key, val] of Object.entries(updates)) {
|
|
212
|
+
fields.push(`${key} = $${paramCount++}`);
|
|
213
|
+
values.push(val);
|
|
214
|
+
}
|
|
215
|
+
values.push(id);
|
|
216
|
+
return this.db.one(
|
|
217
|
+
`UPDATE payments SET ${fields.join(', ')} WHERE id = $${paramCount} RETURNING *`,
|
|
218
|
+
values
|
|
219
|
+
);
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
---
|
|
225
|
+
|
|
226
|
+
## Part 2: Monolith vs Microservices (Decision Framework)
|
|
227
|
+
|
|
228
|
+
### When to Stay Monolithic
|
|
229
|
+
|
|
230
|
+
**Keep monolith if:**
|
|
231
|
+
- Team < 30 people (communication overhead still low)
|
|
232
|
+
- Feature dependencies high (changing one feature requires touching multiple areas)
|
|
233
|
+
- Deployment frequency < weekly (update entire system at once is acceptable)
|
|
234
|
+
- Data strongly coupled (customers, orders, payments in one domain)
|
|
235
|
+
- Performance latency-sensitive < 100ms (in-process calls beat RPC)
|
|
236
|
+
|
|
237
|
+
**Monolith advantages:**
|
|
238
|
+
- Single deployment unit (easier to roll forward/back)
|
|
239
|
+
- ACID transactions easy (in same database)
|
|
240
|
+
- Debugging simpler (logs in one place, single memory space)
|
|
241
|
+
- Performance: in-memory function calls vs HTTP RPC
|
|
242
|
+
|
|
243
|
+
**Example: Monolithic e-commerce platform**
|
|
244
|
+
```
|
|
245
|
+
monolith/
|
|
246
|
+
├── transport/
|
|
247
|
+
│ ├── auth.js
|
|
248
|
+
│ ├── products.js
|
|
249
|
+
│ ├── orders.js
|
|
250
|
+
│ └── payments.js
|
|
251
|
+
├── services/
|
|
252
|
+
│ ├── authService.js
|
|
253
|
+
│ ├── productService.js
|
|
254
|
+
│ ├── orderService.js
|
|
255
|
+
│ └── paymentService.js
|
|
256
|
+
└── repositories/
|
|
257
|
+
├── userRepo.js
|
|
258
|
+
├── productRepo.js
|
|
259
|
+
├── orderRepo.js
|
|
260
|
+
└── paymentRepo.js
|
|
261
|
+
```
|
|
262
|
+
|
|
263
|
+
All services run in same process, same database. Easy to refactor, deploy, test.
|
|
264
|
+
|
|
265
|
+
### When to Split to Microservices
|
|
266
|
+
|
|
267
|
+
**Split ONLY if:**
|
|
268
|
+
- Team > 30 people (need autonomy + independent deployments)
|
|
269
|
+
- Services truly independent (different databases, different deployment cadences)
|
|
270
|
+
- You can tolerate 100-500ms RPC latency between services
|
|
271
|
+
- Each service has independent scaling needs
|
|
272
|
+
|
|
273
|
+
**Microservices disadvantages:**
|
|
274
|
+
- Distributed transactions (eventual consistency or sagas)
|
|
275
|
+
- Debugging spans multiple services/logs (correlation IDs mandatory)
|
|
276
|
+
- RPC latency adds up (cascade failures likely)
|
|
277
|
+
- Ops complexity increases 10x (monitoring, health checks, circuit breakers)
|
|
278
|
+
|
|
279
|
+
**Trigger for splitting:** When layered architecture + teamwork alignment breaks down.
|
|
280
|
+
|
|
281
|
+
**NOT OK to split:**
|
|
282
|
+
- Customer service and Order service can't be truly independent (customers have orders)
|
|
283
|
+
- Payment and Order service tightly coupled (can't process payment independent of order state)
|
|
284
|
+
|
|
285
|
+
**OK to split:**
|
|
286
|
+
- User authentication (separate service, used by many)
|
|
287
|
+
- Notification service (email/SMS, independent of order flow)
|
|
288
|
+
- Analytics service (read-only, independent queries)
|
|
289
|
+
|
|
290
|
+
**Strangler Fig Pattern (low-risk migration):**
|
|
291
|
+
|
|
292
|
+
Start monolithic. When it's time to extract Payment service:
|
|
293
|
+
1. Keep monolith running
|
|
294
|
+
2. Create Payment microservice alongside
|
|
295
|
+
3. Route new Payment requests -> new service
|
|
296
|
+
4. Keep old requests going to monolith's PaymentService
|
|
297
|
+
5. Over months, migrate & retire old code
|
|
298
|
+
6. Remove dependency from monolith
|
|
299
|
+
|
|
300
|
+
```javascript
|
|
301
|
+
// Monolith, gradually being strangled:
|
|
302
|
+
async function charge(customerId, amount) {
|
|
303
|
+
if (featureFlags.usePaymentMicroservice) {
|
|
304
|
+
// Call remote service
|
|
305
|
+
return await paymentMicroservice.charge({ customerId, amount });
|
|
306
|
+
} else {
|
|
307
|
+
// Old in-process service
|
|
308
|
+
return await paymentService.charge({ customerId, amount });
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
```
|
|
312
|
+
|
|
313
|
+
---
|
|
314
|
+
|
|
315
|
+
## Part 3: Dependency Management (ABOVE LINE)
|
|
316
|
+
|
|
317
|
+
### The Problem
|
|
318
|
+
|
|
319
|
+
As codebases grow, circular dependencies emerge:
|
|
320
|
+
- Service imports Repository
|
|
321
|
+
- Repository imports utility in Service (closes circle)
|
|
322
|
+
- Creates tight coupling, hard to test, risky refactors
|
|
323
|
+
|
|
324
|
+
### The Solution: Dependency Auditor
|
|
325
|
+
|
|
326
|
+
**Enforce dependency direction at build time** (ABOVE LINE improvement not in any benchmark repo).
|
|
327
|
+
|
|
328
|
+
**Check:**
|
|
329
|
+
1. Transport layer files import only Transport + Service
|
|
330
|
+
2. Service layer files import only Service + Repository
|
|
331
|
+
3. Repository layer files import only Repository (no Service)
|
|
332
|
+
4. No circular imports within layer
|
|
333
|
+
|
|
334
|
+
**Tool:**
|
|
335
|
+
```bash
|
|
336
|
+
npm run audit:dependencies # Pre-commit gate
|
|
337
|
+
```
|
|
338
|
+
|
|
339
|
+
---
|
|
340
|
+
|
|
341
|
+
## Checklist: Did You Get Architecture Right?
|
|
342
|
+
|
|
343
|
+
Before shipping a new service, verify:
|
|
344
|
+
|
|
345
|
+
- [ ] **Layer separation:** Transport doesn't contain business logic
|
|
346
|
+
- [ ] **Dependency direction:** No circles (Service imports Repo only, not vice versa)
|
|
347
|
+
- [ ] **Repository abstraction:** No business logic in SQL queries
|
|
348
|
+
- [ ] **Service orchestration:** Complex flows live in Service, not Transport
|
|
349
|
+
- [ ] **Error handling:** Errors typed + recovery strategies clear
|
|
350
|
+
- [ ] **Idempotency:** Distributed transactions have idempotency keys
|
|
351
|
+
- [ ] **Feature-based:** Related code lives together, not scattered across service/util folders
|
|
352
|
+
- [ ] **Testing:** Unit tests mock Repository (test business logic), no DB
|
|
353
|
+
- [ ] **Documentation:** README explains layer separation for this service
|
|
354
|
+
|
|
355
|
+
---
|
|
356
|
+
|
|
357
|
+
## References
|
|
358
|
+
|
|
359
|
+
- [Awesome-Copilot Architecture](https://github.com/github/awesome-copilot)
|
|
360
|
+
- [Antigravity Microservices](https://github.com/sickn33/antigravity-awesome-skills)
|
|
361
|
+
- [MiniMax Fullstack Structure](https://github.com/MiniMax-AI/skills)
|