Skip to content

A simple frontend-backend project that exposes a FastAPI REST API back-end and a Flutter frontend to showcase API integration, Pydantic Schemas, Alembic Migrations and SQLAlchemy ORM models.

License

Notifications You must be signed in to change notification settings

ex-rnd/FastAPI-Flutter-API-Integration-Using-Alembic-MySQL

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 

Repository files navigation

🎮 FastAPI Flutter API Integration

A simple frontend-backend project that exposes a FastAPI REST API back-end and a Flutter frontend to showcase API integration, Pydantic Schemas, Alembic Migrations and SQLAlchemy ORM models.

✳️ Visual Overview

FastAPI-Flutter-Final.mp4

📹 Demo

First, see it in action:

  1. Open a terminal and start the backend.
uvicorn app.main:app --reload --host 127.0.0.1 --port 8000
  1. In Postman, set the base_url to localhost:8000, the headers to Content-Type:application/json and send a POST /new with the body (below) to create a new fruit.
FastAPI-Flutter-Postman-Screenshot 2025-09-26 161419
{
  "name": "Strawberry",
  "seedless": true
}
  1. Run the Flutter app on an emulator or device.
  2. Switch to the List tab to fetch and view fruits.

🔍 Project Overview

Problem

  • Provide a reliable HTTP API for managing fruit records and a simple cross-platform UI for users to view and add fruits.

Key Components

  • FastAPI REST endpoints
  • SQLAlchemy ORM models
  • Alembic migration scripts
  • Pydantic schemas for input/output validation
  • Flutter UI with bottom navigation
  • Dart model mapping TINYINT seedless flag to bool
  • HTTP integration tested via Postman

🛠️ Getting Started

  1. Clone
git clone https://github.com/ex-rnd/FastAPI-Flutter-API-Integration-Using-Alembic-MySQL.git
cd fastapi-flutter-integration
  1. Backend setup
  • Create a Python virtual environment.
python3 -m venv venv
source venv/bin/activate   # macOS/Linux
venv\Scripts\activate      # Windows
pip install -r requirements.txt
  • Install requirements.
pip install -r requirements.txt
  • Create a .env with your MySQL URL.
DATABASE_URL=mysql+pymysql://user:pass@host:3306/dbname
  • Run alembic migrations.
alembic upgrade head
  1. Frontend setup
  • Navigate to the flutter folder.
cd frontend
  • Fetch Dart packages.
flutter pub get
  • Update lib/config.dart with your API base URL.
Flutter-URL-For-Local-Host-Screenshot 2025-09-26 163016

▶️ Usage

API Testing with Postman.

  • Open Postman.

  • Use the Environment to set base_url to http://127.0.0.1:8000.

  • Run requests and inspect responses.

  • Use GET, POST, PUT.

  • Automate tests by creating assertions on status codes and JSON schemas

Flutter Front-End.

  • Ensure your emulator or device is connected
  • From project root:
cd frontend
flutter run

🚀 API Reference

FastAPI-Flutter-API-Reference-Screenshot 2025-09-26 164721

📐 App Architecture

High level overview

Flutter App  ← HTTP (http package) →  FastAPI  
    ↑                                     │  
    │                                     ↓  
 ListView / Form             SQLAlchemy ORM → MySQL  
                             Alembic Migrations  

Low level overview

[Flutter UI] → http.get/post → [FastAPI App]
  ↓                          ↓
ListView / Form      Pydantic validation
                      ↓
                 SQLAlchemy models
                      ↓
                  MySQL database
               (migrations via Alembic)  

🤝 Contributing

  • Fork the repo
  • Branch naming: feature/xyz or fix/xyz
  • Run linters:
Backend: flake8, black
Frontend: flutter format
  • Add tests:
Backend unit tests with: pytest
Frontend widget tests with: flutter test
  • Submit PRs with clear descriptions and link related issues

🎮 Thank you for exploring FastAPI-Flutter integration 🎉!

About

A simple frontend-backend project that exposes a FastAPI REST API back-end and a Flutter frontend to showcase API integration, Pydantic Schemas, Alembic Migrations and SQLAlchemy ORM models.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published