This project is a REST API designed using the Hexagonal Architecture. It allows you to perform CRUD operations for character management. The project includes:
- 🌐 Web Interface (Flask-based API)
- 💻 Console Client (using Typer)
- 📝 API Documentation with Swagger UI at the
/docsendpoint - 🧪 Unit Tests with pytest and coverage reports
- 🐳 Docker Compose for easy deployment
- 🧑💻 Postman Collection for API testing in
/docsfolder
- Clone the repository:
git clone <repository_url>
cd <repository_folder>- Create and activate a virtual environment:
python3 -m venv venv
source venv/bin/activate- Install dependencies:
pip install -r requirements.txt- Set environment variables:
cp env_example .env
export $(cat .env | xargs)
Ensure you have Docker and Docker Compose installed. Then, simply run:
cp env_example .env
docker-compose up -dThis will spin up the entire application environment.
The console client provides a CLI for interacting with the API.
python3 cli.py --helplist-characters: Lists all characters.get-character <id>: Retrieves a character by ID.add-character: Adds a new character (provide required fields).delete-character <id>: Deletes a character by ID.
Example:
python3 src/cli.py add-character --name "Luke" --height 172 --mass 77 --hair-color "blond" --skin-color "fair" --eye-color "blue" --birth-year 19if you are deploying the application without Docker, you can run the Flask application directly:
python3 src/app.pyOnce the application is running (via Docker or locally), you can access the API documentation:
- 🚀 Swagger UI: http://localhost:5000/docs
The project uses pytest for unit testing and pytest-cov for coverage reports.
- Run all tests:
pytest- Run tests with coverage report:
pytest --cov=src --cov-report=term-missing---------- coverage: platform linux, python 3.10.12-final-0 ----------
Name Stmts Miss Cover Missing
-------------------------------------------------------------------------------
src/app.py 6 6 0% 1-13
src/application/character_creator.py 7 0 100%
src/application/character_inspector.py 14 0 100%
src/application/character_remover.py 7 0 100%
src/cli.py 3 3 0% 1-4
src/domain/entities/exceptions.py 10 2 80% 3, 10
src/domain/entities/schemas.py 32 2 94% 25, 32
src/domain/repositories/character_repository.py 12 0 100%
src/settings.py 9 9 0% 1-14
-------------------------------------------------------------------------------
TOTAL 100 22 78%
├── application # Use cases (business logic)
├── domain # Domain models and schemas
├── infra # Infrastructure layer (e.g., Flask views, SQL repositories)
│ ├── web
│ │ └── flask # Flask API endpoints and configurations
│ └── repositories # SQLAlchemy repositories
├── cli.py # Console client (Typer-based)
├── app.py # Flask application setup
├── docker-compose.yml # Docker Compose configuration
├── requirements.txt # Python dependencies
├── tests # Unit tests with pytest
│ └── application_test.py # Tests for application layer
└── README.md # Project documentation
- Swagger UI is available at:
/docs - The OpenAPI specification is generated dynamically for all endpoints.
- 🐍 Python 3
- ⚡ Flask - Web Framework
- 🏗️ SQLAlchemy - ORM
- 📝 Pydantic - Data validation and serialization
- 💻 Typer - CLI for Python
- 🐳 Docker & Docker Compose - Containerization
- 🧪 pytest & pytest-cov - Testing and coverage reporting
💡 Designed with Hexagonal Architecture for clean, testable, and maintainable code. 🚀