How fan9704/drawing-competition-backend-v2 works
Project Type and Purpose
• This is a backend web service for a drawing or challenge-based application refactored using FastAPI.
• Its purpose is to expose RESTful endpoints (with Swagger documentation available at /docs) that handle functionalities for challenges, teams, submissions, clips, rounds, and statistics.
• The project leverages FastAPI, Tortoise ORM for persistence, and Pydantic for data validation, with the use of JWT for authorization and middleware for internationalization (i18n).
Analyzing the File Structure
• The top-level organization clearly separates the application code under the “src” directory, testing under “tests”, Docker-related deployment configuration (Dockerfile and docker-compose.yaml), and project metadata/configurations.
• Key directories in “src” include:
• configs – Contains configuration for the application such as database (db.py), JWT settings, and OpenAPI configurations.
• dependencies – Manages external dependencies (repositories and utilities) that might be injected into services or routers.
• exceptions – Custom exception handling logic to streamline error responses.
• middlewares – Likely routing and language selection middleware (e.g., language.py).
• models – Two distinct parts: “pydantic” models for request/response validation and “tortoise” models for database ORM mapping; enums reside here as well.
• repositories – Abstract data access into CRUD operations for challenges, rounds, submissions, and teams.
• routers – FastAPI route definitions that map endpoints (challenge, clip, round, statistic, team, etc.) to business logic.
• services – Contains the business logic for processing clips and team operations.
• utils – Generic utility functions like those for API routing, clip operations, image judging logic, and JWT handling.
• The project also includes language-driven functionality (translations directory) and extensive automated tests (unit, integration, e2e) that further validate each architectural component.
• At the top, show “Clients/Users” sending requests.
• Branch out to:
• “Routers” layer: separate nodes for each domain (challenge, clip, round, statistic, team, submission).
• “Services” layer: business logic nodes (clip logic, team operations).
• “Repositories” layer: corresponding CRUD operations that connect to models.
• “Models”: split into Pydantic (for API validation) and Tortoise ORM (for persistence with PostgreSQL).
• At the bottom, connect to “PostgreSQL Database” (and note connection requirements like timezone settings).
• On the side, list “External Dependencies” such as GhostScript, opencv-python, and other libraries.
• API request flows → Middleware (i18n, JWT) → Routers → Service → Repository → Database.
• Optionally, indicate testing components and containerization outside the primary application logic for deployment reference.