CSCI 338: Fall 2025

Software Engineering

CSCI 338: Fall 2025

Project 2 > Database

1. Introduction

We are now going to start building our Docker containers. This project uses a three-container architecture where each service runs in its own isolated container:

  1. Database Container - PostgreSQL database for storing application data
  2. Backend Container - FastAPI server that handles API requests and communicates with the database
  3. Frontend Container - React application that provides the user interface

Why three containers?

The containers communicate with each other through Docker’s internal networking, which we’ll configure in the docker-compose.yaml file.

Architecture Diagram:

┌─────────────────────────────────────────────────────────────┐
│                    Your Laptop                              │
│                                                             │
│  ┌──────────────┐         ┌──────────────┐                  │
│  │   Browser    │────────▶│  Frontend    │                  │
│  │              │  :5173  │  Container   │                  │
│  │ localhost    │◀────────│  (React)     │                  │
│  └──────────────┘         └──────┬───────┘                  │
│                                  │                          │
│                                  │ HTTP Requests            │
│                                  │ (localhost:8000)         │
│                                  ▼                          │
│                          ┌──────────────┐                   │
│                          │   Backend    │                   │
│                          │  Container   │                   │
│                          │  (FastAPI)   │                   │
│                          └──────┬───────┘                   │
│                                  │                          │
│                                  │ SQL Queries              │
│                                  │ (internal Docker network)│
│                                  ▼                          │
│                          ┌──────────────┐                   │
│                          │  Database    │                   │
│                          │  Container   │                   │
│                          │ (PostgreSQL) │                   │
│                          └──────────────┘                   │
│                                                             │
└─────────────────────────────────────────────────────────────┘

Port Mappings:
- Frontend:  localhost:5173  ←→  Container:5173
- Backend:   localhost:8000  ←→  Container:8000
- Database:  localhost:5433  ←→  Container:5432 (internal only)

How it works:

2. Create a New Branch

Before you begin, create a new Git branch for this work:

git checkout -b system-setup

Why create a branch?

Before you move on

Verify that you’re on your new branch – not main.

3. Create Database Dockerfile

Create database/Dockerfile with the following exact content:

FROM postgres:15
ENV POSTGRES_PASSWORD=postgres

Why this works:

4. Create .env File

Create a .env file at the root of your project with the following content:

# Local Docker DB connection string:
DATABASE_URL=postgresql+asyncpg://postgres:postgres@db:5432/todo_db

Why this matters:

Before you move on

  • Verify your .env file exists at the project root and contains the DATABASE_URL.
  • Also verify that your file structure looks like the one below:
project02-fall2025
├── .env            # new (and excluded from version control via .gitignore)
├── .git/
├── .gitignore
├── backend/
│   └── models/
├── database/
│   └── Dockerfile  # new
├── README.md
└── ui/
    └── src/

5. Push your new branch

Go ahead and push your new branch to GitHub.

Before you move on

Verify that your new branch is on GitHub. Don’t worry about making a PR or merging anything yet. We’ll address that later.


← Back to Project 2 Instructions