A scalable RESTful API built with FastAPI and PostgreSQL. This project demonstrates backend architecture using standard CRUD operations, database migrations and strict data validation.
- Full CRUD Operations: Create, Read (All & By ID), Update and Delete tasks.
- Smart Updates: Implementation of
PATCHmethod for partial updates (specifically for toggling theis_completestatus). - Due Dates: Implementation of datetime sorting to prioritize tasks.
- Subtasks: Relational mapping to allow nested tasks (One-to-Many).
- Data Validation: Strict schema validation using Pydantic V2.
- Database Persistence: robust data storage using PostgreSQL.
- ORM Layer: Clean database interaction using SQLAlchemy.
- Migrations: Database schema version control using Alembic.
- Modular Architecture: Codebase organized into distinct layers (Routers, CRUD, Models, Schemas) for maintainability.
- Framework: FastAPI
- Database: PostgreSQL
- ORM: SQLAlchemy
- Migrations: Alembic
- Serialization/Validation: Pydantic
- Server: Uvicorn (ASGI)
This project follows a modular pattern to ensure scalability and separation of concerns:
├── alembic/ # Database migration scripts
├── crud/
│ └── todo_crud.py # Database interaction logic (Create, Read, Update, Delete)
├── database/
│ └── connections.py # Database session and connection setup
├── models/
│ └── todo_model.py # SQLAlchemy database models
├── schema/
│ └── todo_schema.py # Pydantic models for request/response validation
├── routers/
│ └── todo_router.py # API Endpoint definitions
├── main.py # Application entry point
├── .env # Environment variables (Database credentials)
└── alembic.ini # Alembic configuration
Follow these steps to set up the project locally.
- Python 3.10+
- PostgreSQL installed and running
git clone https://github.com/rhoda-lee/Todo-App.git
cd your-repo-namepython -m venv venv
# Windows
venv\Scripts\activate
# Mac/Linux
source venv/bin/activatepip install -r requirements.txtCreate a .env file in the root directory and add your PostgreSQL credentials:
DATABASE_URL=postgresql://username:password@localhost:5432/your_database_nameNote: Make sure to create the database in PostgreSQL before running migrations.
Use Alembic to create the tables in your database:
alembic upgrade headuvicorn main:app --reloadThe API will be available at http://127.0.0.1:8000.
FastAPI provides automatic, interactive documentation. Once the server is running, visit:
- Swagger UI: http://127.0.0.1:8000/docs
- ReDoc: http://127.0.0.1:8000/redoc
| Method | Endpoint | Description |
|---|---|---|
GET |
/todos/ |
Retrieve all todo items |
POST |
/todos/ |
Create a new todo item |
GET |
/todos/{id} |
Retrieve a specific item by ID |
PATCH |
/todos/{id} |
Update an item (e.g., mark as done) |
DELETE |
/todos/{id} |
Delete an item |
This project is currently in active development. Upcoming features include:
- Tagging System: Many-to-Many relationships for task categorization.
Rhoda Oduro-Nyarko
Built with ❤️ using Python and FastAPI.