ai-nexus 1.5.0 → 1.5.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/README.ko.md +12 -0
- package/README.md +12 -0
- package/config/skills/database.md +1 -1
- package/config/skills/mongodb.md +182 -0
- package/package.json +1 -1
package/README.ko.md
CHANGED
|
@@ -407,6 +407,18 @@ node bin/ai-nexus.cjs test "your prompt"
|
|
|
407
407
|
|
|
408
408
|
Claude Code만 쓰고 스킬로 충분하면 ai-nexus가 필요 없을 수도 있습니다.
|
|
409
409
|
|
|
410
|
+
**CLAUDE.md나 AGENTS.md에 다 넣으면 되지 않나요?**
|
|
411
|
+
|
|
412
|
+
넣을 수는 있지만 규모가 커지면 문제가 됩니다. CLAUDE.md는 뭘 하든 매 프롬프트마다 전부 로드됩니다. 룰이 5개면 괜찮지만, 50개 이상이면 커밋 메시지 쓸 때 Docker best practices까지 같이 로드되는 거예요. [ETH Zurich 연구](https://arxiv.org/pdf/2602.11988)에서도 이게 성능과 비용 둘 다 악화시킨다고 나왔습니다.
|
|
413
|
+
|
|
414
|
+
ai-nexus는 프롬프트당 관련 있는 2-3개 룰만 로드하고, 나머지는 비활성 상태로 둡니다.
|
|
415
|
+
|
|
416
|
+
**Claude Code 스킬 쓰면 룰이 필요 없지 않나요?**
|
|
417
|
+
|
|
418
|
+
스킬은 `/commit`, `/review`처럼 직접 호출하는 작업 워크플로우에 좋습니다. 하지만 룰을 대체하지는 못해요. 룰은 코딩 컨벤션, 보안 기준, 네이밍 패턴처럼 자동으로 적용되는 가이드라인입니다. 코드 짤 때마다 `/security-checklist`를 기억해서 호출할 수는 없잖아요.
|
|
419
|
+
|
|
420
|
+
ai-nexus는 룰과 스킬 둘 다 프롬프트 기반으로 라우팅해서, 직접 호출하지 않아도 필요한 컨텍스트가 자동으로 로드됩니다.
|
|
421
|
+
|
|
410
422
|
---
|
|
411
423
|
|
|
412
424
|
## 지원하기
|
package/README.md
CHANGED
|
@@ -407,6 +407,18 @@ Skills already handle on-demand loading within Claude Code. ai-nexus is for a di
|
|
|
407
407
|
|
|
408
408
|
If you only use Claude Code and skills cover your needs, you may not need ai-nexus.
|
|
409
409
|
|
|
410
|
+
**Why not just put everything in CLAUDE.md or AGENTS.md?**
|
|
411
|
+
|
|
412
|
+
You can — but it doesn't scale. CLAUDE.md loads on every prompt regardless of what you're doing. With 5 rules, that's fine. With 50+, you're burning tokens on Docker best practices while writing a commit message. The [ETH Zurich study](https://arxiv.org/pdf/2602.11988) shows this hurts both performance and cost.
|
|
413
|
+
|
|
414
|
+
ai-nexus solves this by loading only 2-3 relevant rules per prompt, while keeping the rest parked.
|
|
415
|
+
|
|
416
|
+
**Why not just use Claude Code skills instead of rules?**
|
|
417
|
+
|
|
418
|
+
Skills are great for on-demand workflows you explicitly invoke (`/commit`, `/review`). But they don't replace rules — rules are passive guidelines that apply automatically (coding conventions, security standards, naming patterns). You shouldn't have to remember to invoke `/security-checklist` every time you write code.
|
|
419
|
+
|
|
420
|
+
ai-nexus handles both: it routes rules *and* skills based on your prompt, so the right context loads automatically without you thinking about it.
|
|
421
|
+
|
|
410
422
|
---
|
|
411
423
|
|
|
412
424
|
## Support
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
---
|
|
2
|
+
description: Practical MongoDB / NoSQL best practices for schema design, indexing, aggregation pipeline optimization, and secure production usage.
|
|
3
|
+
keywords: [mongodb, nosql, mongoose, aggregation, index, indexing, compound, ttl, text, schema, embedding, referencing, sharding, transactions, performance, query, pipeline]
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# MongoDB (NoSQL)
|
|
7
|
+
|
|
8
|
+
Practical guidance for building efficient, maintainable, and secure MongoDB-backed applications. Focus is on actionable rules, decision heuristics, and small examples.
|
|
9
|
+
|
|
10
|
+
## When to activate
|
|
11
|
+
- Building or optimizing MongoDB queries or aggregations
|
|
12
|
+
- Designing collection/document schemas
|
|
13
|
+
- Adding or auditing indexes
|
|
14
|
+
- Implementing security for stored data or connections
|
|
15
|
+
- Working on sharding, transactions, or time-series data
|
|
16
|
+
|
|
17
|
+
---
|
|
18
|
+
|
|
19
|
+
## Indexing: when & which type
|
|
20
|
+
- **Single-field**: good for high-cardinality single-field lookups.
|
|
21
|
+
- **Compound**: use when queries filter/sort by multiple fields. Put the most selective / most-filtered field first.
|
|
22
|
+
- Example: `{ age: 1, status: 1 }` helps queries with `age` and `status`.
|
|
23
|
+
- Order matters: `{ status: 1, age: 1 }` won't help a query that only filters by `age`.
|
|
24
|
+
- **Text index**: use for full-text search across string fields. Avoid over-indexing — use dedicated search (e.g., Atlas Search) if heavy usage.
|
|
25
|
+
- **TTL index**: use for expiring ephemeral data (sessions, caches). Set `expireAfterSeconds`.
|
|
26
|
+
- **Wildcard index**: `{ "$**": 1 }` — use sparingly for schemas with many dynamic fields; increases write latency ~15-30% and storage 2-5x.
|
|
27
|
+
- **Practical checks**
|
|
28
|
+
- Run `db.collection.explain('executionStats')` to check index usage.
|
|
29
|
+
- Avoid indexes on very high-write, low-read fields.
|
|
30
|
+
- Remove unused indexes (costly on writes & storage): `db.collection.getIndexes()` + `dropIndex()`.
|
|
31
|
+
|
|
32
|
+
### Mongoose index snippets
|
|
33
|
+
```javascript
|
|
34
|
+
// Compound index (background build to avoid blocking)
|
|
35
|
+
userSchema.index({ email: 1, status: 1 }, { background: true });
|
|
36
|
+
|
|
37
|
+
// TTL index for auto-expiry (e.g., sessions expire after 24h)
|
|
38
|
+
sessionSchema.index({ createdAt: 1 }, { expireAfterSeconds: 86400 });
|
|
39
|
+
|
|
40
|
+
// Text index with field weights
|
|
41
|
+
postSchema.index({ title: 'text', body: 'text' }, { weights: { title: 3, body: 1 } });
|
|
42
|
+
|
|
43
|
+
// Sparse index for optional fields (only indexes docs where field exists)
|
|
44
|
+
profileSchema.index({ twitterHandle: 1 }, { sparse: true });
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
---
|
|
48
|
+
|
|
49
|
+
## Embedding vs Referencing — practical decision rules
|
|
50
|
+
- **Embed** when:
|
|
51
|
+
- One-to-few relationships (comments on a post <100).
|
|
52
|
+
- Data accessed together most of the time.
|
|
53
|
+
- Example: post with small list of tags, metadata.
|
|
54
|
+
- **Reference** when:
|
|
55
|
+
- One-to-many with large or growing lists (orders, logs).
|
|
56
|
+
- The child is large or independently updated.
|
|
57
|
+
- Many-to-many relationships.
|
|
58
|
+
- **Hybrid approach**:
|
|
59
|
+
- Denormalize frequently-read fields (e.g., username snapshot on comment) but keep authoritative source in referenced doc.
|
|
60
|
+
- **Quick rule**: model around access patterns, not perfectly normalized schema.
|
|
61
|
+
|
|
62
|
+
### Mongoose embedding example with validation
|
|
63
|
+
```javascript
|
|
64
|
+
postSchema.add({
|
|
65
|
+
comments: [{
|
|
66
|
+
userId: { type: Schema.Types.ObjectId, ref: 'User', required: true },
|
|
67
|
+
text: { type: String, maxlength: 500, required: true },
|
|
68
|
+
createdAt: { type: Date, default: Date.now }
|
|
69
|
+
}],
|
|
70
|
+
commentCount: {
|
|
71
|
+
type: Number,
|
|
72
|
+
validate: {
|
|
73
|
+
validator: v => v <= 100,
|
|
74
|
+
message: 'Max 100 embedded comments; use referencing for more'
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
---
|
|
81
|
+
|
|
82
|
+
## Data modeling patterns (common practical patterns)
|
|
83
|
+
- **Bucket pattern**: group many small time-series events into monthly/day buckets to avoid huge arrays.
|
|
84
|
+
```javascript
|
|
85
|
+
// Example: metrics bucketed by day
|
|
86
|
+
{
|
|
87
|
+
_id: deviceId,
|
|
88
|
+
bucketDate: ISODate("2026-03-08"),
|
|
89
|
+
readings: [ { ts: ..., value: ... }, ... ] // capped at ~1000 docs
|
|
90
|
+
}
|
|
91
|
+
```
|
|
92
|
+
- **Outlier pattern**: keep typical documents compact; move unusually large data to separate collection with reference.
|
|
93
|
+
- **Polymorphic / type-discriminator**: use a `type` field + sparse fields per type, index `type` + commonly-queried fields.
|
|
94
|
+
- **Time-series**: prefer MongoDB time-series collections (5.0+) or bucket pattern for high-frequency data.
|
|
95
|
+
|
|
96
|
+
---
|
|
97
|
+
|
|
98
|
+
## Aggregation pipeline optimization
|
|
99
|
+
- **$match early**: filter as soon as possible to reduce pipeline volume.
|
|
100
|
+
- **$project early**: drop unneeded fields prior to heavy stages like `$group`.
|
|
101
|
+
- **Use indexes before aggregation**: if possible, use `$match` on indexed fields so the engine can use indexes.
|
|
102
|
+
- **Avoid memory spikes**: `$group` can be memory heavy; add `$limit` / `$sort` with proper indexes.
|
|
103
|
+
- **Use `allowDiskUse:true`** for large jobs, but prefer pre-filtering.
|
|
104
|
+
- **Pipeline ordering cheat sheet**: `$match` → `$project` → `$lookup` (if needed) → `$group` → `$sort` → `$limit`.
|
|
105
|
+
|
|
106
|
+
```javascript
|
|
107
|
+
// Example: aggregation to compute per-customer revenue (optimized)
|
|
108
|
+
db.orders.aggregate([
|
|
109
|
+
{ $match: { status: "completed", createdAt: { $gte: ISODate("2026-01-01") } } }, // indexed filters first
|
|
110
|
+
{ $project: { customerId: 1, amount: 1, _id: 0 } }, // remove heavy/unneeded fields
|
|
111
|
+
{ $group: { _id: "$customerId", total: { $sum: "$amount" } } },
|
|
112
|
+
{ $sort: { total: -1 } },
|
|
113
|
+
{ $limit: 100 }
|
|
114
|
+
], { allowDiskUse: false });
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
---
|
|
118
|
+
|
|
119
|
+
## ❌ Common anti-patterns to avoid
|
|
120
|
+
- Storing unbounded arrays (e.g., activity logs) → use bucket pattern or separate collection
|
|
121
|
+
- Using `$where` or client-side evaluation → blocks indexing, slow, security risk
|
|
122
|
+
- Over-using `$lookup` in high-traffic aggregations → denormalize hot paths or pre-aggregate
|
|
123
|
+
- Creating indexes on low-cardinality fields alone (e.g., `gender: 1`) → rarely selective, wastes write capacity
|
|
124
|
+
- Ignoring document size limit (16MB) → monitor with `$objSize` or schema validation
|
|
125
|
+
|
|
126
|
+
---
|
|
127
|
+
|
|
128
|
+
## Transactions, consistency & sharding (practical notes)
|
|
129
|
+
- Use multi-document transactions only when necessary — they add latency (~2-3x) and complexity.
|
|
130
|
+
- Favor single-document atomic operations (atomic by design) when possible.
|
|
131
|
+
- For sharding:
|
|
132
|
+
- Choose shard key based on write and query patterns (avoid monotonically increasing keys like `createdAt` alone).
|
|
133
|
+
- Use hashed shard keys for even distribution if queries don't filter by range.
|
|
134
|
+
- Monitor chunk distribution and balancing via `sh.status()`.
|
|
135
|
+
- Test transactions/sharding in staging with representative data sizes.
|
|
136
|
+
|
|
137
|
+
---
|
|
138
|
+
|
|
139
|
+
## Production & security considerations
|
|
140
|
+
- Never expose MongoDB directly to the internet — use private networks, VPC peering, or Atlas private endpoints.
|
|
141
|
+
- Authentication & RBAC: enable SCRAM / x.509 and use least-privilege roles.
|
|
142
|
+
- Field-level encryption: consider for highly sensitive fields (PII, tokens) using MongoDB Client-Side Field Level Encryption (CSFLE).
|
|
143
|
+
- Secrets: store connection strings / credentials in environment variables or secret manager; do not embed in code.
|
|
144
|
+
- TLS: require TLS for all connections (`tls=true` in connection string).
|
|
145
|
+
- Backups & PITR: ensure regular backups; test restore procedures quarterly.
|
|
146
|
+
- Audit & logging: enable audit logs for sensitive operations where compliance requires.
|
|
147
|
+
|
|
148
|
+
---
|
|
149
|
+
|
|
150
|
+
## Monitoring & performance checks
|
|
151
|
+
- Use Profiler and `system.profile` to find slow queries:
|
|
152
|
+
`db.setProfilingLevel(1, { slowms: 100 })`
|
|
153
|
+
- Monitor `db.serverStatus()` metrics: `opcounters`, `asserts`, `connections`, `mem`, `metrics.document`.
|
|
154
|
+
- Regularly review index usage: `db.collection.aggregate([{ $indexStats: {} }])`.
|
|
155
|
+
- Plan index changes after schema or query changes — test with `explain('executionStats')`.
|
|
156
|
+
|
|
157
|
+
---
|
|
158
|
+
|
|
159
|
+
## Quick checklists (for PRs/Code Reviews)
|
|
160
|
+
- [ ] Queries have appropriate filters and projections (no `find({})` without limits)
|
|
161
|
+
- [ ] Critical fields are indexed (and compound indexes tested with real query patterns)
|
|
162
|
+
- [ ] Aggregations place `$match` and `$project` early in pipeline
|
|
163
|
+
- [ ] Large arrays or documents have outlier/bucket handling
|
|
164
|
+
- [ ] No hardcoded connection strings or secrets in code
|
|
165
|
+
- [ ] TLS and authentication are enforced in production config
|
|
166
|
+
- [ ] Schema validation rules added for critical collections (optional but recommended)
|
|
167
|
+
|
|
168
|
+
---
|
|
169
|
+
|
|
170
|
+
## Example prompts (helps semantic router match this file)
|
|
171
|
+
```
|
|
172
|
+
"mongodb aggregation pipeline optimization"
|
|
173
|
+
"optimize mongoose query performance"
|
|
174
|
+
"mongodb ttl index sessions"
|
|
175
|
+
"embedding vs referencing mongodb"
|
|
176
|
+
"mongo shard key best practices"
|
|
177
|
+
"mongodb compound index order best practices"
|
|
178
|
+
"how to avoid aggregation memory limit"
|
|
179
|
+
"mongoose populate vs embedding performance"
|
|
180
|
+
"mongodb field level encryption example"
|
|
181
|
+
"time-series collection vs bucket pattern"
|
|
182
|
+
```
|
package/package.json
CHANGED