Skip to content
Skills Library
Programming · Building & coding

backend-patterns

/backend-patterns

API設計、Repository、サービス層、Resultパターン、キャッシュ、トランザクションのパターンガイド(フレームワーク非依存)。APIエンドポイント・ビジネスロジック・データアクセス層の実装/設計/レビュー時に使用する。対外契約(バージョニング・エラー体系)は dev-core:interface-contract-design、実行時信頼性の設計判断(リトライ・ロック・TTL)は dev-core:resilience-design が正本で、本スキルは実装コード例を担当する。

Repository
cc-plugins ↗
Licence
MIT
Last repository change
26.10.2026

Assessment and security

100/ 100Class: good
Format25 / 25
Frontmatter with name and description, valid name, description up to 1,024 characters, name matching the folder.
Discoverability25 / 25
Description explains when to use the skill, has a reasonable length and uses third person.
Content35 / 35
At least 150 words and at most 500 lines, headings, step lists, examples or code.
Hygiene15 / 15
No placeholders such as TODO, no Windows paths, with a licence.
Riskno signals detected in the scan
Files in this package
1
Scripts
0
HTML comments
0
URLs in SKILL.md
0
Deprecation

No signals detected. Repository changed on 26.10.2026, without references to retired models or APIs.

Licence

MIT, open: use and modify while retaining author attribution.

What it does and when to use it

API設計、Repository、サービス層、Resultパターン、キャッシュ、トランザクションのパターンガイド(フレームワーク非依存)。APIエンドポイント・ビジネスロジック・データアクセス層の実装/設計/レビュー時に使用する。対外契約(バージョニング・エラー体系)は dev-core:interface-contract-design、実行時信頼性の設計判断(リトライ・ロック・TTL)は dev-core:resilience-design が正本で、本スキルは実装コード例を担当する。

Original author description

API設計、Repository、サービス層、Resultパターン、キャッシュ、トランザクションのパターンガイド(フレームワーク非依存)。APIエンドポイント・ビジネスロジック・データアクセス層の実装/設計/レビュー時に使用する。対外契約(バージョニング・エラー体系)は dev-core:interface-contract-design、実行時信頼性の設計判断(リトライ・ロック・TTL)は dev-core:resilience-design が正本で、本スキルは実装コード例を担当する。

How it works

  1. API 設計
  2. Repository パターン
  3. サービス層(ユースケース)
  4. Result パターン
  5. キャッシュ戦略
  6. トランザクション
Original SKILL.md headings · 96 lines, 261 words
SKILL.md preview
---
name: backend-patterns
description: "API設計、Repository、サービス層、Resultパターン、キャッシュ、トランザクションのパターンガイド(フレームワーク非依存)。APIエンドポイント・ビジネスロジック・データアクセス層の実装/設計/レビュー時に使用する。対外契約(バージョニング・エラー体系)は dev-core:interface-contract-design、実行時信頼性の設計判断(リトライ・ロック・TTL)は dev-core:resilience-design が正本で、本スキルは実装コード例を担当する。"
---

# Backend Patterns

フレームワーク非依存のバックエンド設計パターン。ORM固有のAPI(Eloquent, Prisma等)は context7 MCP や .claude/*.local.md を参照してください。

実行時の信頼性の設計判断(例外3分類・リトライ・分離レベル/ロック選択・キャッシュTTL/無効化)は dev-core:resilience-design が正本。本スキルは実装コード例を担当する。

## API 設計

対外契約(バージョニング・後方互換・冪等性・イベント契約・RFC 9457 エラー体系)は dev-core:interface-contract-design が正本。本スキルは実装パターンを扱う。

### RESTful エンドポイント

```
GET    /api/users          # 一覧取得
GET    /api/users/:id      # 詳細取得
POST   /api/users          # 作成
PUT    /api/users/:id      # 更新
DELETE /api/users/:id      # 削除
```

### レスポンス形式

- 正常系: リソースを直接返し、適切な HTTP ステータスで結果を表現する(封筒でくるまない)。
- エラー: `application/problem+json`(RFC 9457 Problem Details)で返す。形式の正本は dev-core:interface-contract-design Step 7。
- `success` フラグ封筒型(全部 200 で返して `success: false`)は非推奨。HTTP セマンティクスを殺し、監視もリトライも壊れるため。

### HTTP ステータスコード

200: 成功 | 201: 作成 | 400: バリデーションエラー | 401: 認証 | 403: 認可 | 404: 未発見 | 500: サーバーエラー

## Repository パターン

```typescript
interface Repository<T, ID> {
  findById(id: ID): Promise<T | null>;
  findAll(): Promise<T[]>;
  save(entity: T): Promise<T>;
  delete(id: ID): Promise<void>;
}
```

具象実装はORM/フレームワークに依存(Eloquent, Prisma, TypeORM等)。インターフェースで抽象化し、依存性逆転を実現。

## サービス層(ユースケース)

```typescript
class CreateUserUseCase {
  constructor(
    private userRepository: UserRepository,
    private emailService: EmailService
  ) {}

  async execute(input: CreateUserInput): Promise<Result<User>> {
    const validated = CreateUserSchema.parse(input);
    const user = User.create(validated);
    const saved = await this.userRepository.save(user);
    await this.emailService.sendWelcome(saved.email);
    return ok(saved);
  }
}
```

## Result パターン

**言語に標準の Result 機構がある場合はそれを使い、以下の自前定義は不要**: Rust は `std::result::Result` + `thiserror`(Tauri コマンド境界では `Serialize` 可能なエラー型に変換)、Go は `(T, error)`。Python は例外文化が主流のため、業務例外は独自例外クラスか構造化戻り値で表現し、Result ライブラリのフル導入はチーム合意がある場合のみ(適用基準は dev-core:resilience-design Step 2)。以下は TS/JS のように言語標準がない場合の定義例:

```typescript
type Result<T, E = Error> =
  | { success: true; value: T }
  | { success: false; error: E };

function ok<T>(value: T): Result<T, never> {
  return { success: true, value };
}

function err<E>(error: E): Result<never, E> {
  return { success: false, error };
}
```

## キャッシュ戦略

### Cache-Aside パターン

1. キャッシュ確認 → 2. ヒットしなければDB取得 → 3. キャッシュに保存
- 更新時はキャッシュを無効化
- TTL を適切に設定(ユースケースに応じて)

## トランザクション

- 複数の書き込み操作は必ずトランザクションで囲む
- 原子性(ACID)の保証
- デッドロック防止(一貫したロック順序)
- 具体的なAPI はORM/フレームワークに依存(`DB::transaction()`, `prisma.$transaction()`等)

Versions

RepositoryScoreLicence
This page · tadokoro-ryusuke/cc-plugins100MIT
Sanit-mann/The-Insectoids100MIT
kensaurus/cursor-kenji100MIT
Selenophile2004/applied-agent-skills100MIT
tranhieutt/software_development_department100MIT
affaan-m/ECC95MIT
affaan-m/ECC95MIT
SHRIJANAGAIN/Nemo-Cli95Apache-2.0
andersonlimahw/lemon-ai-hub95MIT

Database snapshot: 13.11.2026 · package version 88f39eaeb850 (SHA-256 digest of the entire package)

Downloads in the last 30 days: 0 · ranking

Report a problem with this skill: harmful content, incorrect descriptions or an author’s removal request.

Similar skills

  • 90resilience-design
    トランザクション・例外・リトライ・キャッシュという実行時の信頼性設計スキル。同時実行、ロック、二重登録防止、エラーハンドリング方針、リトライ設計、Result型、キャッシュ導入、タイムアウト、サーキットブレーカーが話題になったら必ず使用する。実装コード例は dev-core:backend-patterns が正本で、本スキルは設計判断と選定フローを担当。
  • 100interface-contract-design
    API・イベント・エラーレスポンスなど機械間境界の契約設計スキル。API設計、OpenAPI、バージョニング、後方互換、ページネーション、冪等性、Webhook、イベント設計、Saga、Outbox、エラーコード体系、RFC 9457 が話題になったら必ず使用する。実装コードのパターンは dev-core:backend-patterns が正本で、本スキルは対外契約と互換性戦略を担当。
  • 90cache-design
    Design a caching strategy for an application — pattern selection, key design, TTL, and eviction policy. Use when asked to "add caching to this", "design a cache strategy", or "what should we cache".
  • 100backend
    Backend development patterns for services, error handling, logging, caching. Use when building backend services, APIs, or microservices.
  • 100api-and-interface-design
    Stable API and interface design patterns. Use when designing REST/GraphQL endpoints, module boundaries, type contracts between modules or frontend/backend, or changing public interfaces.
  • 95backend-testing
    Turn backend test ambiguity into one practical backend test packet. Use when the user needs API/service/repository/auth-flow coverage design, fixture or seed/reset strategy, container-vs-mock dependency choices, contract/API compatibility checks, or flaky backend-suite…

Feedback and reports

Your message goes to Bartosz Sokoliński. An email address is needed only for a reply. See the privacy policy.