This project is a fast api application for generating random passwords. assword
- Python 3.10+ support
- Asynchoronous capabilities
- Basic Authentication using Username and Password
- Testing suite
- Type checking using mypy
- Readily available CRUD operations
- Linting using pylint
- Formatting using black
You need following to run this project:
- Python 3.10
- Docker with Docker Compose
- Poetry
I use asdf to manage my python versions. You can use it too. However, it is only supported on Linux and macOS. For Windows, you can use something like pyenv.
Once you have installed the above and have cloned the repository, you can follow the following steps to get the project up and running:
cd backend
- Create a virtual environment using poetry:
poetry shell
- Install the dependencies:
poetry install
-
Copy the
.env.example
file to.env
and update the values as per your needs. -
Run the migrations:
make migrate
- Run the server:
make run
OR
- Run the backend app using docker compose:
docker-compose up -d
OR
- Install dependencies using pip
pip install -r requirements.txt
- Run the backend app using python
python3 backend
The server should now be running on http://localhost:8000
and the API documentation should be available at http://localhost:8000/docs
.
The project is designed to be modular and scalable. There are 3 main directories in the project:
-
core
: This directory contains the central part of this project. It contains most of the boiler plate code like security dependencies, database connections, configuration, middlewares etc. It also contains the base classes for the models, repositories, and controllers. Thecore
directory is designed to be as minimal as possible and usually requires minimal attention. Overall, thecore
directory is designed to be as generic as possible. -
app
: This directory contains the actual application code. It contains the controllers, and schemas for the application. The directory has following sub-directories:controllers
This is where the business logic for the application are.schemas
This is where the schemas for the application is defined. The schemas are used for validation and serialization/deserialization of the data.
-
api
: This directory contains the API layer of the application. It contains the API router.
The authentication used is basic implementation of basic auth. When the credential
is supplied in the Authorization
header, the username
and password
is verified and the user is automatically authenticated by setting request.user.id
using middleware. If for any endpoint you want to enforce authentication, you can use the AuthenticationRequired
dependency. It will raise a HTTPException
if the user is not authenticated.
You can use make format
to format the code using black
and isort
.
You can use make lint
to lint the code using pylint
.
The project contains tests for all endpoints, some of the logical components like BasicAuth
and AuthenticationRequired
and an example of testing complex inner components like PasswordGeneratorController
. The tests are located in tests/
. You can run the tests using make test
.