@h1dr0n/skill-pool 0.1.0
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/LICENSE +21 -0
- package/README.md +296 -0
- package/bin/cli.js +157 -0
- package/package.json +41 -0
- package/skills/api/agents/backend-specialist.md +69 -0
- package/skills/api/agents/database-optimizer.md +176 -0
- package/skills/api/manifest.yaml +20 -0
- package/skills/api/rules/auth-security.md +45 -0
- package/skills/api/skills/api-patterns/SKILL.md +81 -0
- package/skills/api/skills/api-patterns/api-style.md +42 -0
- package/skills/api/skills/api-patterns/auth.md +24 -0
- package/skills/api/skills/api-patterns/documentation.md +26 -0
- package/skills/api/skills/api-patterns/graphql.md +41 -0
- package/skills/api/skills/api-patterns/rate-limiting.md +31 -0
- package/skills/api/skills/api-patterns/response.md +37 -0
- package/skills/api/skills/api-patterns/rest.md +40 -0
- package/skills/api/skills/api-patterns/scripts/api_validator.py +211 -0
- package/skills/api/skills/api-patterns/security-testing.md +122 -0
- package/skills/api/skills/api-patterns/trpc.md +41 -0
- package/skills/api/skills/api-patterns/versioning.md +22 -0
- package/skills/api/skills/database-patterns.md +126 -0
- package/skills/api/skills/deployment-patterns.md +105 -0
- package/skills/api/skills/docker-patterns.md +135 -0
- package/skills/common/agents/code-reviewer.md +78 -0
- package/skills/common/agents/planner.md +80 -0
- package/skills/common/agents/security-reviewer.md +82 -0
- package/skills/common/agents/software-architect.md +81 -0
- package/skills/common/manifest.yaml +25 -0
- package/skills/common/rules/coding-style.md +39 -0
- package/skills/common/rules/git-workflow.md +33 -0
- package/skills/common/rules/security.md +25 -0
- package/skills/common/skills/architecture/SKILL.md +55 -0
- package/skills/common/skills/architecture/context-discovery.md +43 -0
- package/skills/common/skills/architecture/examples.md +94 -0
- package/skills/common/skills/architecture/pattern-selection.md +68 -0
- package/skills/common/skills/architecture/patterns-reference.md +50 -0
- package/skills/common/skills/architecture/trade-off-analysis.md +77 -0
- package/skills/common/skills/brainstorming/SKILL.md +163 -0
- package/skills/common/skills/brainstorming/dynamic-questioning.md +350 -0
- package/skills/common/skills/clean-code.md +99 -0
- package/skills/common/skills/code-review-checklist.md +86 -0
- package/skills/common/skills/plan-writing/SKILL.md +152 -0
- package/skills/common/skills/skill-feedback.md +94 -0
- package/skills/common/skills/tdd-workflow.md +130 -0
- package/skills/common/skills/verification-loop.md +112 -0
- package/skills/cpp/agents/cpp-build-resolver.md +90 -0
- package/skills/cpp/agents/cpp-reviewer.md +72 -0
- package/skills/cpp/manifest.yaml +15 -0
- package/skills/cpp/skills/cpp-coding-standards.md +722 -0
- package/skills/cpp/skills/cpp-testing.md +323 -0
- package/skills/devops/agents/devops-automator.md +376 -0
- package/skills/devops/agents/sre.md +90 -0
- package/skills/devops/manifest.yaml +20 -0
- package/skills/devops/skills/deployment-patterns.md +427 -0
- package/skills/devops/skills/deployment-procedures/SKILL.md +241 -0
- package/skills/devops/skills/docker-patterns.md +364 -0
- package/skills/devops/skills/e2e-testing.md +326 -0
- package/skills/devops/skills/github-ops.md +144 -0
- package/skills/django/manifest.yaml +16 -0
- package/skills/django/skills/django-patterns.md +734 -0
- package/skills/django/skills/django-security.md +593 -0
- package/skills/django/skills/django-tdd.md +729 -0
- package/skills/django/skills/django-verification.md +469 -0
- package/skills/dotnet/agents/csharp-reviewer.md +101 -0
- package/skills/dotnet/manifest.yaml +14 -0
- package/skills/dotnet/skills/csharp-testing.md +321 -0
- package/skills/dotnet/skills/dotnet-patterns.md +321 -0
- package/skills/go/agents/code-reviewer.md +76 -0
- package/skills/go/agents/go-build-resolver.md +94 -0
- package/skills/go/agents/go-reviewer.md +76 -0
- package/skills/go/manifest.yaml +17 -0
- package/skills/go/rules/go-style.md +55 -0
- package/skills/go/skills/golang-patterns.md +674 -0
- package/skills/go/skills/golang-testing.md +720 -0
- package/skills/java/agents/java-build-resolver.md +153 -0
- package/skills/java/agents/java-reviewer.md +92 -0
- package/skills/java/manifest.yaml +18 -0
- package/skills/java/skills/java-coding-standards.md +147 -0
- package/skills/java/skills/jpa-patterns.md +151 -0
- package/skills/java/skills/springboot-patterns.md +314 -0
- package/skills/java/skills/springboot-security.md +272 -0
- package/skills/kotlin/agents/kotlin-build-resolver.md +118 -0
- package/skills/kotlin/agents/kotlin-reviewer.md +159 -0
- package/skills/kotlin/manifest.yaml +17 -0
- package/skills/kotlin/skills/kotlin-coroutines-flows.md +284 -0
- package/skills/kotlin/skills/kotlin-patterns.md +711 -0
- package/skills/kotlin/skills/kotlin-testing.md +824 -0
- package/skills/laravel/manifest.yaml +15 -0
- package/skills/laravel/skills/laravel-patterns.md +409 -0
- package/skills/laravel/skills/laravel-security.md +279 -0
- package/skills/laravel/skills/laravel-tdd.md +277 -0
- package/skills/laravel/skills/laravel-verification.md +173 -0
- package/skills/mobile/agents/dart-build-resolver.md +201 -0
- package/skills/mobile/agents/flutter-reviewer.md +243 -0
- package/skills/mobile/manifest.yaml +19 -0
- package/skills/mobile/skills/android-clean-architecture.md +339 -0
- package/skills/mobile/skills/dart-flutter-patterns.md +563 -0
- package/skills/mobile/skills/swiftui-patterns.md +259 -0
- package/skills/nestjs/manifest.yaml +13 -0
- package/skills/nestjs/skills/nestjs-patterns.md +230 -0
- package/skills/perl/manifest.yaml +13 -0
- package/skills/perl/skills/perl-patterns.md +504 -0
- package/skills/perl/skills/perl-security.md +503 -0
- package/skills/perl/skills/perl-testing.md +475 -0
- package/skills/python/agents/python-reviewer.md +98 -0
- package/skills/python/manifest.yaml +18 -0
- package/skills/python/rules/python-style.md +69 -0
- package/skills/python/skills/python-patterns/SKILL.md +441 -0
- package/skills/python/skills/python-patterns.md +90 -0
- package/skills/python/skills/python-testing.md +81 -0
- package/skills/rust/agents/rust-build-resolver.md +148 -0
- package/skills/rust/agents/rust-reviewer.md +94 -0
- package/skills/rust/manifest.yaml +16 -0
- package/skills/rust/rules/rust-style.md +107 -0
- package/skills/rust/skills/rust-patterns.md +499 -0
- package/skills/rust/skills/rust-testing.md +500 -0
- package/skills/security/agents/accessibility-auditor.md +316 -0
- package/skills/security/agents/security-reviewer.md +108 -0
- package/skills/security/manifest.yaml +19 -0
- package/skills/security/skills/red-team-tactics/SKILL.md +199 -0
- package/skills/security/skills/security-bounty-hunter.md +99 -0
- package/skills/security/skills/security-review.md +495 -0
- package/skills/security/skills/security-scan.md +165 -0
- package/skills/security/skills/vulnerability-scanner/SKILL.md +276 -0
- package/skills/security/skills/vulnerability-scanner/checklists.md +121 -0
- package/skills/security/skills/vulnerability-scanner/scripts/security_scan.py +458 -0
- package/skills/swift/manifest.yaml +16 -0
- package/skills/swift/skills/swift-actor-persistence.md +142 -0
- package/skills/swift/skills/swift-concurrency.md +216 -0
- package/skills/swift/skills/swift-protocol-di-testing.md +190 -0
- package/skills/swift/skills/swiftui-patterns.md +259 -0
- package/skills/unity/agents/game-designer.md +167 -0
- package/skills/unity/agents/unity-architect.md +52 -0
- package/skills/unity/agents/unity-editor-tool-developer.md +310 -0
- package/skills/unity/agents/unity-multiplayer-engineer.md +321 -0
- package/skills/unity/agents/unity-shader-graph-artist.md +269 -0
- package/skills/unity/manifest.yaml +21 -0
- package/skills/unity/rules/csharp-patterns.md +48 -0
- package/skills/unity/rules/unity-specific.md +53 -0
- package/skills/unity/skills/systematic-debugging.md +92 -0
- package/skills/unity/skills/unity-architecture.md +173 -0
- package/skills/unreal/agents/level-designer.md +208 -0
- package/skills/unreal/agents/technical-artist.md +229 -0
- package/skills/unreal/agents/unreal-multiplayer-architect.md +313 -0
- package/skills/unreal/agents/unreal-systems-engineer.md +310 -0
- package/skills/unreal/agents/unreal-technical-artist.md +256 -0
- package/skills/unreal/agents/unreal-world-builder.md +273 -0
- package/skills/unreal/manifest.yaml +21 -0
- package/skills/unreal/skills/unreal-patterns.md +183 -0
- package/skills/web/agents/frontend-specialist.md +71 -0
- package/skills/web/agents/ui-designer.md +383 -0
- package/skills/web/agents/ux-architect.md +469 -0
- package/skills/web/manifest.yaml +22 -0
- package/skills/web/rules/accessibility.md +54 -0
- package/skills/web/rules/css-performance.md +52 -0
- package/skills/web/skills/e2e-testing.md +132 -0
- package/skills/web/skills/frontend-design/SKILL.md +452 -0
- package/skills/web/skills/frontend-design/animation-guide.md +331 -0
- package/skills/web/skills/frontend-design/color-system.md +311 -0
- package/skills/web/skills/frontend-design/decision-trees.md +418 -0
- package/skills/web/skills/frontend-design/motion-graphics.md +306 -0
- package/skills/web/skills/frontend-design/scripts/accessibility_checker.py +183 -0
- package/skills/web/skills/frontend-design/scripts/ux_audit.py +722 -0
- package/skills/web/skills/frontend-design/typography-system.md +345 -0
- package/skills/web/skills/frontend-design/ux-psychology.md +1116 -0
- package/skills/web/skills/frontend-design/visual-effects.md +383 -0
- package/skills/web/skills/react-nextjs.md +135 -0
- package/skills/web/skills/tailwind-patterns/SKILL.md +269 -0
- package/src/adapters/antigravity.js +164 -0
- package/src/adapters/claude.js +188 -0
- package/src/adapters/cursor.js +161 -0
- package/src/adapters/index.js +67 -0
- package/src/adapters/windsurf.js +158 -0
- package/src/commands/add.js +266 -0
- package/src/commands/create.js +127 -0
- package/src/commands/diff.js +78 -0
- package/src/commands/info.js +88 -0
- package/src/commands/init.js +224 -0
- package/src/commands/install.js +90 -0
- package/src/commands/list.js +54 -0
- package/src/commands/remove.js +101 -0
- package/src/commands/targets.js +32 -0
- package/src/commands/update.js +57 -0
- package/src/core/manifest.js +57 -0
- package/src/core/plugins.js +86 -0
- package/src/core/resolver.js +84 -0
- package/src/core/tracker.js +49 -0
- package/src/utils/fs.js +80 -0
- package/src/utils/git.js +52 -0
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: Database Optimizer
|
|
3
|
+
description: Expert database specialist focusing on schema design, query optimization, indexing strategies, and performance tuning for PostgreSQL, MySQL, and modern databases like Supabase and PlanetScale.
|
|
4
|
+
color: amber
|
|
5
|
+
emoji: 🗄️
|
|
6
|
+
vibe: Indexes, query plans, and schema design — databases that don't wake you at 3am.
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
# 🗄️ Database Optimizer
|
|
10
|
+
|
|
11
|
+
## Identity & Memory
|
|
12
|
+
|
|
13
|
+
You are a database performance expert who thinks in query plans, indexes, and connection pools. You design schemas that scale, write queries that fly, and debug slow queries with EXPLAIN ANALYZE. PostgreSQL is your primary domain, but you're fluent in MySQL, Supabase, and PlanetScale patterns too.
|
|
14
|
+
|
|
15
|
+
**Core Expertise:**
|
|
16
|
+
- PostgreSQL optimization and advanced features
|
|
17
|
+
- EXPLAIN ANALYZE and query plan interpretation
|
|
18
|
+
- Indexing strategies (B-tree, GiST, GIN, partial indexes)
|
|
19
|
+
- Schema design (normalization vs denormalization)
|
|
20
|
+
- N+1 query detection and resolution
|
|
21
|
+
- Connection pooling (PgBouncer, Supabase pooler)
|
|
22
|
+
- Migration strategies and zero-downtime deployments
|
|
23
|
+
- Supabase/PlanetScale specific patterns
|
|
24
|
+
|
|
25
|
+
## Core Mission
|
|
26
|
+
|
|
27
|
+
Build database architectures that perform well under load, scale gracefully, and never surprise you at 3am. Every query has a plan, every foreign key has an index, every migration is reversible, and every slow query gets optimized.
|
|
28
|
+
|
|
29
|
+
**Primary Deliverables:**
|
|
30
|
+
|
|
31
|
+
1. **Optimized Schema Design**
|
|
32
|
+
```sql
|
|
33
|
+
-- Good: Indexed foreign keys, appropriate constraints
|
|
34
|
+
CREATE TABLE users (
|
|
35
|
+
id BIGSERIAL PRIMARY KEY,
|
|
36
|
+
email VARCHAR(255) UNIQUE NOT NULL,
|
|
37
|
+
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
|
|
38
|
+
);
|
|
39
|
+
|
|
40
|
+
CREATE INDEX idx_users_created_at ON users(created_at DESC);
|
|
41
|
+
|
|
42
|
+
CREATE TABLE posts (
|
|
43
|
+
id BIGSERIAL PRIMARY KEY,
|
|
44
|
+
user_id BIGINT NOT NULL REFERENCES users(id) ON DELETE CASCADE,
|
|
45
|
+
title VARCHAR(500) NOT NULL,
|
|
46
|
+
content TEXT,
|
|
47
|
+
status VARCHAR(20) NOT NULL DEFAULT 'draft',
|
|
48
|
+
published_at TIMESTAMPTZ,
|
|
49
|
+
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
|
|
50
|
+
);
|
|
51
|
+
|
|
52
|
+
-- Index foreign key for joins
|
|
53
|
+
CREATE INDEX idx_posts_user_id ON posts(user_id);
|
|
54
|
+
|
|
55
|
+
-- Partial index for common query pattern
|
|
56
|
+
CREATE INDEX idx_posts_published
|
|
57
|
+
ON posts(published_at DESC)
|
|
58
|
+
WHERE status = 'published';
|
|
59
|
+
|
|
60
|
+
-- Composite index for filtering + sorting
|
|
61
|
+
CREATE INDEX idx_posts_status_created
|
|
62
|
+
ON posts(status, created_at DESC);
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
2. **Query Optimization with EXPLAIN**
|
|
66
|
+
```sql
|
|
67
|
+
-- ❌ Bad: N+1 query pattern
|
|
68
|
+
SELECT * FROM posts WHERE user_id = 123;
|
|
69
|
+
-- Then for each post:
|
|
70
|
+
SELECT * FROM comments WHERE post_id = ?;
|
|
71
|
+
|
|
72
|
+
-- ✅ Good: Single query with JOIN
|
|
73
|
+
EXPLAIN ANALYZE
|
|
74
|
+
SELECT
|
|
75
|
+
p.id, p.title, p.content,
|
|
76
|
+
json_agg(json_build_object(
|
|
77
|
+
'id', c.id,
|
|
78
|
+
'content', c.content,
|
|
79
|
+
'author', c.author
|
|
80
|
+
)) as comments
|
|
81
|
+
FROM posts p
|
|
82
|
+
LEFT JOIN comments c ON c.post_id = p.id
|
|
83
|
+
WHERE p.user_id = 123
|
|
84
|
+
GROUP BY p.id;
|
|
85
|
+
|
|
86
|
+
-- Check the query plan:
|
|
87
|
+
-- Look for: Seq Scan (bad), Index Scan (good), Bitmap Heap Scan (okay)
|
|
88
|
+
-- Check: actual time vs planned time, rows vs estimated rows
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
3. **Preventing N+1 Queries**
|
|
92
|
+
```typescript
|
|
93
|
+
// ❌ Bad: N+1 in application code
|
|
94
|
+
const users = await db.query("SELECT * FROM users LIMIT 10");
|
|
95
|
+
for (const user of users) {
|
|
96
|
+
user.posts = await db.query(
|
|
97
|
+
"SELECT * FROM posts WHERE user_id = $1",
|
|
98
|
+
[user.id]
|
|
99
|
+
);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
// ✅ Good: Single query with aggregation
|
|
103
|
+
const usersWithPosts = await db.query(`
|
|
104
|
+
SELECT
|
|
105
|
+
u.id, u.email, u.name,
|
|
106
|
+
COALESCE(
|
|
107
|
+
json_agg(
|
|
108
|
+
json_build_object('id', p.id, 'title', p.title)
|
|
109
|
+
) FILTER (WHERE p.id IS NOT NULL),
|
|
110
|
+
'[]'
|
|
111
|
+
) as posts
|
|
112
|
+
FROM users u
|
|
113
|
+
LEFT JOIN posts p ON p.user_id = u.id
|
|
114
|
+
GROUP BY u.id
|
|
115
|
+
LIMIT 10
|
|
116
|
+
`);
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
4. **Safe Migrations**
|
|
120
|
+
```sql
|
|
121
|
+
-- ✅ Good: Reversible migration with no locks
|
|
122
|
+
BEGIN;
|
|
123
|
+
|
|
124
|
+
-- Add column with default (PostgreSQL 11+ doesn't rewrite table)
|
|
125
|
+
ALTER TABLE posts
|
|
126
|
+
ADD COLUMN view_count INTEGER NOT NULL DEFAULT 0;
|
|
127
|
+
|
|
128
|
+
-- Add index concurrently (doesn't lock table)
|
|
129
|
+
COMMIT;
|
|
130
|
+
CREATE INDEX CONCURRENTLY idx_posts_view_count
|
|
131
|
+
ON posts(view_count DESC);
|
|
132
|
+
|
|
133
|
+
-- ❌ Bad: Locks table during migration
|
|
134
|
+
ALTER TABLE posts ADD COLUMN view_count INTEGER;
|
|
135
|
+
CREATE INDEX idx_posts_view_count ON posts(view_count);
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
5. **Connection Pooling**
|
|
139
|
+
```typescript
|
|
140
|
+
// Supabase with connection pooling
|
|
141
|
+
import { createClient } from '@supabase/supabase-js';
|
|
142
|
+
|
|
143
|
+
const supabase = createClient(
|
|
144
|
+
process.env.SUPABASE_URL!,
|
|
145
|
+
process.env.SUPABASE_ANON_KEY!,
|
|
146
|
+
{
|
|
147
|
+
db: {
|
|
148
|
+
schema: 'public',
|
|
149
|
+
},
|
|
150
|
+
auth: {
|
|
151
|
+
persistSession: false, // Server-side
|
|
152
|
+
},
|
|
153
|
+
}
|
|
154
|
+
);
|
|
155
|
+
|
|
156
|
+
// Use transaction pooler for serverless
|
|
157
|
+
const pooledUrl = process.env.DATABASE_URL?.replace(
|
|
158
|
+
'5432',
|
|
159
|
+
'6543' // Transaction mode port
|
|
160
|
+
);
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
## Critical Rules
|
|
164
|
+
|
|
165
|
+
1. **Always Check Query Plans**: Run EXPLAIN ANALYZE before deploying queries
|
|
166
|
+
2. **Index Foreign Keys**: Every foreign key needs an index for joins
|
|
167
|
+
3. **Avoid SELECT ***: Fetch only columns you need
|
|
168
|
+
4. **Use Connection Pooling**: Never open connections per request
|
|
169
|
+
5. **Migrations Must Be Reversible**: Always write DOWN migrations
|
|
170
|
+
6. **Never Lock Tables in Production**: Use CONCURRENTLY for indexes
|
|
171
|
+
7. **Prevent N+1 Queries**: Use JOINs or batch loading
|
|
172
|
+
8. **Monitor Slow Queries**: Set up pg_stat_statements or Supabase logs
|
|
173
|
+
|
|
174
|
+
## Communication Style
|
|
175
|
+
|
|
176
|
+
Analytical and performance-focused. You show query plans, explain index strategies, and demonstrate the impact of optimizations with before/after metrics. You reference PostgreSQL documentation and discuss trade-offs between normalization and performance. You're passionate about database performance but pragmatic about premature optimization.
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
name: api
|
|
2
|
+
version: 0.3.0
|
|
3
|
+
description: Backend API development - REST design, auth, database, deployment, Docker, architecture
|
|
4
|
+
depends:
|
|
5
|
+
- common
|
|
6
|
+
tags:
|
|
7
|
+
- backend
|
|
8
|
+
- api
|
|
9
|
+
- nodejs
|
|
10
|
+
- rest
|
|
11
|
+
rules:
|
|
12
|
+
- rules/auth-security.md
|
|
13
|
+
skills:
|
|
14
|
+
- skills/database-patterns.md
|
|
15
|
+
- skills/deployment-patterns.md
|
|
16
|
+
- skills/docker-patterns.md
|
|
17
|
+
- skills/api-patterns
|
|
18
|
+
agents:
|
|
19
|
+
- agents/backend-specialist.md
|
|
20
|
+
- agents/database-optimizer.md
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
# Authentication & API Security
|
|
2
|
+
|
|
3
|
+
## Auth Strategy Selection
|
|
4
|
+
|
|
5
|
+
| Strategy | Use When |
|
|
6
|
+
|----------|----------|
|
|
7
|
+
| JWT | Stateless APIs, microservices |
|
|
8
|
+
| Session | Server-rendered apps, simple setups |
|
|
9
|
+
| API Keys | Service-to-service, public APIs |
|
|
10
|
+
| OAuth 2.0 | Third-party integrations |
|
|
11
|
+
| Passkeys | Modern user auth (WebAuthn) |
|
|
12
|
+
|
|
13
|
+
## JWT Best Practices
|
|
14
|
+
|
|
15
|
+
- Short expiry (15 min access, 7 day refresh)
|
|
16
|
+
- Store refresh token in HTTP-only secure cookie
|
|
17
|
+
- Never store JWT in localStorage
|
|
18
|
+
- Include only necessary claims (no sensitive data)
|
|
19
|
+
- Validate `iss`, `aud`, `exp` on every request
|
|
20
|
+
|
|
21
|
+
## Password Handling
|
|
22
|
+
|
|
23
|
+
- Hash with bcrypt (cost factor 12+) or Argon2
|
|
24
|
+
- Never store plaintext passwords
|
|
25
|
+
- Enforce minimum 8 characters
|
|
26
|
+
- Check against breached password lists (HIBP)
|
|
27
|
+
|
|
28
|
+
## API Security Checklist
|
|
29
|
+
|
|
30
|
+
- [ ] Input validation on all endpoints (Zod, Joi, class-validator)
|
|
31
|
+
- [ ] Parameterized queries (never string concatenation for SQL)
|
|
32
|
+
- [ ] Rate limiting on auth endpoints (stricter: 5 attempts/min)
|
|
33
|
+
- [ ] CORS configured for specific origins only
|
|
34
|
+
- [ ] HTTPS enforced (HSTS header)
|
|
35
|
+
- [ ] No sensitive data in error responses
|
|
36
|
+
- [ ] Audit logging for auth events
|
|
37
|
+
|
|
38
|
+
## Headers
|
|
39
|
+
|
|
40
|
+
```
|
|
41
|
+
Strict-Transport-Security: max-age=31536000; includeSubDomains
|
|
42
|
+
X-Content-Type-Options: nosniff
|
|
43
|
+
X-Frame-Options: DENY
|
|
44
|
+
Content-Security-Policy: default-src 'self'
|
|
45
|
+
```
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: api-patterns
|
|
3
|
+
description: API design principles and decision-making. REST vs GraphQL vs tRPC selection, response formats, versioning, pagination.
|
|
4
|
+
allowed-tools: Read, Write, Edit, Glob, Grep
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
# API Patterns
|
|
8
|
+
|
|
9
|
+
> API design principles and decision-making for 2025.
|
|
10
|
+
> **Learn to THINK, not copy fixed patterns.**
|
|
11
|
+
|
|
12
|
+
## 🎯 Selective Reading Rule
|
|
13
|
+
|
|
14
|
+
**Read ONLY files relevant to the request!** Check the content map, find what you need.
|
|
15
|
+
|
|
16
|
+
---
|
|
17
|
+
|
|
18
|
+
## 📑 Content Map
|
|
19
|
+
|
|
20
|
+
| File | Description | When to Read |
|
|
21
|
+
|------|-------------|--------------|
|
|
22
|
+
| `api-style.md` | REST vs GraphQL vs tRPC decision tree | Choosing API type |
|
|
23
|
+
| `rest.md` | Resource naming, HTTP methods, status codes | Designing REST API |
|
|
24
|
+
| `response.md` | Envelope pattern, error format, pagination | Response structure |
|
|
25
|
+
| `graphql.md` | Schema design, when to use, security | Considering GraphQL |
|
|
26
|
+
| `trpc.md` | TypeScript monorepo, type safety | TS fullstack projects |
|
|
27
|
+
| `versioning.md` | URI/Header/Query versioning | API evolution planning |
|
|
28
|
+
| `auth.md` | JWT, OAuth, Passkey, API Keys | Auth pattern selection |
|
|
29
|
+
| `rate-limiting.md` | Token bucket, sliding window | API protection |
|
|
30
|
+
| `documentation.md` | OpenAPI/Swagger best practices | Documentation |
|
|
31
|
+
| `security-testing.md` | OWASP API Top 10, auth/authz testing | Security audits |
|
|
32
|
+
|
|
33
|
+
---
|
|
34
|
+
|
|
35
|
+
## 🔗 Related Skills
|
|
36
|
+
|
|
37
|
+
| Need | Skill |
|
|
38
|
+
|------|-------|
|
|
39
|
+
| API implementation | `@[skills/backend-development]` |
|
|
40
|
+
| Data structure | `@[skills/database-design]` |
|
|
41
|
+
| Security details | `@[skills/security-hardening]` |
|
|
42
|
+
|
|
43
|
+
---
|
|
44
|
+
|
|
45
|
+
## ✅ Decision Checklist
|
|
46
|
+
|
|
47
|
+
Before designing an API:
|
|
48
|
+
|
|
49
|
+
- [ ] **Asked user about API consumers?**
|
|
50
|
+
- [ ] **Chosen API style for THIS context?** (REST/GraphQL/tRPC)
|
|
51
|
+
- [ ] **Defined consistent response format?**
|
|
52
|
+
- [ ] **Planned versioning strategy?**
|
|
53
|
+
- [ ] **Considered authentication needs?**
|
|
54
|
+
- [ ] **Planned rate limiting?**
|
|
55
|
+
- [ ] **Documentation approach defined?**
|
|
56
|
+
|
|
57
|
+
---
|
|
58
|
+
|
|
59
|
+
## ❌ Anti-Patterns
|
|
60
|
+
|
|
61
|
+
**DON'T:**
|
|
62
|
+
- Default to REST for everything
|
|
63
|
+
- Use verbs in REST endpoints (/getUsers)
|
|
64
|
+
- Return inconsistent response formats
|
|
65
|
+
- Expose internal errors to clients
|
|
66
|
+
- Skip rate limiting
|
|
67
|
+
|
|
68
|
+
**DO:**
|
|
69
|
+
- Choose API style based on context
|
|
70
|
+
- Ask about client requirements
|
|
71
|
+
- Document thoroughly
|
|
72
|
+
- Use appropriate status codes
|
|
73
|
+
|
|
74
|
+
---
|
|
75
|
+
|
|
76
|
+
## Script
|
|
77
|
+
|
|
78
|
+
| Script | Purpose | Command |
|
|
79
|
+
|--------|---------|---------|
|
|
80
|
+
| `scripts/api_validator.py` | API endpoint validation | `python scripts/api_validator.py <project_path>` |
|
|
81
|
+
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
# API Style Selection (2025)
|
|
2
|
+
|
|
3
|
+
> REST vs GraphQL vs tRPC - Hangi durumda hangisi?
|
|
4
|
+
|
|
5
|
+
## Decision Tree
|
|
6
|
+
|
|
7
|
+
```
|
|
8
|
+
Who are the API consumers?
|
|
9
|
+
│
|
|
10
|
+
├── Public API / Multiple platforms
|
|
11
|
+
│ └── REST + OpenAPI (widest compatibility)
|
|
12
|
+
│
|
|
13
|
+
├── Complex data needs / Multiple frontends
|
|
14
|
+
│ └── GraphQL (flexible queries)
|
|
15
|
+
│
|
|
16
|
+
├── TypeScript frontend + backend (monorepo)
|
|
17
|
+
│ └── tRPC (end-to-end type safety)
|
|
18
|
+
│
|
|
19
|
+
├── Real-time / Event-driven
|
|
20
|
+
│ └── WebSocket + AsyncAPI
|
|
21
|
+
│
|
|
22
|
+
└── Internal microservices
|
|
23
|
+
└── gRPC (performance) or REST (simplicity)
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## Comparison
|
|
27
|
+
|
|
28
|
+
| Factor | REST | GraphQL | tRPC |
|
|
29
|
+
|--------|------|---------|------|
|
|
30
|
+
| **Best for** | Public APIs | Complex apps | TS monorepos |
|
|
31
|
+
| **Learning curve** | Low | Medium | Low (if TS) |
|
|
32
|
+
| **Over/under fetching** | Common | Solved | Solved |
|
|
33
|
+
| **Type safety** | Manual (OpenAPI) | Schema-based | Automatic |
|
|
34
|
+
| **Caching** | HTTP native | Complex | Client-based |
|
|
35
|
+
|
|
36
|
+
## Selection Questions
|
|
37
|
+
|
|
38
|
+
1. Who are the API consumers?
|
|
39
|
+
2. Is the frontend TypeScript?
|
|
40
|
+
3. How complex are the data relationships?
|
|
41
|
+
4. Is caching critical?
|
|
42
|
+
5. Public or internal API?
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# Authentication Patterns
|
|
2
|
+
|
|
3
|
+
> Choose auth pattern based on use case.
|
|
4
|
+
|
|
5
|
+
## Selection Guide
|
|
6
|
+
|
|
7
|
+
| Pattern | Best For |
|
|
8
|
+
|---------|----------|
|
|
9
|
+
| **JWT** | Stateless, microservices |
|
|
10
|
+
| **Session** | Traditional web, simple |
|
|
11
|
+
| **OAuth 2.0** | Third-party integration |
|
|
12
|
+
| **API Keys** | Server-to-server, public APIs |
|
|
13
|
+
| **Passkey** | Modern passwordless (2025+) |
|
|
14
|
+
|
|
15
|
+
## JWT Principles
|
|
16
|
+
|
|
17
|
+
```
|
|
18
|
+
Important:
|
|
19
|
+
├── Always verify signature
|
|
20
|
+
├── Check expiration
|
|
21
|
+
├── Include minimal claims
|
|
22
|
+
├── Use short expiry + refresh tokens
|
|
23
|
+
└── Never store sensitive data in JWT
|
|
24
|
+
```
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# API Documentation Principles
|
|
2
|
+
|
|
3
|
+
> Good docs = happy developers = API adoption.
|
|
4
|
+
|
|
5
|
+
## OpenAPI/Swagger Essentials
|
|
6
|
+
|
|
7
|
+
```
|
|
8
|
+
Include:
|
|
9
|
+
├── All endpoints with examples
|
|
10
|
+
├── Request/response schemas
|
|
11
|
+
├── Authentication requirements
|
|
12
|
+
├── Error response formats
|
|
13
|
+
└── Rate limiting info
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
## Good Documentation Has
|
|
17
|
+
|
|
18
|
+
```
|
|
19
|
+
Essentials:
|
|
20
|
+
├── Quick start / Getting started
|
|
21
|
+
├── Authentication guide
|
|
22
|
+
├── Complete API reference
|
|
23
|
+
├── Error handling guide
|
|
24
|
+
├── Code examples (multiple languages)
|
|
25
|
+
└── Changelog
|
|
26
|
+
```
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
# GraphQL Principles
|
|
2
|
+
|
|
3
|
+
> Flexible queries for complex, interconnected data.
|
|
4
|
+
|
|
5
|
+
## When to Use
|
|
6
|
+
|
|
7
|
+
```
|
|
8
|
+
✅ Good fit:
|
|
9
|
+
├── Complex, interconnected data
|
|
10
|
+
├── Multiple frontend platforms
|
|
11
|
+
├── Clients need flexible queries
|
|
12
|
+
├── Evolving data requirements
|
|
13
|
+
└── Reducing over-fetching matters
|
|
14
|
+
|
|
15
|
+
❌ Poor fit:
|
|
16
|
+
├── Simple CRUD operations
|
|
17
|
+
├── File upload heavy
|
|
18
|
+
├── HTTP caching important
|
|
19
|
+
└── Team unfamiliar with GraphQL
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## Schema Design Principles
|
|
23
|
+
|
|
24
|
+
```
|
|
25
|
+
Principles:
|
|
26
|
+
├── Think in graphs, not endpoints
|
|
27
|
+
├── Design for evolvability (no versions)
|
|
28
|
+
├── Use connections for pagination
|
|
29
|
+
├── Be specific with types (not generic "data")
|
|
30
|
+
└── Handle nullability thoughtfully
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## Security Considerations
|
|
34
|
+
|
|
35
|
+
```
|
|
36
|
+
Protect against:
|
|
37
|
+
├── Query depth attacks → Set max depth
|
|
38
|
+
├── Query complexity → Calculate cost
|
|
39
|
+
├── Batching abuse → Limit batch size
|
|
40
|
+
├── Introspection → Disable in production
|
|
41
|
+
```
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# Rate Limiting Principles
|
|
2
|
+
|
|
3
|
+
> Protect your API from abuse and overload.
|
|
4
|
+
|
|
5
|
+
## Why Rate Limit
|
|
6
|
+
|
|
7
|
+
```
|
|
8
|
+
Protect against:
|
|
9
|
+
├── Brute force attacks
|
|
10
|
+
├── Resource exhaustion
|
|
11
|
+
├── Cost overruns (if pay-per-use)
|
|
12
|
+
└── Unfair usage
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Strategy Selection
|
|
16
|
+
|
|
17
|
+
| Type | How | When |
|
|
18
|
+
|------|-----|------|
|
|
19
|
+
| **Token bucket** | Burst allowed, refills over time | Most APIs |
|
|
20
|
+
| **Sliding window** | Smooth distribution | Strict limits |
|
|
21
|
+
| **Fixed window** | Simple counters per window | Basic needs |
|
|
22
|
+
|
|
23
|
+
## Response Headers
|
|
24
|
+
|
|
25
|
+
```
|
|
26
|
+
Include in headers:
|
|
27
|
+
├── X-RateLimit-Limit (max requests)
|
|
28
|
+
├── X-RateLimit-Remaining (requests left)
|
|
29
|
+
├── X-RateLimit-Reset (when limit resets)
|
|
30
|
+
└── Return 429 when exceeded
|
|
31
|
+
```
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
# Response Format Principles
|
|
2
|
+
|
|
3
|
+
> Consistency is key - choose a format and stick to it.
|
|
4
|
+
|
|
5
|
+
## Common Patterns
|
|
6
|
+
|
|
7
|
+
```
|
|
8
|
+
Choose one:
|
|
9
|
+
├── Envelope pattern ({ success, data, error })
|
|
10
|
+
├── Direct data (just return the resource)
|
|
11
|
+
└── HAL/JSON:API (hypermedia)
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
## Error Response
|
|
15
|
+
|
|
16
|
+
```
|
|
17
|
+
Include:
|
|
18
|
+
├── Error code (for programmatic handling)
|
|
19
|
+
├── User message (for display)
|
|
20
|
+
├── Details (for debugging, field-level errors)
|
|
21
|
+
├── Request ID (for support)
|
|
22
|
+
└── NOT internal details (security!)
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## Pagination Types
|
|
26
|
+
|
|
27
|
+
| Type | Best For | Trade-offs |
|
|
28
|
+
|------|----------|------------|
|
|
29
|
+
| **Offset** | Simple, jumpable | Performance on large datasets |
|
|
30
|
+
| **Cursor** | Large datasets | Can't jump to page |
|
|
31
|
+
| **Keyset** | Performance critical | Requires sortable key |
|
|
32
|
+
|
|
33
|
+
### Selection Questions
|
|
34
|
+
|
|
35
|
+
1. How large is the dataset?
|
|
36
|
+
2. Do users need to jump to specific pages?
|
|
37
|
+
3. Is data frequently changing?
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
# REST Principles
|
|
2
|
+
|
|
3
|
+
> Resource-based API design - nouns not verbs.
|
|
4
|
+
|
|
5
|
+
## Resource Naming Rules
|
|
6
|
+
|
|
7
|
+
```
|
|
8
|
+
Principles:
|
|
9
|
+
├── Use NOUNS, not verbs (resources, not actions)
|
|
10
|
+
├── Use PLURAL forms (/users not /user)
|
|
11
|
+
├── Use lowercase with hyphens (/user-profiles)
|
|
12
|
+
├── Nest for relationships (/users/123/posts)
|
|
13
|
+
└── Keep shallow (max 3 levels deep)
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
## HTTP Method Selection
|
|
17
|
+
|
|
18
|
+
| Method | Purpose | Idempotent? | Body? |
|
|
19
|
+
|--------|---------|-------------|-------|
|
|
20
|
+
| **GET** | Read resource(s) | Yes | No |
|
|
21
|
+
| **POST** | Create new resource | No | Yes |
|
|
22
|
+
| **PUT** | Replace entire resource | Yes | Yes |
|
|
23
|
+
| **PATCH** | Partial update | No | Yes |
|
|
24
|
+
| **DELETE** | Remove resource | Yes | No |
|
|
25
|
+
|
|
26
|
+
## Status Code Selection
|
|
27
|
+
|
|
28
|
+
| Situation | Code | Why |
|
|
29
|
+
|-----------|------|-----|
|
|
30
|
+
| Success (read) | 200 | Standard success |
|
|
31
|
+
| Created | 201 | New resource created |
|
|
32
|
+
| No content | 204 | Success, nothing to return |
|
|
33
|
+
| Bad request | 400 | Malformed request |
|
|
34
|
+
| Unauthorized | 401 | Missing/invalid auth |
|
|
35
|
+
| Forbidden | 403 | Valid auth, no permission |
|
|
36
|
+
| Not found | 404 | Resource doesn't exist |
|
|
37
|
+
| Conflict | 409 | State conflict (duplicate) |
|
|
38
|
+
| Validation error | 422 | Valid syntax, invalid data |
|
|
39
|
+
| Rate limited | 429 | Too many requests |
|
|
40
|
+
| Server error | 500 | Our fault |
|