Skip to content

hn8ix/fastapi-backend

Repository files navigation

Task Manager API

A REST API for managing tasks and categories, built with FastAPI and PostgreSQL.

Getting Started

To get a local copy up and running, follow these steps.

Prerequisites

  • Python 3.10 or higher
  • PostgreSQL 13 or higher
  • pip or another Python package manager

Installation

  1. Clone the repository
git clone https://github.com/h8nix/faspt_project.git
cd faspt_project
  1. Create and activate a virtual environment
python3 -m venv venv
source venv/bin/activate  # On Windows: venv\Scripts\activate
  1. Install dependencies
pip install -r requirements.txt
  1. Set up environment variables

Create a .env file in the root directory and configure your database URL:

DATABASE_URL=postgresql+asyncpg://user:password@localhost:5432/task_manager
  1. Create database tables
python3 -c "from faspt.app.db.session import engine; from faspt.app.models.base import Base; Base.metadata.create_all(bind=engine)"
  1. Start the application
uvicorn faspt.app.main:app --reload

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

Interactive API documentation can be accessed at http://localhost:8000/docs

Available Scripts

Development Server

uvicorn faspt.app.main:app --reload

Starts the development server with auto-reload enabled. Changes to the code will automatically reload the server.

Production Build

uvicorn faspt.app.main:app

Starts the server in production mode without auto-reload.

Project Structure

faspt/app/
├── main.py              FastAPI application entry point
├── core/
│   ├── config.py        Configuration management
│   └── exceptions.py    Domain-specific exceptions
├── api/                 HTTP routing layer
│   ├── categories.py
│   └── tasks.py
├── services/            Business logic layer
│   ├── category.py
│   └── task.py
├── repositories/        Data access layer
│   ├── interfaces.py
│   ├── category.py
│   └── task.py
├── models/              SQLAlchemy ORM models
│   ├── base.py
│   ├── category.py
│   └── task.py
├── schemas/             Pydantic validation schemas
│   ├── category.py
│   └── task.py
└── db/
    └── session.py       Database connection management

Architecture

This project demonstrates clean architecture principles with clear separation of concerns:

  • HTTP Layer (api/): Handles incoming requests and responses
  • Business Logic Layer (services/): Contains application logic independent of HTTP
  • Data Access Layer (repositories/): Manages database operations
  • Domain Models (models/): SQLAlchemy ORM definitions
  • Configuration (core/): Settings and error definitions

The services layer uses dependency injection to accept repository interfaces rather than concrete implementations. This makes the code testable and maintainable.

API Endpoints

Categories

POST   /categories/           Create a new category
GET    /categories/           Get all categories
GET    /categories/{id}       Get a category by ID
PATCH  /categories/{id}       Update a category
DELETE /categories/{id}       Delete a category

Tasks

POST   /tasks/                Create a new task
GET    /tasks/                Get all tasks
GET    /tasks/{id}            Get a task by ID
PATCH  /tasks/{id}            Update a task
DELETE /tasks/{id}            Delete a task

Configuration

Configuration is handled through environment variables defined in .env files.

Environment Files

  • .env.example - Template with all available configuration options
  • .env.development - Development configuration
  • .env.testing - Test environment configuration
  • .env.production.example - Production configuration template

Common Configuration Variables

Variable Description Example
ENVIRONMENT Deployment environment development, testing, production
DEBUG Enable debug mode true, false
DATABASE_URL PostgreSQL connection string postgresql+asyncpg://user:password@localhost:5432/db
SECRET_KEY Secret key for authentication your-secret-key
CORS_ALLOWED_ORIGINS Allowed CORS origins ["http://localhost:3000"]

Dependencies

  • fastapi 0.135.1 - Web framework
  • sqlalchemy 2.0.48 - ORM and database toolkit
  • asyncpg 0.31.0 - PostgreSQL async driver
  • pydantic 2.13.2 - Data validation
  • pydantic-settings 2.13.1 - Settings management
  • uvicorn 0.44.0 - ASGI server

See requirements.txt for the complete list.

Client Application (Frontend)

This REST API was specifically designed and developed to serve the Todo App frontend client.

The frontend application seamlessly integrates with these API endpoints, handling tasks and categories through the provided CORS configuration.

Roadmap

The following features are planned for future development:

  • Implement Alembic database migrations for version control
  • Add comprehensive test suite with Pytest and pytest-asyncio
  • Implement Docker containerization with Docker Compose
  • Deploy to production environments (Heroku, AWS)

Learn More

License

This project is licensed under the MIT License - see the LICENSE file for details.

Author

Credits

License

This project is licensed under the MIT License - see the LICENSE file for details.

About

Backend service for the Todo App. Features a clean layered architecture, async database operations, and FastAPI.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages