An open API service indexing awesome lists of open source software.

https://github.com/rahulsamant37/fastapi_clean-architecture

A production-ready Todo API built with FastAPI following clean architecture principles and best practices.
https://github.com/rahulsamant37/fastapi_clean-architecture

boilerplate-template continuous-integration docker docker-compose fastapi fastapi-crud fastapi-template help-others unittest

Last synced: 4 months ago
JSON representation

A production-ready Todo API built with FastAPI following clean architecture principles and best practices.

Awesome Lists containing this project

README

          

# FastAPI Clean Architecture Todo API

A production-ready Todo API built with FastAPI following clean architecture principles and best practices.

## ๐Ÿ—๏ธ Architecture

This project follows clean architecture principles, with clear separation of:

- **Entities** - Core business objects (`User`, `Todo`)
- **Use Cases** - Application business rules in services
- **Controllers** - HTTP request handlers
- **Infrastructure** - Database, authentication, and external interfaces

## ๐Ÿ”‘ Key Features

- Complete CRUD operations for Todos
- User authentication with JWT
- Password hashing with bcrypt
- Rate limiting
- PostgreSQL database with SQLAlchemy ORM
- Comprehensive test suite
- Docker support
- Clean code structure following best practices

## ๐Ÿš€ Getting Started

### Prerequisites

- Python 3.12+
- Docker and Docker Compose (optional)
- PostgreSQL (if running without Docker)

### Running with Docker

```bash
# Start the application and database
docker-compose up
```

The API will be available at `http://localhost:8000`

### Local Development Setup

```bash
# Create a virtual environment
python -m venv venv
source venv/bin/activate # Linux/macOS
venv\Scripts\activate # Windows

# Install dependencies
pip install -r requirements-dev.txt

# Configure environment variables
cp .env.example .env # Update with your values

# Run the application
uvicorn src.main:app --reload
```

## ๐Ÿ“ API Documentation

Once running, view the interactive API documentation at:

- Swagger UI: `http://localhost:8000/docs`
- ReDoc: `http://localhost:8000/redoc`

### Key Endpoints

- `POST /auth/` - Register new user
- `POST /auth/token` - Login and get access token
- `GET /todos/` - List all todos
- `POST /todos/` - Create new todo
- `GET /todos/{id}` - Get single todo
- `PUT /todos/{id}` - Update todo
- `DELETE /todos/{id}` - Delete todo
- `PUT /todos/{id}/complete` - Mark todo as complete

## ๐Ÿงช Testing

```bash
# Run all tests
pytest

# Run with coverage
pytest --cov=src
```

## ๐Ÿ› ๏ธ Project Structure

```
src/
โ”œโ”€โ”€ auth/ # Authentication logic
โ”œโ”€โ”€ database/ # Database configuration
โ”œโ”€โ”€ entities/ # Domain entities
โ”œโ”€โ”€ todos/ # Todo feature module
โ”œโ”€โ”€ users/ # User feature module
โ”œโ”€โ”€ exceptions.py # Custom exceptions
โ”œโ”€โ”€ logging.py # Logging configuration
โ””โ”€โ”€ main.py # Application entry point
```

## ๐Ÿ”’ Security Features

- JWT authentication
- Password hashing with bcrypt
- Rate limiting on registration endpoint
- CORS protection
- Input validation with Pydantic

## ๐Ÿค Contributing

1. Fork the repository
2. Create a new branch (`git checkout -b feature/amazing-feature`)
3. Commit your changes (`git commit -m 'Add amazing feature'`)
4. Push to the branch (`git push origin feature/amazing-feature`)
5. Open a Pull Request

## ๐Ÿ“„ License

This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.