Skip to content

Latest commit

 

History

1 Commit

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

A2 Service: Data Persistence & Architecture Swap

This project demonstrates a clean architecture approach by swapping an ephemeral, in-memory data store for a persistent PostgreSQL database running in a Docker container.

The core achievement of this setup is that the application layer, routes, and business logic remain completely unchanged during the storage swap—proving the effectiveness of the repository pattern.


🛠️ Stack Components

  • Backend Framework: Python 3.11 with FastAPI & Uvicorn
  • Database: PostgreSQL 15 (Alpine Linux distribution)
  • Database Driver: psycopg2-binary
  • Orchestration: Docker & Docker Compose

📁 Environment Setup

  • .env

🏗️ The Architecture Payoff

By leveraging a strict repository interface pattern (UserRepository), our application interacts with data via a predefined contract (save and get_all).

When transitioning from the old InMemoryUserRepository to the new PostgresUserRepository, zero lines of code were altered inside our HTTP routes or domain logic. The database transition was completed entirely by switching one initialization line in main.py:

# ❌ OLD STORE:
# repo = InMemoryUserRepository()

#  NEW STORE:
DATABASE_URL = os.getenv("DATABASE_URL")
repo = PostgresUserRepository(DATABASE_URL)

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages