Skip to content

TodoApp is a FastAPI-based todo management system with JWT authentication, full-text search, and Redis caching. Built for scalability and performance, it uses MySQL for data storage and provides a user-friendly API for managing todos and users.

Notifications You must be signed in to change notification settings

ikaushikpal/TodoApp

Repository files navigation

TodoApp - FastAPI Setup Instructions

1. Clone the Repository

git clone https://github.com/ikaushikpal/TodoApp.git
cd TodoApp

2. Create a Virtual Environment

python -m venv .venv
source .venv/bin/activate # On macOS/Linux

OR

.venv\Scripts\activate # On Windows

3. Install Dependencies

pip install -r requirements.txt

4. Configure Environment Variables

Rename example.env to .env:

mv example.env .env

Update the .env file with your actual values:

# Database Configuration
HOST=localhost
PORT=3306
USER=root
PASSWORD=your_database_password
DATABASE=todo_app_python

# JWT Configuration
JWT_SECRET_KEY=supersecretkey123
JWT_ALGORITHM=HS256
JWT_EXPIRATION=3600

# Redis Configuration
REDIS_URL=redis://localhost:6379/0

Rename example.alembic.ini to alembic.ini:

mv example.alembic.ini alembic.ini

Update the sqlalchemy.url in alembic.ini with your MySQL connection URL:

sqlalchemy.url = mysql+pymysql://username:password@localhost/todo_app_python

5. Initialize Alembic (Database Migrations)

Generate a migration:

alembic revision --autogenerate -m "Initial migration"

Apply the migration:

alembic upgrade head

6. Add Full-Text Search Indexes

Run the following MySQL queries to enable full-text search on the users and todos tables:

Full-Text Index for users Table:

ALTER TABLE users ADD FULLTEXT(id, username, email, first_name, last_name, country_code, phone_number);

Full-Text Index for todos Table:

CREATE FULLTEXT INDEX todos_title_IDX ON todo_app_python.todos (title, description);

7. Run the FastAPI Server

Start the FastAPI server in reload mode (automatically reloads on code changes):

uvicorn main:app --reload

Have configured logs using python logger. So if don't want to UNICORN info logs, then use the following command.

uvicorn main:app --host 0.0.0.0 --port 8000 --log-level error --reload

for production deployment use bellow command

gunicorn -w 4 -k uvicorn.workers.UvicornWorker --keep-alive 5 main:app

8. Access API Docs

Summary of Changes

  • Environment Configuration:
    • Renamed example.env to .env and updated it with your actual values.
    • Renamed example.alembic.ini to alembic.ini and updated the sqlalchemy.url.
  • Database Setup:
    • Applied Alembic migrations to initialize the database schema.
    • Added full-text search indexes for the users and todos tables.
  • Running the Application:
    • Started the FastAPI server in reload mode for local development.

About

TodoApp is a FastAPI-based todo management system with JWT authentication, full-text search, and Redis caching. Built for scalability and performance, it uses MySQL for data storage and provides a user-friendly API for managing todos and users.

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published