Files
mtgonline/backend
akadmin bea91db64d Phase 3: Schema Layer - Pydantic v2 migration, deduplication, and missing schemas
- Migrated all schemas to Pydantic v2 syntax (model_config, ConfigDict)
- Fixed mutable default in ProtoMessageBase using Field(default_factory=datetime.now)
- Consolidated CardCollection and Wishlist schemas in user_card_collection.py
- Created game_schemas.py with GameCreate, GameResponse, GameJoinRequest, etc.
- Created mtg_card_schemas.py with MtgCardResponse, MtgCardSearchRequest, etc.
- Added CardImportBatchCreate, CardImportBatchResponse, UserCardImportCreate/Response schemas
- Fixed duplicate UserCardImportRecord class between card_import_batch.py and user_card_import_record.py
- Updated __init__.py with comprehensive schema exports
- Created verify_schemas.py for schema-model matching verification
2026-08-16 05:22:17 +00:00
..

MTG Online Backend

FastAPI application for processing MTG card data and managing user decks.

Overview

Python FastAPI application that:

  • Downloads and processes MTGJSON v5 data
  • Stores card data in PostgreSQL (mtgdata database)
  • Manages user accounts, decks, and card imports
  • Exposes REST API for deckbuilding and card search

Key Features

  • MTGJSON Data Pipeline — Downloads and upserts MTGJSON v5 dataset
  • Card Import — Users import card collections with fuzzy matching
  • Deck Management — Create, edit, and finalize decks with precedents
  • Card Search — Fast card lookup for deckbuilding
  • JWT Authentication — Secured API endpoints

API Endpoints

Card Import (/api/v1/card-import/)

Method Endpoint Description
GET /status Get import status
POST / Import/update cards
DELETE / Delete import
GET /summary Match results summary

User Data (/api/v1/user-data/)

Method Endpoint Description
GET/PUT /profile User profile
GET /collection Card collection
GET /groups User groups
GET /preferences User preferences
GET /replays User replays

Decks (/api/v1/decks/)

Method Endpoint Description
CRUD /{deck_id} Deck management
POST /{deck_id}/cards Add card to deck
POST /{deck_id}/finalize Finalize deck
POST /search/cards Search cards
CRUD /precedents/ Deck precedents
CRUD /suggestions/ Card suggestions

Tech Stack

  • Language: Python 3.12
  • Framework: FastAPI
  • Database: PostgreSQL (async via asyncpg)
  • ORM: SQLAlchemy 2.0
  • Migrations: Alembic
  • Cache: Redis
  • Auth: JWT (python-jose + bcrypt)

Running Locally

# Start services
docker compose -f ../docker-compose.dev.yml up -d

# Run migrations
cd app && alembic upgrade head

# Access API
curl http://localhost:5555/health

Migrations

# Create new migration
alembic revision --autogenerate -m "description"

# Run migrations
alembic upgrade head

# Rollback
alembic downgrade -1

License

MIT