diff --git a/frontend/CLAUDE.md b/frontend/CLAUDE.md index 50fd407..25c9fd6 100644 --- a/frontend/CLAUDE.md +++ b/frontend/CLAUDE.md @@ -446,8 +446,108 @@ try { --- +## Backend API Reference + +### REST Endpoints + +**Auth** (`/api/auth/`) +| Method | Endpoint | Description | +|--------|----------|-------------| +| GET | `/auth/google` | Start Google OAuth (redirect) | +| GET | `/auth/google/callback` | Google OAuth callback | +| GET | `/auth/discord` | Start Discord OAuth (redirect) | +| GET | `/auth/discord/callback` | Discord OAuth callback | +| POST | `/auth/refresh` | Refresh access token | +| POST | `/auth/logout` | Revoke refresh token | +| POST | `/auth/logout-all` | Revoke all user tokens | +| GET | `/auth/link/google` | Link Google account (authed) | +| GET | `/auth/link/discord` | Link Discord account (authed) | + +**Users** (`/api/users/`) +| Method | Endpoint | Description | +|--------|----------|-------------| +| GET | `/users/me` | Get current user profile | +| PATCH | `/users/me` | Update profile (display_name, avatar_url) | +| GET | `/users/me/linked-accounts` | List linked OAuth accounts | +| DELETE | `/users/me/link/{provider}` | Unlink OAuth provider | +| GET | `/users/me/sessions` | Get active session count | +| GET | `/users/me/starter-status` | Check if starter deck selected | +| POST | `/users/me/starter-deck` | Select starter deck | + +**Collections** (`/api/collections/`) +| Method | Endpoint | Description | +|--------|----------|-------------| +| GET | `/collections/me` | Get user's card collection | +| GET | `/collections/me/cards/{card_id}` | Get specific card quantity | + +**Decks** (`/api/decks/`) +| Method | Endpoint | Description | +|--------|----------|-------------| +| GET | `/decks` | List user's decks | +| POST | `/decks` | Create new deck | +| GET | `/decks/{id}` | Get deck by ID | +| PUT | `/decks/{id}` | Update deck | +| DELETE | `/decks/{id}` | Delete deck | +| POST | `/decks/validate` | Validate deck without saving | + +**Games** (`/api/games/`) +| Method | Endpoint | Description | +|--------|----------|-------------| +| POST | `/games` | Create new game | +| GET | `/games/{id}` | Get game info | +| GET | `/games/me/active` | List user's active games | +| POST | `/games/{id}/resign` | Resign from game (HTTP fallback) | + +### WebSocket Events (Socket.IO) + +**Namespace:** `/game` + +**Client → Server:** +| Event | Payload | Description | +|-------|---------|-------------| +| `game:join` | `{ game_id }` | Join/rejoin a game room | +| `game:action` | `{ action_type, ...data }` | Execute game action | +| `game:resign` | `{ game_id }` | Resign from game | +| `game:spectate` | `{ game_id }` | Join as spectator | +| `game:leave_spectate` | `{ game_id }` | Leave spectator mode | + +**Server → Client:** +| Event | Payload | Description | +|-------|---------|-------------| +| `game:state` | `GameState` | Full game state (visibility filtered) | +| `game:action_result` | `ActionResult` | Result of player action | +| `game:error` | `{ message, code }` | Error notification | +| `game:turn_timeout_warning` | `{ remaining_seconds }` | Turn timer warning | +| `game:game_over` | `{ winner, reason }` | Game ended | +| `game:opponent_connected` | `{ connected }` | Opponent connection status | +| `game:reconnected` | `{ game_id, state }` | Auto-reconnected to game | +| `game:spectator_count` | `{ count }` | Spectator count update | + +### Key Backend Files + +| File | Description | +|------|-------------| +| `backend/app/api/auth.py` | Auth endpoints implementation | +| `backend/app/api/users.py` | User endpoints implementation | +| `backend/app/api/games.py` | Game REST endpoints | +| `backend/app/schemas/` | Pydantic request/response schemas | +| `backend/app/schemas/ws_messages.py` | WebSocket message schemas | +| `backend/app/socketio/game_namespace.py` | WebSocket event handlers | + +### Type Definitions to Mirror + +When creating frontend types, reference these backend schemas: +- `backend/app/schemas/user.py` → `UserResponse`, `UserUpdate` +- `backend/app/schemas/deck.py` → `DeckResponse`, `DeckCreate`, `DeckUpdate` +- `backend/app/schemas/game.py` → `GameCreateRequest`, `GameResponse` +- `backend/app/schemas/ws_messages.py` → All WebSocket message types + +--- + ## See Also - `PROJECT_PLAN_FRONTEND.json` - Phase plan and tasks - `../backend/CLAUDE.md` - Backend guidelines +- `../backend/app/schemas/` - API schema definitions +- `../backend/app/socketio/README.md` - WebSocket documentation - `../CLAUDE.md` - Project-wide guidelines