How ingsoft1-capybaras/switcher-backend works
Project Type and Purpose
• This is a modular, monolithic backend API built with FastAPI (served by Uvicorn).
• It serves a board‑game application, exposing endpoints for entities such as Board, Game, Player, FigureCards, MovementCards, GameState, PartialMovement.
• Persists data in (presumably) a relational database via a shared database module.
File Structure
• Top‐level:
• main.py – FastAPI app entry point
• connection_manager.py & database/db.py – sets up DB connection pooling
• settings.py – environment/config management
• run_server.sh & Makefile – deployment/test scripts
• Feature modules (each under its own directory):
• {board, game, player, figureCards, movementCards, gameState, partial_movement}
– endpoints.py (HTTP layer)
– <feature>_logic.py (business logic/domain)
– <feature>_repository.py (data access)
– models.py (ORM/data models)
– schemas.py (Pydantic request/response)
• tests/ – unit & integration tests
README for Additional Insights
• Server is launched via uvicorn main:app --reload, reads ENVIRONMENT variable to select DB.
• Uses Python 3.6+, FastAPI, Pydantic, a SQL‐backed database.
• No frontend here – purely backend API.
Main Components
A. External Client (could be CLI, frontend, other services)
B. API Gateway Layer
• FastAPI (main.py)
• Route registration via each module’s endpoints.py
C. Domain Layer (per‑feature business logic components)
• BoardLogic, GameLogic, PlayerLogic, etc.
D. Data Access Layer
• BoardRepository, GameRepository, etc.
• ConnectionManager & pooled DB sessions (database/db.py)
E. Database
• PostgreSQL/MySQL (or SQLite depending on ENV)
F. Configuration
• settings.py driving ENVIRONMENT → DB selection
G. Dev/Test Harness (Makefile, run_server.sh, pytest)
Architectural Patterns & Principles
• Layered (Presentation → Domain → Persistence)
• Modular feature boundaries (each feature grouped in its directory)
• Dependency Inversion: Logic depends on abstracted repository interfaces
• Single responsibility per module
• Environment‐driven configuration for multiple databases
Technologies & Frameworks to Label
• FastAPI + Uvicorn
• Pydantic for Schemas
• SQLAlchemy or equivalent ORM (in models.py)
• Connection Pool Manager (connection_manager.py)
• pytest for testing
• bash scripts & Makefile for orchestration
Essential Elements
• Labels: Module names, file names (e.g., board/endpoints.py)
• Configuration overlay: settings.py feeding into DB connection