How danxvv/banpayghibli works
Project Type and Purpose
• The project is a backend API built using FastAPI that provides complete CRUD operations on a users table, along with role-based access control and integration with an external Ghibli API. It also includes authentication (using JWT), database migrations with Alembic, and it is fully containerized using Docker Compose.
File Structure
• The top-level project includes configuration files (Dockerfile, docker-compose.yml, .env.example), setup scripts (entrypoint.sh), and documentation (README.md, Postman collection).
• The “src” directory is the main application code. It is organized into:
• An “auth” module for authentication routes and schemas.
• A “ghibli” module dedicated to calling the Ghibli API.
• A “users” module that handles user models, routes, services, and repositories.
• A “database” module that manages SQLAlchemy sessions and configurations.
• Utility code in the “utils” module.
• Migration scripts reside in the “alembic” folder, indicating database schema management.
• Tests are separated in the “tests” directory.
README for Architectural Insights
• The README outlines key API endpoints for authentication, users, roles, and Ghibli data.
• It mentions the use of technologies (Python, FastAPI, SQLAlchemy, Alembic, PostgreSQL, Docker) that should be part of the system design.
• Guidance is provided for local development (via Docker) and includes detailed API endpoint interactions, which help in understanding data flows and security roles.
a. Main Components to Include:
• API Server:
• FastAPI application (src/main.py) hosting the endpoints.
• Route modules: auth routes (src/auth), users routes (src/users), and ghibli routes (src/ghibli).
• Database:
• PostgreSQL (as configured via Docker Compose and SQLAlchemy in src/database).
• Alembic module used for migration/versioning.
• Authentication Component:
• JWT authentication handled in auth module with helper functions (e.g., in src/utils/security.py).
• External Service:
• Ghibli API integration defined in src/ghibli/services.py.
• Docker Infrastructure:
• Dockerfile and docker-compose.yml that containerize the API and the database.
• Testing Environment:
• Unit/integration tests in the tests folder.
b. Relationships and Interactions:
• The API Server interacts with:
• The Database module for CRUD operations (through SQLAlchemy sessions and models defined under src/users/models.py).
• The External Ghibli API via the designated service (src/ghibli/services.py) triggered based on specific user roles.
• The Authentication component secures endpoints and manages token generation as defined in the auth routes.
• Each module (auth, users, ghibli) is connected through a central router (src/router.py), ensuring that every route is accessible via versioned endpoint paths as described in the README.
• Docker Compose orchestrates the containers, ensuring the API service and PostgreSQL run and communicate properly.
c. Architectural Patterns and Technologies:
• MVC-like structure: Models (src/users/models.py), Views/Routes (various routes in respective modules), and Controllers/Services.
• Dependency injection: Likely used in FastAPI (see src/dependencies.py) to inject database sessions, authentication services into endpoints.
• Containerization: Deployment is handled via Docker and Docker Compose.
• Security: JWT-based token authentication managed via utility modules.
• External integration: The project incorporates an external API call (to the Ghibli API) that is conditionally triggered by user roles.
d. Relevant Technologies:
• FastAPI for the API framework.
• SQLAlchemy for ORM/database interactions.
• Alembic for migrations.
• PostgreSQL as the database.
• Docker and Docker Compose for containerization.
• JWT for secure authentication.