https://github.com/spartan09/fastapi-tdd-todo-app
A full-featured Todo API built with FastAPI, featuring user authentication, role-based access control, and SQLite database integration.
https://github.com/spartan09/fastapi-tdd-todo-app
alembic fastapi jwt pydantic-v2 sqlalchemy sqlite3
Last synced: 2 months ago
JSON representation
A full-featured Todo API built with FastAPI, featuring user authentication, role-based access control, and SQLite database integration.
- Host: GitHub
- URL: https://github.com/spartan09/fastapi-tdd-todo-app
- Owner: Spartan09
- Created: 2025-02-22T11:27:03.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2025-02-22T12:02:02.000Z (over 1 year ago)
- Last Synced: 2025-02-22T12:27:15.672Z (over 1 year ago)
- Topics: alembic, fastapi, jwt, pydantic-v2, sqlalchemy, sqlite3
- Language: Python
- Homepage:
- Size: 0 Bytes
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# FastAPI Todo Application
A robust REST API for managing todos with user authentication and role-based access control, built using FastAPI and SQLAlchemy.
## Features
- User authentication with JWT tokens
- Role-based access control (Admin and Regular users)
- CRUD operations for todos
- User management with password hashing
- Database migrations using Alembic
- SQLite database integration
## Tech Stack
- FastAPI
- SQLAlchemy
- Alembic
- Pydantic
- PassLib
- Python-Jose
- SQLite
## Getting Started
### Prerequisites
- Python 3.7+
- pip
### Installation
1. Clone the repository
```bash
git clone https://github.com/yourusername/fastapi-todo-app.git
cd fastapi-todo-app
```
2. Create a virtual environment
```bash
python -m venv venv
source venv/bin/activate # On Windows use: venv\Scripts\activate
```
3. Install dependencies
```bash
pip install -r requirements.txt
```
4. Run database migrations
```bash
alembic upgrade head
```
5. Start the server
```bash
uvicorn todoapp.main:app --reload
```
The API will be available at `http://localhost:8000`
## API Documentation
Once the server is running, you can access:
- Interactive API documentation: `http://localhost:8000/docs`
- Alternative API documentation: `http://localhost:8000/redoc`
## API Endpoints
### Authentication
- `POST /auth/` - Create new user
- `POST /auth/token` - Login and get access token
### Todos
- `GET /` - Get all todos for authenticated user
- `GET /todo/{todo_id}` - Get specific todo
- `POST /todo` - Create new todo
- `PUT /todo/{todo_id}` - Update todo
- `DELETE /todo/{todo_id}` - Delete todo
### Users
- `GET /user/` - Get user information
- `PUT /user/password` - Change password
### Admin
- `GET /admin/todo` - Get all todos (admin only)
- `DELETE /admin/todo/{todo_id}` - Delete any todo (admin only)
## Database Schema
### Users Table
- id (Primary Key)
- email (Unique)
- username (Unique)
- first_name
- last_name
- hashed_password
- is_active
- role
- phone_number
### Todos Table
- id (Primary Key)
- title
- description
- priority
- complete
- owner_id (Foreign Key to Users)
## Security Features
- Password hashing using bcrypt
- JWT token authentication
- Role-based access control
- Token expiration
- Secure password validation