A minimal, module-based FastAPI backend with:
- Feature-first structure (
modules/*) - JWT authentication
- PostgreSQL + PostGIS (Docker only)
- Backend runs locally inside a virtual environment
- Python 3.10+
- Docker & Docker Compose
git clone <repo-url>
cd backendSet-ExecutionPolicy -Scope Process -ExecutionPolicy Bypass.\.venv\Scripts\Activate.ps1You should now see:
(.venv)
python -m pip install --upgrade pip
pip install -r requirements.txtdocker compose up -dPostgreSQL + PostGIS will be available on:
localhost:5432
uvicorn app.main:app --reload- Swagger UI → http://localhost:8000/docs
- ReDoc → http://localhost:8000/redoc
- JWT logic is in
app/core/security.py - Protect routes using:
Depends(get_current_user)Clients must send:
Authorization: Bearer <token>
If (venv) is not visible in the terminal, the app will not work correctly.
To re-enter venv anytime:
.\.venv\Scripts\Activate.ps1- Create a new folder:
app/modules/<module_name>/
- Add these files:
router.py
service.py
repository.py
models.py
schemas.py
- Register the router in
app/main.py:
from app.modules.<module_name>.router import router as module_router
app.include_router(module_router, prefix="/<module_name>")Whenever you add or modify a database model:
-
Register the model
# Add your model import to: app/db/models.py -
Generate a migration
alembic revision --autogenerate -m "describe your change" -
Apply the migration
alembic upgrade head
That’s it.
All required values are defined in .env:
ENVIRONMENT=local
SECRET_KEY=supersecret
ALGORITHM=HS256
ACCESS_TOKEN_EXPIRE_MINUTES=60
POSTGRES_USER=app
POSTGRES_PASSWORD=app
POSTGRES_DB=app
POSTGRES_HOST=localhost
POSTGRES_PORT=5432.\.venv\Scripts\Activate.ps1docker compose up -duvicorn app.main:app --reloaddocker compose down- Keep infrastructure minimal
- Keep modules isolated
- Add complexity only when needed
- Optimize for speed and clarity