Welcome to the Interview Backend Challenge! This project is built with FastAPI for serving the API and Pydantic for robust data validation, following a clean architecture approach to ensure maintainability and scalability.
The objectives are described in the PDF you received.
- 🐍 Python 3.13 or higher
- ⚡ UV (Python package manager and virtual environment tool)
- 🐳 Docker (for containerized development)
Make sure you have Python 3.13 or higher installed. You can download it from the official Python website.
UV is a fast Python package manager that also allows you to create and manage virtual environments.
For installation details, see the UV documentation.
UV automatically creates a virtual environment for the project by installing the required dependencies. At this point it is necessary to have Python version 3.13 or higher installed. To create a virtual environment and install the dependencies, run the following command in the project directory:
uv sync --extra devTo run the project, use the following command:
docker-compose build
docker-compose upOnce the application is running, you can access it at http://localhost:3001/docs.
To run the tests, use the following command:
uv run pytest ./testsThe codebase is organized into three main layers:
- Exposes the HTTP API using FastAPI.
- Contains route definitions for users and news (
routes/). - Handles authentication and security logic (
auth/). - Manages dependency injection and wiring via
container.py, which connects protocol interfaces to their concrete implementations for loose coupling and easy testing.
- Defines the business logic and domain entities.
- Organized by feature (e.g.,
news/,users/), each with:entities/: Pydantic models and DTOs for data validation and transfer.protocols/: Abstract repository interfaces (Python Protocols) that describe required data operations, independent of the database or framework.services/: Business logic and use cases, operating only on protocols and entities, never on infrastructure details.
- Implements the actual data access logic.
- Contains database models (Beanie ODM for MongoDB) and repository implementations that fulfill the contracts defined in
core/protocols/. - Includes database connection setup and seeding utilities.
-
The
api/container.pyfile is responsible for dependency injection. -
It binds protocol interfaces from
core/protocols/to their concrete implementations ininfraestructure/database/repositories/. -
This design allows you to swap implementations (e.g., for testing) without changing business logic.
-
Ensure you have Docker installed and running to use docker-compose commands.
-
The project is designed to be run in a virtual environment for better dependency management.
-
The
uvcommand is used to manage the virtual environment and dependencies. -
If you want to add a new dependency with
uvyou can use the command:
uv add <package_name>- Visual Studio Code
- If you are using Visual Studio Code, you can install the Python extension for better support.
- And the black formatter for code formatting.