-
Notifications
You must be signed in to change notification settings - Fork 4
FastAPI
lisambet edited this page Feb 2, 2026
·
3 revisions
FastAPI is a modern, high-performance web framework for building APIs with Python 3.8+ based on standard Python type hints.
| Property | Value |
|---|---|
| Used In | AI Service |
| Language | Python |
| Port | 3005 |
| Documentation | fastapi.tiangolo.com |
โ ๏ธ Note: Do not confuse FastAPI (Python) with Fastify (Node.js).
- FastAPI is used only for the AI microservice.
- Fastify is used for the Gateway, Auth, and Game services.
We chose FastAPI for the AI microservice because it bridges the gap between web servers and Data Science tools perfectly.
- Native Python Support: Our AI model uses PyTorch and Stable Baselines3, which are Python-native. FastAPI allows us to serve these models directly without context switching.
- High Performance: It is one of the fastest Python frameworks available, running on Uvicorn (an ASGI server). This is critical for the AI, which must reply with a move in <50ms.
- Automatic Documentation: It automatically generates interactive Swagger UI documentation, allowing us to test the AI moves manually in the browser.
- Data Validation: It uses Pydantic to validate game coordinates automatically. If the Game Service sends a string instead of a number, FastAPI rejects it instantly.
Instead of manually checking if ball_x is a number, we define a "Model" (Schema). FastAPI guarantees that the function get_move is only called if the data is valid.
from pydantic import BaseModel
# Define the expected data structure
class GameState(BaseModel):
ball_x: float
ball_y: float
paddle_y: float
opponent_y: float
# The API Endpoint
@app.post("/join-game")
async def get_move(state: GameState):
# 'state' is already validated and converted to the correct types
action = model.predict([state.ball_x, state.ball_y, ...])
return {"action": int(action)}- Gateway Service - API Gateway & JWT validation
- Auth Service - Authentication & 2FA/TOTP
- AI Service - AI opponent
- API Documentation - OpenAPI/Swagger
- Fastify - Web framework
- Prisma - ORM
- WebSockets - Real-time communication
- Restful API - API standards
- React - UI library
- CSS - Styling
- Tailwind - CSS framework
- Accessibility - WCAG compliance
- TypeScript - Language
- Zod - Schema validation
- Nginx - Reverse proxy
- Logging and Error management - Observability
- OAuth 2.0 - Authentication flows
- Two-factor authentication - 2FA/TOTP
- Avalanche - Blockchain network
- Hardhat - Development framework
- Solidity - Smart contracts language
- Open Zeppelin - Security standards
- ESLint - Linting
- Vitest - Testing
- GitHub Actions - CI/CD
- Husky, Commit lints and git hooks - Git hooks
- ELK - Logging stack
๐ Page model