🏓 Initial ServeSync demo build
- FastAPI backend with PostgreSQL + Redis - 4 core features: Registration, Courts, Matchmaking, Tournament - Double elimination tournament with bracket visualization - ELO-based matchmaking (Stage 1 Open, Stage 2 Skill-Based) - Real-time WebSocket updates - TV Screen display for courts - Vue 3 + Tailwind CSS frontend - Seed data: 12 players, 4 courts, active matches, tournament in progress - Docker compose stack with Nginx reverse proxy
This commit is contained in:
5
backend/app/models/__init__.py
Normal file
5
backend/app/models/__init__.py
Normal file
@@ -0,0 +1,5 @@
|
||||
from app.models.player import Player
|
||||
from app.models.court import Court
|
||||
from app.models.booking import Booking
|
||||
from app.models.match import Match, MatchPlayer
|
||||
from app.models.tournament import Tournament, TournamentEntry, TournamentMatch
|
||||
33
backend/app/models/booking.py
Normal file
33
backend/app/models/booking.py
Normal file
@@ -0,0 +1,33 @@
|
||||
from sqlalchemy import Column, Integer, ForeignKey, DateTime, Float, String, Enum, Boolean
|
||||
from sqlalchemy.orm import relationship
|
||||
from sqlalchemy.sql import func
|
||||
from app.database import Base
|
||||
import enum
|
||||
|
||||
|
||||
class BookingStatus(str, enum.Enum):
|
||||
PENDING = "pending"
|
||||
CONFIRMED = "confirmed"
|
||||
IN_PROGRESS = "in_progress"
|
||||
COMPLETED = "completed"
|
||||
CANCELLED = "cancelled"
|
||||
|
||||
|
||||
class Booking(Base):
|
||||
__tablename__ = "bookings"
|
||||
|
||||
id = Column(Integer, primary_key=True, index=True)
|
||||
player_id = Column(Integer, ForeignKey("players.id"), nullable=False)
|
||||
court_id = Column(Integer, ForeignKey("courts.id"), nullable=False)
|
||||
start_time = Column(DateTime(timezone=True), nullable=False)
|
||||
end_time = Column(DateTime(timezone=True), nullable=False)
|
||||
duration_hours = Column(Float, default=1.0)
|
||||
total_cost = Column(Float, default=0.0)
|
||||
status = Column(Enum(BookingStatus), default=BookingStatus.CONFIRMED)
|
||||
is_match_booking = Column(Boolean, default=False)
|
||||
notes = Column(String(500))
|
||||
created_at = Column(DateTime(timezone=True), server_default=func.now())
|
||||
|
||||
# Relationships
|
||||
player = relationship("Player", back_populates="bookings")
|
||||
court = relationship("Court", back_populates="bookings")
|
||||
22
backend/app/models/court.py
Normal file
22
backend/app/models/court.py
Normal file
@@ -0,0 +1,22 @@
|
||||
from sqlalchemy import Column, Integer, String, Boolean, Float, DateTime
|
||||
from sqlalchemy.orm import relationship
|
||||
from sqlalchemy.sql import func
|
||||
from app.database import Base
|
||||
import enum
|
||||
|
||||
|
||||
class Court(Base):
|
||||
__tablename__ = "courts"
|
||||
|
||||
id = Column(Integer, primary_key=True, index=True)
|
||||
name = Column(String(50), nullable=False)
|
||||
court_number = Column(Integer, unique=True, nullable=False)
|
||||
hourly_rate = Column(Float, default=200.0)
|
||||
is_active = Column(Boolean, default=True)
|
||||
surface_type = Column(String(50), default="Sport Court")
|
||||
features = Column(String(500), default="LED Lighting, Spectator Seating")
|
||||
created_at = Column(DateTime(timezone=True), server_default=func.now())
|
||||
|
||||
# Relationships
|
||||
bookings = relationship("Booking", back_populates="court")
|
||||
matches = relationship("Match", back_populates="court")
|
||||
73
backend/app/models/match.py
Normal file
73
backend/app/models/match.py
Normal file
@@ -0,0 +1,73 @@
|
||||
from sqlalchemy import Column, Integer, ForeignKey, DateTime, Float, String, Enum, Boolean, JSON
|
||||
from sqlalchemy.orm import relationship
|
||||
from sqlalchemy.sql import func
|
||||
from app.database import Base
|
||||
import enum
|
||||
|
||||
|
||||
class MatchStage(str, enum.Enum):
|
||||
OPEN = "open"
|
||||
SKILL_BASED = "skill_based"
|
||||
TOURNAMENT = "tournament"
|
||||
|
||||
|
||||
class MatchStatus(str, enum.Enum):
|
||||
LOBBY = "lobby"
|
||||
IN_PROGRESS = "in_progress"
|
||||
COMPLETED = "completed"
|
||||
CANCELLED = "cancelled"
|
||||
|
||||
|
||||
class MatchType(str, enum.Enum):
|
||||
SINGLES = "singles"
|
||||
DOUBLES = "doubles"
|
||||
|
||||
|
||||
class Match(Base):
|
||||
__tablename__ = "matches"
|
||||
|
||||
id = Column(Integer, primary_key=True, index=True)
|
||||
court_id = Column(Integer, ForeignKey("courts.id"), nullable=True)
|
||||
stage = Column(Enum(MatchStage), default=MatchStage.OPEN)
|
||||
match_type = Column(Enum(MatchType), default=MatchType.DOUBLES)
|
||||
status = Column(Enum(MatchStatus), default=MatchStatus.LOBBY)
|
||||
|
||||
# Scores
|
||||
team1_score = Column(Integer, default=0)
|
||||
team2_score = Column(Integer, default=0)
|
||||
team1_games = Column(Integer, default=0)
|
||||
team2_games = Column(Integer, default=0)
|
||||
|
||||
# Game details
|
||||
max_players = Column(Integer, default=4)
|
||||
min_elo = Column(Float, nullable=True)
|
||||
max_elo = Column(Float, nullable=True)
|
||||
|
||||
# Match metadata
|
||||
title = Column(String(200))
|
||||
started_at = Column(DateTime(timezone=True), nullable=True)
|
||||
ended_at = Column(DateTime(timezone=True), nullable=True)
|
||||
created_at = Column(DateTime(timezone=True), server_default=func.now())
|
||||
updated_at = Column(DateTime(timezone=True), onupdate=func.now())
|
||||
|
||||
# Relationships
|
||||
court = relationship("Court", back_populates="matches")
|
||||
match_players = relationship("MatchPlayer", back_populates="match", cascade="all, delete-orphan")
|
||||
|
||||
|
||||
class MatchPlayer(Base):
|
||||
__tablename__ = "match_players"
|
||||
|
||||
id = Column(Integer, primary_key=True, index=True)
|
||||
match_id = Column(Integer, ForeignKey("matches.id"), nullable=False)
|
||||
player_id = Column(Integer, ForeignKey("players.id"), nullable=False)
|
||||
team = Column(Integer, nullable=False) # 1 or 2
|
||||
elo_before = Column(Float, nullable=True)
|
||||
elo_after = Column(Float, nullable=True)
|
||||
elo_change = Column(Float, default=0.0)
|
||||
is_winner = Column(Boolean, nullable=True)
|
||||
joined_at = Column(DateTime(timezone=True), server_default=func.now())
|
||||
|
||||
# Relationships
|
||||
match = relationship("Match", back_populates="match_players")
|
||||
player = relationship("Player", back_populates="match_players")
|
||||
46
backend/app/models/player.py
Normal file
46
backend/app/models/player.py
Normal file
@@ -0,0 +1,46 @@
|
||||
from sqlalchemy import Column, Integer, String, Float, DateTime, Enum, Boolean
|
||||
from sqlalchemy.orm import relationship
|
||||
from sqlalchemy.sql import func
|
||||
from app.database import Base
|
||||
import enum
|
||||
|
||||
|
||||
class MembershipTier(str, enum.Enum):
|
||||
BRONZE = "bronze"
|
||||
SILVER = "silver"
|
||||
GOLD = "gold"
|
||||
PLATINUM = "platinum"
|
||||
ELITE = "elite"
|
||||
|
||||
|
||||
class Player(Base):
|
||||
__tablename__ = "players"
|
||||
|
||||
id = Column(Integer, primary_key=True, index=True)
|
||||
name = Column(String(100), nullable=False)
|
||||
email = Column(String(255), unique=True, nullable=False)
|
||||
phone = Column(String(20))
|
||||
elo_rating = Column(Float, default=1000.0)
|
||||
membership_tier = Column(Enum(MembershipTier), default=MembershipTier.BRONZE)
|
||||
wins = Column(Integer, default=0)
|
||||
losses = Column(Integer, default=0)
|
||||
total_matches = Column(Integer, default=0)
|
||||
is_active = Column(Boolean, default=True)
|
||||
avatar_color = Column(String(7), default="#3B82F6")
|
||||
created_at = Column(DateTime(timezone=True), server_default=func.now())
|
||||
updated_at = Column(DateTime(timezone=True), onupdate=func.now())
|
||||
|
||||
# Relationships
|
||||
bookings = relationship("Booking", back_populates="player")
|
||||
match_players = relationship("MatchPlayer", back_populates="player")
|
||||
tournament_entries = relationship("TournamentEntry", back_populates="player")
|
||||
|
||||
@property
|
||||
def win_rate(self):
|
||||
if self.total_matches == 0:
|
||||
return 0
|
||||
return round(self.wins / self.total_matches * 100, 1)
|
||||
|
||||
@property
|
||||
def tier_label(self):
|
||||
return self.membership_tier.value.capitalize()
|
||||
93
backend/app/models/tournament.py
Normal file
93
backend/app/models/tournament.py
Normal file
@@ -0,0 +1,93 @@
|
||||
from sqlalchemy import Column, Integer, ForeignKey, DateTime, Float, String, Enum, Boolean, JSON
|
||||
from sqlalchemy.orm import relationship
|
||||
from sqlalchemy.sql import func
|
||||
from app.database import Base
|
||||
import enum
|
||||
|
||||
|
||||
class TournamentStatus(str, enum.Enum):
|
||||
REGISTRATION = "registration"
|
||||
IN_PROGRESS = "in_progress"
|
||||
COMPLETED = "completed"
|
||||
|
||||
|
||||
class BracketType(str, enum.Enum):
|
||||
WINNERS = "winners"
|
||||
LOSERS = "losers"
|
||||
GRAND_FINAL = "grand_final"
|
||||
|
||||
|
||||
class TournamentMatchStatus(str, enum.Enum):
|
||||
PENDING = "pending"
|
||||
IN_PROGRESS = "in_progress"
|
||||
COMPLETED = "completed"
|
||||
|
||||
|
||||
class Tournament(Base):
|
||||
__tablename__ = "tournaments"
|
||||
|
||||
id = Column(Integer, primary_key=True, index=True)
|
||||
name = Column(String(200), nullable=False)
|
||||
status = Column(Enum(TournamentStatus), default=TournamentStatus.REGISTRATION)
|
||||
max_participants = Column(Integer, default=8)
|
||||
current_round = Column(Integer, default=1)
|
||||
bracket_data = Column(JSON, nullable=True)
|
||||
started_at = Column(DateTime(timezone=True), nullable=True)
|
||||
ended_at = Column(DateTime(timezone=True), nullable=True)
|
||||
created_at = Column(DateTime(timezone=True), server_default=func.now())
|
||||
|
||||
# Relationships
|
||||
entries = relationship("TournamentEntry", back_populates="tournament")
|
||||
tournament_matches = relationship("TournamentMatch", back_populates="tournament")
|
||||
|
||||
|
||||
class TournamentEntry(Base):
|
||||
__tablename__ = "tournament_entries"
|
||||
|
||||
id = Column(Integer, primary_key=True, index=True)
|
||||
tournament_id = Column(Integer, ForeignKey("tournaments.id"), nullable=False)
|
||||
player_id = Column(Integer, ForeignKey("players.id"), nullable=False)
|
||||
seed = Column(Integer, nullable=True)
|
||||
final_rank = Column(Integer, nullable=True)
|
||||
is_eliminated = Column(Boolean, default=False)
|
||||
losses = Column(Integer, default=0)
|
||||
wins = Column(Integer, default=0)
|
||||
is_in_losers = Column(Boolean, default=False)
|
||||
registered_at = Column(DateTime(timezone=True), server_default=func.now())
|
||||
|
||||
# Relationships
|
||||
tournament = relationship("Tournament", back_populates="entries")
|
||||
player = relationship("Player", back_populates="tournament_entries")
|
||||
|
||||
|
||||
class TournamentMatch(Base):
|
||||
__tablename__ = "tournament_matches"
|
||||
|
||||
id = Column(Integer, primary_key=True, index=True)
|
||||
tournament_id = Column(Integer, ForeignKey("tournaments.id"), nullable=False)
|
||||
match_id = Column(Integer, ForeignKey("matches.id"), nullable=True)
|
||||
round_number = Column(Integer, nullable=False)
|
||||
match_number = Column(Integer, nullable=False)
|
||||
bracket_type = Column(Enum(BracketType), default=BracketType.WINNERS)
|
||||
status = Column(Enum(TournamentMatchStatus), default=TournamentMatchStatus.PENDING)
|
||||
|
||||
# Players
|
||||
player1_id = Column(Integer, ForeignKey("players.id"), nullable=True)
|
||||
player2_id = Column(Integer, ForeignKey("players.id"), nullable=True)
|
||||
player3_id = Column(Integer, ForeignKey("players.id"), nullable=True) # doubles team2 p1
|
||||
player4_id = Column(Integer, ForeignKey("players.id"), nullable=True) # doubles team2 p2
|
||||
|
||||
# Scores
|
||||
team1_score = Column(Integer, default=0)
|
||||
team2_score = Column(Integer, default=0)
|
||||
winner_team = Column(Integer, nullable=True)
|
||||
|
||||
# Next match routing
|
||||
winner_next_match = Column(Integer, nullable=True)
|
||||
loser_next_match = Column(Integer, nullable=True)
|
||||
|
||||
created_at = Column(DateTime(timezone=True), server_default=func.now())
|
||||
completed_at = Column(DateTime(timezone=True), nullable=True)
|
||||
|
||||
# Relationships
|
||||
tournament = relationship("Tournament", back_populates="tournament_matches")
|
||||
Reference in New Issue
Block a user