Claude CodeでAPIコンポジションを設計する:BFF・複数サービス集約・データ変換

はじめに 「フロントエンドが複数のマイクロサービスを直接叩いていてAPIコールが多い」——BFF(Backend for Frontend)でAPIコンポジションレイヤーを設け、複数サービスのデータを1つのAPIレスポンスに集約する設計をClaude Codeに生成させる。 CLAUDE.mdにAPIコンポジション設計ルールを書く ## APIコンポジション設計ルール ### コンポジション...

By · · 1 min read
Claude CodeでAPIコンポジションを設計する:BFF・複数サービス集約・データ変換

Source: DEV Community

はじめに 「フロントエンドが複数のマイクロサービスを直接叩いていてAPIコールが多い」——BFF(Backend for Frontend)でAPIコンポジションレイヤーを設け、複数サービスのデータを1つのAPIレスポンスに集約する設計をClaude Codeに生成させる。 CLAUDE.mdにAPIコンポジション設計ルールを書く ## APIコンポジション設計ルール ### コンポジション原則 - BFFが複数のダウンストリームサービスを並列で呼び出す - フロントエンドに必要なデータだけを返す(過剰データを除去) - エラーはサービス単位で分離(1サービス失敗でもレスポンスを返す) ### パフォーマンス - 独立したサービス呼び出しは常に並列実行(Promise.all) - 依存関係がある場合のみ逐次(例: userId取得後にそのユーザーの注文取得) - 結果をBFFレベルでキャッシュ(TTL: 30秒) ### データ変換 - ダウンストリームのレスポンスをBFFで変換(フロントの型に合わせる) - camelCase変換、フィールド名の統一、不要フィールドの除去 APIコンポジション実装の生成 BFF APIコンポジションを設計してください。 要件: - 複数サービスの並列呼び出し - 部分的な失敗の処理 - レスポンスデータ変換 - BFFキャッシュ 生成ファイル: src/bff/composition/ 生成されるAPIコンポジション実装 // src/bff/composition/composer.ts — APIコンポジションエンジン export interface DataSource<T> { name: string; fetch: () => Promise<T>; optional?: boolean; // true: 失敗してもレスポンスに含めない(エラーにしない) cacheTtlSec?: number; // BFFレベルキャッシュのTTL fallback?: () => T; // フォールバック値 } export type ComposedResult<T extends Record<string, DataSource<unknown>>&g

Related Posts

Similar Topics

#ai (18)#feat (17)#fix (17)#webdev (14)#javascript (13)#chore (9)#opensource (8)#large language models (4)#modernization (6)#css (6)#backbonejs (6)#es6 (6)#redis (2)#security (5)#nextjs (5)#programming (5)#code generation (4)#api (4)#node (4)#html (4)

Trending on ShareHub

  1. Understanding Modern JavaScript Frameworks in 2026
    by Alex Chen · Feb 12, 2026 · 0 likes
  2. The System Design Primer
    by Sarah Kim · Feb 12, 2026 · 0 likes
  3. Just shipped my first open-source project!
    by Alex Chen · Feb 12, 2026 · 0 likes
  4. OpenAI Blog
    by Sarah Kim · Feb 12, 2026 · 0 likes
  5. Building Accessible Web Applications: A Practical Guide
    by Alex Chen · Feb 12, 2026 · 0 likes
  6. Rapper Lil Poppa dead at 25, days after releasing new music
    Rapper Lil Poppa dead at 25, days after releasing new music
    by Anonymous User · Feb 19, 2026 · 0 likes
  7. write-for-us
    by Volt Raven · Mar 7, 2026 · 0 likes
  8. Before the Coffee Gets Cold: Heartfelt Story of Time Travel and Second Chances
    Before the Coffee Gets Cold: Heartfelt Story of Time Travel and Second Chances
    by Anonymous User · Feb 12, 2026 · 0 likes
    #coffee gets cold #the #time travel
  9. Best DoorDash Promo Code Reddit Finds for Top Discounts
    Best DoorDash Promo Code Reddit Finds for Top Discounts
    by Anonymous User · Feb 12, 2026 · 0 likes
    #doordash #promo #reddit
  10. Premium SEO Services That Boost Rankings & Revenue | VirtualSEO.Expert
    by Anonymous User · Feb 12, 2026 · 0 likes
  11. NBC under fire for commentary about Team USA women's hockey team
    NBC under fire for commentary about Team USA women's hockey team
    by Anonymous User · Feb 18, 2026 · 0 likes
  12. Where to Watch The Nanny: Streaming and Online Viewing Options
    Where to Watch The Nanny: Streaming and Online Viewing Options
    by Anonymous User · Feb 12, 2026 · 0 likes
    #streaming #the nanny #where
  13. How Much Is Kindle Unlimited? Subscription Cost and Plan Details
    How Much Is Kindle Unlimited? Subscription Cost and Plan Details
    by Anonymous User · Feb 12, 2026 · 0 likes
    #kindle unlimited #subscription #unlimited
  14. Russian skater facing backlash for comment about Amber Glenn
    Russian skater facing backlash for comment about Amber Glenn
    by Anonymous User · Feb 18, 2026 · 0 likes
  15. Google News
    Google News
    by Anonymous User · Feb 18, 2026 · 0 likes

Latest on ShareHub

Browse Topics

#artificial intelligence (31559)#data science (24017)#ai (16795)#generative ai (15034)#crypto (14995)#machine learning (14680)#bitcoin (14234)#featured (13554)#news & insights (13064)#crypto news (11083)

Around the Network