DailyDo is a FastAPI-based Todo application that allows users to create, retrieve, update, and delete tasks. It leverages SQLModel for database interactions and Pytest for testing, ensuring a structured and maintainable codebase.
- FastAPI – Web framework for building APIs
- SQLModel – ORM for database interactions
- PostgreSQL – Database for storing todo tasks
- Pytest – Testing framework
- TestClient – For API testing
project-root/
│── dailydo_todo_app/
│ ├── __init__.py
│ ├── main.py # Main FastAPI application, API routes, SQLModel, Database setup
│ ├── settings.py # Configuration settings
│── test.py # Pytest test cases
│ ├── __init__.py
│ ├── test_main.py # Test cases for API endpoints
│── .env # Environment variables
│── pyproject.toml # Poetry project configuration
│── README.md # Documentation
-
Clone the repository:
git clone https://github.com/yourusername/dailydo-todo-app.git cd dailydo-todo-app -
Install Poetry:
curl -sSL https://install.python-poetry.org | python3 - -
Install dependencies:
poetry install
-
Activate the virtual environment:
poetry shell
-
Set up environment variables: Create a
.envfile and configure it with your PostgreSQL credentials. -
Run the FastAPI application:
uvicorn dailydo_todo_app.main:app --reload
The database connection is established using SQLModel. Tables are created automatically when the app starts if they do not already exist.
- Engine Creation: Defined in
main.pyusingSQLModel.metadata.create_all(engine). - Session Management: Managed via
get_sessiondependency injection.
| Method | Endpoint | Description |
|---|---|---|
| GET | / |
Welcome message |
| GET | /todos |
Retrieve all todos |
| GET | /todos/{id} |
Retrieve a single todo |
| POST | /todos |
Create a new todo |
| PUT | /todos/{id} |
Update an existing todo |
| DELETE | /todos/{id} |
Delete a todo |
The project uses FastAPI's dependency injection to manage database sessions efficiently. In test.py, app.dependency_overrides replaces the real session with a test session, ensuring isolation between tests and production data.
Run all tests using:
pytest test.py- Fork the repository.
- Create a new branch for your feature.
- Commit your changes and push to GitHub.
- Open a pull request for review.
This project is licensed under the MIT License.