バックエンド開発パターン
スケーラブルなサーバーサイドアプリケーションのためのバックエンドアーキテクチャパターンとベストプラクティス。
API設計パターン
RESTful API構造
// PASS: リソースベースのURL
GET /api/markets # リソースのリスト
GET /api/markets/:id # 単一リソースの取得
POST /api/markets # リソースの作成
PUT /api/markets/:id # リソースの置換
PATCH /api/markets/:id # リソースの更新
DELETE /api/markets/:id # リソースの削除
// PASS: フィルタリング、ソート、ページネーション用のクエリパラメータ
GET /api/markets?status=active&sort=volume&limit=20&offset=0
リポジトリパターン
// データアクセスロジックの抽象化
interface MarketRepository {
findAll(filters?: MarketFilters): Promise<Market[]>
findById(id: string): Promise<Market | null>
create(data: CreateMarketDto): Promise<Market>
update(id: string, data: UpdateMarketDto): Promise<Market>
delete(id: string): Promise<void>
}
class SupabaseMarketRepository implements MarketRepository {
async findAll(filters?: MarketFilters): Promise<Market[]> {
let query = supabase.from('markets').select('*')
if (filters?.status) {
query = query.eq('status', filters.status)
}
if (filters?.limit) {
query = query.limit(filters.limit)
}
const { d…