A production-ready asynchronous REST API built with FastAPI, featuring secure user authentication and advanced notes management. The application uses modern patterns like native SQLAlchemy 2.0 Async, Pydantic 2 settings, and is fully containerized.
- π Asynchronous API - Built with FastAPI 0.135.3 and async/await patterns
- π Secure Authentication - JWT-based OAuth2 Password Grant flow
- π PostgreSQL Database - Native SQLAlchemy 2.0 Async with asyncpg
- π¦ Database Migrations - Managed by Alembic
- π Search & Filter - Support for text search, completion status, and tags
- π·οΈ Tags Support - Organize notes with flexible tagging
- ποΈ Soft Deletes - Recoverable data management
- π³ Docker Support - Fully containerized backend and frontend
- π§ͺ Testing - Comprehensive test suite with pytest and mock dependencies
- π¨ Vue 3 Frontend - Modern frontend with Vite and Pinia state management
- Quick Start with Docker
- Local Installation
- Vue Frontend
- API Endpoints
- Testing
- Project Structure
- Troubleshooting
The fastest way to get started is using Docker Compose:
- Docker (20.10+)
- Docker Compose (v2.0+)
-
Clone the repository
git clone https://github.com/KenMwaura1/Fast-Api-example.git cd Fast-Api-example -
Start the application
docker-compose up -d --build
-
Access the Application
- Frontend: http://localhost:5173
- API Docs (Swagger): http://localhost:8002/docs
- API Backend: http://localhost:8002
- Python 3.13+
- PostgreSQL 14+
- Node.js 18+
-
Clone the repository
git clone https://github.com/KenMwaura1/Fast-Api-example.git cd Fast-Api-example -
Backend Setup
python3 -m venv venv source venv/bin/activate cd src pip install -r requirements.txt
If you prefer to build the backend image directly (the Dockerfile lives in src), run from the repository root:
# build using the `src` folder as the build context
docker build -f src/Dockerfile -t fast-api-example:local src
# run the built image
docker run --rm -p 8000:8000 --env-file src/.env fast-api-example:localThis docker build command sets the build context to src so the COPY requirements.txt in the Dockerfile resolves correctly.
-
Database Configuration Configure your DATABASE_URL in
src/.env(copy fromsrc/app/.env-example):DATABASE_URL=postgresql+asyncpg://user:password@localhost/dbname SECRET_KEY=your-secret-key
-
Run Migrations
cd src alembic upgrade head -
Run the Application
./run.sh
A modern Vue 3 frontend built with Vite and Pinia is included.
-
Navigate to frontend directory
cd vue-client npm install -
Start development server
npm run dev
-
Access the frontend at http://localhost:5173
| Method | Endpoint | Description |
|---|---|---|
| POST | /auth/register |
Register a new user |
| POST | /auth/token |
Login to get access token |
| Method | Endpoint | Description |
|---|---|---|
| GET | /notes/ |
List notes (owned by user) |
| POST | /notes/ |
Create a note |
| GET | /notes/{id} |
Get specific note |
| PUT | /notes/{id} |
Update note |
| DELETE | /notes/{id} |
Soft delete note |
The project includes a comprehensive test suite using pytest with mocked database dependencies.
# From the project root
export PYTHONPATH=$PYTHONPATH:$(pwd)/src
pytest src -vFast-Api-example/
βββ src/
β βββ app/
β β βββ api/ # API routes & logic
β β β βββ auth.py # Auth endpoints
β β β βββ notes.py # Notes endpoints
β β β βββ crud.py # DB operations
β β β βββ models.py # Pydantic models
β β βββ config.py # Pydantic Settings
β β βββ db.py # SQLAlchemy Setup
β β βββ main.py # FastAPI Entry
β βββ migrations/ # Alembic migrations
β βββ tests/ # Test suite
βββ vue-client/ # Vue 3 frontend
βββ docker-compose.yml # Docker orchestration
If you see "relation 'notes' already exists", ensure you have run alembic upgrade head rather than relying on create_all.
If the backend can't connect to the DB in Docker, verify the DATABASE_URL uses db as the hostname: postgresql+asyncpg://user:pass@db/dbname.
Ensure VITE_API_URL in vue-client/.env.development points to the correct backend port (8002 for Docker, 8000 for local).
This project is licensed under the MIT License.
Kennedy Mwaura
- Twitter: @Ken_Mwaura1
- GitHub: @KenMwaura1
Built with β€οΈ using FastAPI and Vue.js

