This project provides a simple user management and login flow:
- Backend: FastAPI + SQLAlchemy, password hashing with Argon2, PostgreSQL database.
- Frontend: Streamlit login UI (Courier-based widget) to authenticate users.
The UI:
It includes user registration, login verification, and basic CRUD operations on users.
- FastAPI, Uvicorn
- SQLAlchemy
- Argon2 for password hashing
- Pydantic for request/response models
- PostgreSQL (can be adapted)
- Streamlit (frontend)
backend/: FastAPI app, database models, routes, and CRUD logicmain.py: FastAPI application entrypointrouter.py: API routes (users CRUD, auth)models.py: SQLAlchemy modelsschemas.py: Pydantic schemascrud.py: Database operationsdatabase.py: DB connection and session
frontend/: Streamlit appapp.py: Streamlit entrypoint using a login widget (src/widgets.py)src/widgets.py,src/utils.py: UI and helper functions
- Python 3.12
- PostgreSQL running and reachable
- Create and activate a virtual environment (optional if you already have one):
python3.12 -m venv venv
source venv/bin/activate- Install dependencies (root or per service):
pip install -r requirements.txt- Configure backend environment variables in
backend/.env:
DB_USER=your_user
DB_PASSWORD=your_password
DB_HOST=localhost
DB_PORT=5432
DB_NAME=your_database- Configure frontend environment for Courier in a
.env(root orfrontend/):
COURIER_AUTH_TOKEN=your_courier_tokenFrom the backend/ directory:
cd backend
uvicorn main:app --reloadThe API will be available at http://127.0.0.1:8000.
From the project root or frontend/ directory:
streamlit run frontend/app.pyThe app will prompt for login using the Courier-powered widget.
POST /auth/register: Register a new user. Body:{ username, email, password, department }POST /auth/login: Login with{ email, password }(Argon2 verification)GET /users: List all usersGET /users/id/{user_id}: Get user by idGET /users/email/{user_email}: Get user by emailPOST /users: Create user (server-side hashing is in register flow; direct create assumes full payload)PUT /users/email/{user_email}: Update user fields; hashes password if presentDELETE /users/email/{user_email}: Delete user by emailPUT /users/email/{user_email}/password: Change password safely (Argon2)
Notes:
- Passwords are hashed with Argon2 (
argon2-cffi). models.Usersstorespassword(hashed),department(enum), and audit fields.
- Ensure
backend/.envis present; the backend will fail fast with a clear error if required variables are missing. - Do not commit real secrets. Use
.envfiles or secret managers for production.
- If you don’t need a custom port, keep
DB_PORT=5432.
- Docker and Docker Compose installed
Create a .env in the project root (same folder as docker-compose.yml):
DB_USER=postgres
DB_PASSWORD=postgres
DB_HOST=db
DB_PORT=5432
DB_NAME=crud
COURIER_AUTH_TOKEN=your_courier_tokenNotes:
- Backend reads DB_* envs. The compose sets
DB_HOST=db(the Postgres service name). - Frontend requires
COURIER_AUTH_TOKEN. If missing, it stops with an error.
From the project root:
docker compose up -d --buildServices and ports:
- Backend (FastAPI): http://localhost:8000
- Frontend (Streamlit): http://localhost:8510 (host port mapped to container 8501)
- Postgres: localhost:5432
###Author Lucas Inocêncio
