ECサイト風のアイテム管理システムです(アイデアベースなのでmercariなどに比べると著しく性能などは下がります(笑))。Go(Gin)バックエンドとNext.jsフロントエンドで構成してます。
shopmarket/
├── backend/ # Go (Gin) API サーバー
└── frontend/ # Next.js アプリケーション
- Go 1.21+
- Gin - Webフレームワーク
- GORM - ORM
- PostgreSQL - データベース
- JWT - 認証
- Docker - コンテナ化
- Next.js 14 (App Router)
- TypeScript
- Tailwind CSS
- shadcn/ui - UIコンポーネント
- React Hook Form - フォーム管理
- Zod - バリデーション
- Axios - HTTP クライアント
- TanStack Query - 状態管理・キャッシュ
- ユーザー登録
- ログイン(JWT認証)
- 認証ミドルウェア
- アイテム一覧表示(全ユーザー)
- アイテム詳細表示(認証必要)
- アイテム作成(認証必要)
- アイテム更新(所有者のみ)
- アイテム削除(所有者のみ)
POST /auth/signup- ユーザー登録POST /auth/login- ログイン
GET /items- 全アイテム取得(認証不要)GET /items/:id- 特定アイテム取得(認証必要)POST /items- アイテム作成(認証必要)PUT /items/:id- アイテム更新(認証必要)DELETE /items/:id- アイテム削除(認証必要)
type User struct {
gorm.Model
Email string `gorm:"not null;unique"`
Password string `gorm:"not null"`
Items []Item `gorm:"constraint:OnDelete:CASCADE"`
}type Item struct {
gorm.Model
Name string `gorm:"not null"`
Price uint `gorm:"not null"`
Description string
SoldOut bool `gorm:"not null;default false"`
UserID uint `gorm:"not null"`
}##セットアップ
- Go 1.21+
- Docker & Docker Compose
- Node.js 18+ (フロントエンド用)
- pnpm (フロントエンド用)
- リポジトリクローン
git clone <repository-url>
cd shopmarket- 依存関係インストール
go mod download- データベース起動
docker-compose up -d db- 環境変数設定
cp .env.example .env
# .envファイルを編集してデータベース接続情報を設定- サーバー起動
go run main.goサーバーは http://localhost:8080 で起動します。
- フロントエンドディレクトリに移動
cd frontend- 依存関係インストール
pnpm install- 開発サーバー起動
pnpm devフロントエンドは http://localhost:3000 で起動します。(3001でも3002等でも大丈夫です)
go test ./...go test -v ./controllers##プロジェクト構造
shopmarket/
├── backend/
│ ├── controllers/
│ ├── services/
│ ├── repositories/
│ ├── models/
│ ├── dto/
│ ├── middlewares/
│ ├── infra/
│ ├── migrations/
│ └── main.go
├── frontend/
│ ├── src/
│ │ ├── app/
│ │ ├── components/
│ │ ├── lib/
│ │ ├── types/
│ │ └── hooks/
│ ├── package.json
│ └── next.config.js
└── docker-compose.yaml
##API使用例
curl -X POST http://localhost:8080/auth/signup \
-H "Content-Type: application/json" \
-d '{
"email": "user@example.com",
"password": "password123"
}'curl -X POST http://localhost:8080/auth/login \
-H "Content-Type: application/json" \
-d '{
"email": "user@example.com",
"password": "password123"
}'curl -X POST http://localhost:8080/items \
-H "Content-Type: application/json" \
-H "Authorization: Bearer <your-jwt-token>" \
-d '{
"name": "商品名",
"price": 1000,
"description": "商品説明"
}'