3-Tier Python App with PostgreSQL
A Python FastAPI backend with PostgreSQL, containerised with Docker Compose, using environment-based configuration and connection pooling — deployed as a client project on Upwork.

A Python FastAPI backend with PostgreSQL, containerised with Docker Compose, using environment-based configuration and connection pooling — deployed as a client project on Upwork.

Problem
A freelance client needed a data capture service: a web form that writes to a database, with a backend API for retrieval. The architecture needed to be multi-tier and deployable on a VPS without managed cloud services.
Approach
Built a FastAPI backend with endpoints for data submission and retrieval.
Integrated PostgreSQL using SQLAlchemy with connection pooling (pool_size=10, max_overflow=20).
Managed credentials via environment variables — no hardcoded secrets in the repository.
Containerised the full stack with Docker Compose: app service, PostgreSQL service, shared network.
Added database health check and automatic restart policy for the app container.
Served a static HTML/JS frontend through Nginx as the reverse proxy layer.
Results
Code
FastAPI endpoint with SQLAlchemy connection pooling and environment config.
from fastapi import FastAPI, Depends
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker, Session
import os
DATABASE_URL = os.getenv("DATABASE_URL")
engine = create_engine(
DATABASE_URL,
pool_size=10,
max_overflow=20,
pool_pre_ping=True,
)
SessionLocal = sessionmaker(bind=engine)
def get_db():
db = SessionLocal()
try:
yield db
finally:
db.close()
app = FastAPI()
@app.post("/submit")
def submit(data: dict, db: Session = Depends(get_db)):
return {"status": "ok"}Stack
Why it matters