Skip to content

Latest commit

 

History

4 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Task Manager API

Simple task management API built with FastAPI, PostgreSQL, Docker and Docker Compose.


Project Overview

This project is a basic backend API created to practice real-world backend concepts such as:

  • FastAPI application structure
  • PostgreSQL integration
  • Database connections with psycopg2
  • Docker containerization
  • Multi-container orchestration with Docker Compose

The API communicates with a PostgreSQL database running inside a separate container.

The database is initialized automatically using init.sql when the PostgreSQL container starts for the first time.


Tech Stack

  • Python 3.12
  • FastAPI
  • PostgreSQL
  • psycopg2
  • Docker
  • Docker Compose

Project Structure

task-manager-api/
│
├── app/
│   ├── database.py
│   └── main.py
│
├── .dockerignore
├── .gitignore
├── docker-compose.yml
├── Dockerfile
├── requirements.txt
└── README.md

Containers

The application uses two containers:

API Container

Container name:

api-container

Responsibilities:

  • Runs FastAPI
  • Handles routes/endpoints
  • Connects to PostgreSQL

PostgreSQL Container

Container name:

postgres-container

Responsibilities:

  • Stores application data
  • Provides database access

Database Configuration

Current database settings:

POSTGRES_USER=postgres
POSTGRES_PASSWORD=postgres
POSTGRES_DB=task_manager_db

Connection URL used by the API:

postgresql://postgres:postgres@postgres:5432/task_manager_db

Important:

Inside Docker Compose:

postgres

is the service name used as the host.

Do not use:

localhost

because containers communicate internally through service names.


Running with Docker Compose

Build and start all services:

docker compose up --build

Stop containers:

docker compose down

Check running containers:

docker ps

Running without Docker Compose

Create virtual environment:

python3 -m venv venv

Activate environment:

Linux:

source venv/bin/activate

Install dependencies:

pip install -r requirements.txt

Run API:

uvicorn app.main:app --reload

API Endpoints

Test database connection

GET /db-test

Example response:

{
    "message": "Database connected successfully"
}

Get tasks

GET /tasks

Example response:

{
    "results": [
        [1, "Study Docker"],
        [2, "Learn PostgreSQL"]
    ]
}

Useful Commands

View logs:

docker logs api-container
docker logs postgres-container

Rebuild containers:

docker compose up --build

Stop containers:

docker compose down

Learning Goals

This project was created to practice:

  • Docker fundamentals
  • Docker Compose
  • FastAPI
  • PostgreSQL
  • Backend architecture basics
  • Container communication

About

Task management API built with FastAPI, PostgreSQL, Docker and Docker Compose for backend and containerization practice.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages