Add backend API reference to frontend CLAUDE.md
- REST endpoints for auth, users, collections, decks, games - WebSocket events (client→server and server→client) - Key backend files to reference - Type definitions to mirror from backend schemas Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
f27830d19e
commit
5b12df0cb1
@ -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
|
## See Also
|
||||||
|
|
||||||
- `PROJECT_PLAN_FRONTEND.json` - Phase plan and tasks
|
- `PROJECT_PLAN_FRONTEND.json` - Phase plan and tasks
|
||||||
- `../backend/CLAUDE.md` - Backend guidelines
|
- `../backend/CLAUDE.md` - Backend guidelines
|
||||||
|
- `../backend/app/schemas/` - API schema definitions
|
||||||
|
- `../backend/app/socketio/README.md` - WebSocket documentation
|
||||||
- `../CLAUDE.md` - Project-wide guidelines
|
- `../CLAUDE.md` - Project-wide guidelines
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user