Backend go architecture
Go バックエンドの実装リファレンス。Package by Feature + Clean Architecture の実際のコード構成、ConnectRPC ハンドラー、sqlc による型安全 DB アクセス、OIDC 認証、DI パターン、ミドルウェア、エラーハンドリングを網羅。「バックエンド」「Go」「handler」「usecase」「domain」「infra」「sqlc」「ConnectRPC」「認証」「ミドルウェア」「DI」「main.go」「トランザクション」「repository」「store」で発動。From its SKILL.md
npx -y skills add UNILORN/claude-skills --skill backend-go-architectureAssembled from the repository path, not quoted from the project. Check it against their README if it does not work.
2 things to look at
- no licenseNo license file was found in the repository. Code published without one is not open source by default, so using it at work is a question for whoever answers licensing questions where you are.
- 0 stars0 stars. Stars are a popularity signal and not a quality one, but at this level it is likely that nobody has read this closely except its author, and you would be relying on your own review.
SKILL.md
5.3 KB, as published. Nobody here has run it
Backend Go Architecture Reference
現在のバックエンド Go ソースコードの実装パターンを完全に文書化したスキル。 新機能追加・バグ修正・リファクタリング時にこのスキルを参照すること。
Tech Stack
| カテゴリ | 技術 | バージョン |
|---|---|---|
| Language | Go | 1.24.3 |
| API Framework | ConnectRPC | v1.19.1 |
| Database Driver | pgx/v5 | v5.8.0 |
| SQL Codegen | sqlc | v2 |
| Schema Migration | Atlas | - |
| Proto Codegen | Buf | v2 |
| Auth | go-oidc/v3 + oauth2 | v3.17.0 |
| CORS | rs/cors + connectrpc/cors | v1.11.1 |
| UUID | google/uuid | v1.6.0 |
| Logging | log/slog (stdlib) | - |
| Linting | golangci-lint | 20+ linters |
| Container | Distroless (nonroot) | - |
Directory Structure (実際のコード)
packages/backend-go/
├── cmd/app/
│ └── main.go # エントリーポイント、DI、サーバー起動
├── db/
│ ├── schema.sql # DB スキーマ (Single Source of Truth)
│ └── migrations/ # Atlas 生成マイグレーション
├── gen/ # Proto 生成コード (gitignore)
│ └── {feature}/v1/
│ ├── {feature}.pb.go
│ └── {feature}v1connect/
│ └── {feature}.connect.go
├── internal/
│ ├── config/
│ │ └── config.go # 環境変数ベースの設定管理
│ ├── database/
│ │ └── tx.go # トランザクション Context ヘルパー
│ ├── domain/
│ │ └── user.go # 共有ドメインエンティティ
│ └── {feature}/ # Package by Feature
│ ├── domain/ # Repository IF, エラー定義
│ ├── usecase/ # ビジネスロジック
│ ├── handler/ # ConnectRPC / HTTP ハンドラー
│ ├── middleware/ # (auth のみ) HTTP ミドルウェア
│ └── infra/ # Repository 実装
│ ├── queries.sql # sqlc クエリ定義
│ ├── sqlcgen/ # sqlc 生成コード (gitignore)
│ ├── store.go # PostgreSQL 実装
│ └── memory_store.go # インメモリ実装 (dev/test)
├── proto/
│ └── {feature}/v1/
│ └── {feature}.proto # Proto サービス定義
├── Dockerfile # Multi-stage (Alpine → Distroless)
├── buf.yaml # Buf 設定
├── sqlc.yaml # sqlc 設定
├── atlas.hcl # Atlas 設定
├── .golangci.yml # Lint 設定
├── go.mod / go.sum
└── .env.example
Dependency Flow
handler → usecase → domain ← infra
↑
internal/domain (shared entities)
handlerはusecaseとgen/(Proto 生成コード) に依存usecaseはdomainのみに依存 (Proto 生成コードに依存しない)infraはdomainの Repository IF を実装し、sqlcgenとdatabaseに依存domainは外部に一切依存しない
Detailed References
実装の詳細は以下のリファレンスを参照:
- レイヤー別実装パターン (domain/usecase/handler/infra の具体的コード): references/layers.md
- DI とサーバー構成 (main.go、ミドルウェアチェーン、条件分岐 DI): references/di-and-server.md
- データベースパターン (sqlc, トランザクション, スキーマ, pgx 型変換): references/database.md
- 認証設計 (OIDC フロー, セッション管理, ミドルウェア, Cookie): references/authentication.md
- ツールチェーン (Buf, sqlc, Atlas, golangci-lint, Dockerfile): references/toolchain.md
Quick Reference: 新機能追加チェックリスト
proto/{feature}/v1/{feature}.protoを作成 →pnpm buf:generatedb/schema.sqlにテーブル追加 →pnpm atlas:diff→pnpm atlas:applyinternal/{feature}/domain/— Repository IF + エラー定義internal/{feature}/infra/queries.sql— sqlc クエリ →pnpm sqlc:generateinternal/{feature}/infra/store.go— PostgreSQL 実装internal/{feature}/infra/memory_store.go— インメモリ実装internal/{feature}/usecase/— ビジネスロジックinternal/{feature}/handler/— ConnectRPC ハンドラーcmd/app/main.go— DI 登録 + mux.Handlesqlc.yaml— 新しいクエリパスを追加