167a352d44d4af0509ec01a4e40cea55ea9bff87
- Updated JWT tokens to include privlevel for authorization - Fixed test fixtures to properly hash passwords with bcrypt - Fixed client fixture to share database session with test fixtures - Reordered deck router routes to prevent conflicts - Removed relationship fields from FolderResponse schema - Updated conftest.py with proper async session management
Cockatrice Web Application
A modern web-based implementation of the Cockatrice multiplayer Magic: The Gathering platform.
Features
- User Authentication: Secure JWT-based authentication with bcrypt password hashing
- Deck Building: Full-featured deck editor with import/export in multiple formats
- Real-Time Multiplayer: WebSocket-based game server for live gameplay
- Protocol Compatibility: Compatible with Cockatrice protocol buffer messages
- Card Database: Integration with MTJSON for comprehensive card data
- Admin Tools: Comprehensive moderation and administration dashboard
Tech Stack
- Backend: Python 3.12, FastAPI, SQLAlchemy (async), PostgreSQL
- Frontend: React, TypeScript, Zustand (coming soon)
- Game Server: WebSocket with real-time state synchronization
- Authentication: JWT tokens with bcrypt password hashing
- Database: PostgreSQL with async driver (asyncpg)
- Protocol: Protocol buffer message compatibility
Getting Started
Prerequisites
- Python 3.12+
- PostgreSQL 14+
- Redis (optional, for caching)
Installation
- Clone the repository
git clone https://github.com/yourusername/cockatrice-web.git
cd cockatrice-web
- Create a virtual environment
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
- Install dependencies
cd backend
pip install -r requirements.txt
- Configure environment
cp .env.example .env
# Edit .env with your configuration
- Set up the database
# Create PostgreSQL database
createdb cockatrice
# Run migrations (when Alembic is set up)
alembic upgrade head
- Run the application
uvicorn app.main:app --reload --host 0.0.0.0 --port 8000
- Access the API documentation
Open http://localhost:8000/docs to view the FastAPI Swagger UI.
Project Structure
cockatrice-web/
├── backend/
│ ├── app/
│ │ ├── core/ # Core configuration and utilities
│ │ │ ├── settings.py # Application settings
│ │ │ ├── database.py # Database engine and sessions
│ │ │ └── security.py # Authentication and password hashing
│ │ ├── models/ # SQLAlchemy ORM models
│ │ │ └── models.py
│ │ ├── schemas/ # Pydantic schemas
│ │ │ ├── schemas.py
│ │ │ ├── proto_messages.py
│ │ │ └── protocol_constants.py
│ │ ├── routers/ # API route handlers
│ │ │ ├── auth.py
│ │ │ ├── users.py
│ │ │ ├── decks.py
│ │ │ ├── rooms.py
│ │ │ ├── games.py
│ │ │ ├── admin.py
│ │ │ └── ws.py
│ │ ├── services/ # Business logic services
│ │ │ ├── game_server.py
│ │ │ ├── card_database.py
│ │ │ └── deck_parser.py
│ │ └── main.py # FastAPI application
│ ├── tests/ # Test suite
│ ├── requirements.txt # Python dependencies
│ ├── pyproject.toml # Ruff configuration
│ └── .env.example # Environment template
├── frontend/ # React/TypeScript frontend (coming soon)
├── shared/ # Shared protocol definitions
│ └── proto/ # Protocol buffer definitions
└── README.md
API Endpoints
Authentication
POST /api/v1/auth/login- User loginPOST /api/v1/auth/register- User registrationPOST /api/v1/auth/refresh- Refresh access tokenGET /api/v1/auth/me- Get current user
Users
GET /api/v1/users/{user_id}- Get user by IDPATCH /api/v1/users/{user_id}- Update user profilePOST /api/v1/users/{user_id}/ban- Ban user (admin)POST /api/v1/users/{user_id}/unban- Unban user (admin)
Decks
GET /api/v1/decks/- List decksPOST /api/v1/decks/- Create deckGET /api/v1/decks/{deck_id}- Get deckPATCH /api/v1/decks/{deck_id}- Update deckDELETE /api/v1/decks/{deck_id}- Delete deckGET /api/v1/decks/folders- List foldersPOST /api/v1/decks/folders- Create folderDELETE /api/v1/decks/folders/{folder_id}- Delete folder
Admin
GET /api/v1/admin/users- List all users (admin)GET /api/v1/admin/bans- List all bans (admin)POST /api/v1/admin/bans- Create ban (admin)POST /api/v1/admin/bans/{ban_id}/unban- Unban user (admin)GET /api/v1/admin/logs- List game logs (admin)
Testing
Run the test suite:
cd backend
pytest
License
MIT License
Contributing
Contributions are welcome! Please open an issue or submit a pull request.
Support
For questions or issues, please open a GitHub issue.
Languages
C++
80.4%
Python
15.7%
CMake
1.8%
Shell
0.9%
C
0.9%
Other
0.1%