$npx -y skills add Aedelon/claude-code-blueprint --skill code-patternsReference patterns for REST APIs, pytest/vitest testing, Docker multi-stage builds, GitHub Actions CI/CD, PostgreSQL, TypeScript generics, Python async, and React Server Components. MUST BE USED when user asks about: "API design", "how to test", "Dockerfile", "CI/CD pipeline", "d
| 1 | # Code Patterns Reference |
| 2 | |
| 3 | This skill contains comprehensive patterns for modern development. Reference files are organized by topic. |
| 4 | |
| 5 | ## Quick Reference |
| 6 | |
| 7 | | Topic | Key Patterns | When to Use | |
| 8 | |-------|--------------|-------------| |
| 9 | | API Design | REST, GraphQL, OpenAPI | Designing/implementing APIs | |
| 10 | | Testing | pytest, vitest, mocking | Writing tests | |
| 11 | | Docker | Multi-stage, Compose | Containerizing apps | |
| 12 | | CI/CD | GitHub Actions, pipelines | Setting up automation | |
| 13 | | Database | PostgreSQL, migrations | Database design | |
| 14 | | TypeScript | Types, generics, patterns | TS development | |
| 15 | | Python | async, patterns, uv | Python development | |
| 16 | | React/Next.js | Server Components, hooks | Frontend development | |
| 17 | |
| 18 | ## Reference Files |
| 19 | |
| 20 | - `api.md` - REST, GraphQL, authentication, pagination |
| 21 | - `testing.md` - pytest, vitest, mocking, coverage |
| 22 | - `docker.md` - Dockerfiles, Compose, production |
| 23 | - `ci-cd.md` - GitHub Actions, deployment |
| 24 | - `database.md` - PostgreSQL, migrations, queries |
| 25 | - `typescript.md` - Types, generics, advanced patterns |
| 26 | - `python.md` - async, patterns, best practices |
| 27 | - `react.md` - Server Components, hooks, Next.js |
| 28 | |
| 29 | --- |
| 30 | |
| 31 | ## API Design Quick Reference |
| 32 | |
| 33 | ### REST Endpoints |
| 34 | ``` |
| 35 | GET /resources List |
| 36 | GET /resources/{id} Get one |
| 37 | POST /resources Create |
| 38 | PUT /resources/{id} Replace |
| 39 | PATCH /resources/{id} Update |
| 40 | DELETE /resources/{id} Delete |
| 41 | ``` |
| 42 | |
| 43 | ### HTTP Status Codes |
| 44 | | Code | Meaning | |
| 45 | |------|---------| |
| 46 | | 200 | OK | |
| 47 | | 201 | Created | |
| 48 | | 204 | No Content | |
| 49 | | 400 | Bad Request | |
| 50 | | 401 | Unauthorized | |
| 51 | | 403 | Forbidden | |
| 52 | | 404 | Not Found | |
| 53 | | 422 | Unprocessable | |
| 54 | | 429 | Rate Limited | |
| 55 | | 500 | Server Error | |
| 56 | |
| 57 | --- |
| 58 | |
| 59 | ## Testing Quick Reference |
| 60 | |
| 61 | ### pytest |
| 62 | ```python |
| 63 | @pytest.fixture |
| 64 | def client(): |
| 65 | return TestClient(app) |
| 66 | |
| 67 | def test_endpoint(client): |
| 68 | response = client.get("/api/users") |
| 69 | assert response.status_code == 200 |
| 70 | ``` |
| 71 | |
| 72 | ### vitest |
| 73 | ```typescript |
| 74 | import { describe, it, expect, vi } from 'vitest'; |
| 75 | |
| 76 | describe('Component', () => { |
| 77 | it('should work', () => { |
| 78 | expect(true).toBe(true); |
| 79 | }); |
| 80 | }); |
| 81 | ``` |
| 82 | |
| 83 | --- |
| 84 | |
| 85 | ## Docker Quick Reference |
| 86 | |
| 87 | ### Multi-Stage Build |
| 88 | ```dockerfile |
| 89 | FROM node:20-alpine AS builder |
| 90 | WORKDIR /app |
| 91 | COPY package*.json ./ |
| 92 | RUN npm ci |
| 93 | COPY . . |
| 94 | RUN npm run build |
| 95 | |
| 96 | FROM node:20-alpine |
| 97 | COPY --from=builder /app/dist ./dist |
| 98 | USER node |
| 99 | CMD ["node", "dist/index.js"] |
| 100 | ``` |
| 101 | |
| 102 | ### Compose |
| 103 | ```yaml |
| 104 | services: |
| 105 | app: |
| 106 | build: . |
| 107 | ports: |
| 108 | - "3000:3000" |
| 109 | depends_on: |
| 110 | db: |
| 111 | condition: service_healthy |
| 112 | db: |
| 113 | image: postgres:16-alpine |
| 114 | healthcheck: |
| 115 | test: ["CMD", "pg_isready"] |
| 116 | ``` |
| 117 | |
| 118 | --- |
| 119 | |
| 120 | ## CI/CD Quick Reference |
| 121 | |
| 122 | ### GitHub Actions |
| 123 | ```yaml |
| 124 | name: CI |
| 125 | on: [push, pull_request] |
| 126 | jobs: |
| 127 | test: |
| 128 | runs-on: ubuntu-latest |
| 129 | steps: |
| 130 | - uses: actions/checkout@v4 |
| 131 | - uses: actions/setup-node@v4 |
| 132 | - run: npm ci |
| 133 | - run: npm test |
| 134 | ``` |
| 135 | |
| 136 | --- |
| 137 | |
| 138 | ## TypeScript Quick Reference |
| 139 | |
| 140 | ### Utility Types |
| 141 | ```typescript |
| 142 | Partial<T> // All properties optional |
| 143 | Required<T> // All properties required |
| 144 | Pick<T, K> // Select properties |
| 145 | Omit<T, K> // Exclude properties |
| 146 | Record<K, V> // Object with key type K, value type V |
| 147 | ``` |
| 148 | |
| 149 | ### Generics |
| 150 | ```typescript |
| 151 | function first<T>(arr: T[]): T | undefined { |
| 152 | return arr[0]; |
| 153 | } |
| 154 | ``` |
| 155 | |
| 156 | --- |
| 157 | |
| 158 | ## Python Quick Reference |
| 159 | |
| 160 | ### Async |
| 161 | ```python |
| 162 | async def fetch_data(): |
| 163 | async with aiohttp.ClientSession() as session: |
| 164 | async with session.get(url) as response: |
| 165 | return await response.json() |
| 166 | ``` |
| 167 | |
| 168 | ### Type Hints |
| 169 | ```python |
| 170 | def process(items: list[str]) -> dict[str, int]: |
| 171 | return {item: len(item) for item in items} |
| 172 | ``` |
| 173 | |
| 174 | --- |
| 175 | |
| 176 | ## React/Next.js Quick Reference |
| 177 | |
| 178 | ### Server Component (default) |
| 179 | ```tsx |
| 180 | // app/page.tsx |
| 181 | async function Page() { |
| 182 | const data = await fetch('...'); |
| 183 | return <div>{data}</div>; |
| 184 | } |
| 185 | ``` |
| 186 | |
| 187 | ### Client Component |
| 188 | ```tsx |
| 189 | 'use client'; |
| 190 | import { useState } from 'react'; |
| 191 | |
| 192 | export function Counter() { |
| 193 | const [count, setCount] = useState(0); |
| 194 | return <button onClick={() => setCount(c => c + 1)}>{count}</button>; |
| 195 | } |
| 196 | ``` |