A RESTful API service for managing users with the ability to select a repository (in-memory or database) during application initialization. The project is developed using FastAPI, PostgreSQL, SQLAlchemy, and Docker Compose. Tests are written using pytest.
- Python 3.10 or higher
- Docker and Docker Compose
- PostgreSQL (if using the database repository)
git clone https://github.com/sixtis1/test-crud.git
cd test-crudInstall the dependencies from the requirements.txt file:
pip install -r requirements.txtStart the PostgreSQL container using Docker Compose:
docker-compose up -dConfiguration parameters are located in the app/.env file.
REPOSITORY_TYPE=memory # Change to "db" to use the database repository
DATABASE_URL=postgresql+asyncpg://user:password@localhost:5432/test_db
POSTGRES_USER=user
POSTGRES_PASSWORD=password
POSTGRES_DB=test_dbStart the application using Uvicorn:
python -m uvicorn app.main:app --reloadThe application will be available at: http://localhost:8000
Upon startup, the application automatically creates the necessary tables in the database.
Interactive API documentation is available at http://localhost:8000/docs
Execute the following command to run all tests:
pytest├── app
│ ├── __init__.py
│ ├── main.py # Entry point of the FastAPI application
│ ├── models.py # SQLAlchemy models
│ ├── schemas.py # Pydantic schemas for validation
│ ├── routers
│ │ ├── __init__.py
│ │ └── users.py # Endpoints for user operations
│ ├── repositories
│ │ ├── __init__.py
│ │ ├── base.py # Abstract repository class
│ │ ├── memory_repository.py # In-memory repository implementation
│ │ └── db_repository.py # Database repository implementation
│ ├── dependencies.py # Application dependencies
│ └── config.py # Configuration file
├── tests
│ ├── __init__.py
│ └── test_users.py # Tests for user endpoints
├── docker-compose.yml # Docker Compose file for PostgreSQL
├── requirements.txt # Project dependencies
└── README.md # Project documentation