This is a production-ready REST API project built with FastAPI and SQLite, following industry-standard structure. The API supports:
- JWT-based Authentication
- Password Hashing (bcrypt)
- CRUD Operations on Items
- SQLite as lightweight backend DB
api_project/ β βββ app/ β βββ main.py # Entry Point β βββ models.py # SQLAlchemy Models β βββ schemas.py # Pydantic Schemas β βββ database.py # Database Connection β βββ crud.py # DB Operations β βββ auth.py # Authentication Helpers β βββ routers/ β β βββ user.py # User Routes (Register/Login) β β βββ item.py # Item CRUD Routes β βββ core/ β βββ security.py # JWT + Password Hashing β βββ requirements.txt βββ .env # Secret Config (Optional) βββ .gitignore βββ README.md
# 1οΈβ£ Clone the repository
git clone https://github.com/AKJilani/FastAPI_SQLite.git
cd FastAPI_SQLite
# 2οΈβ£ Create virtual environment
python -m venv venv
source venv/bin/activate # For Linux/Mac
# venv\Scripts\activate # For Windows
# 3οΈβ£ Install dependencies
pip install -r requirements.txt
# 4οΈβ£ Run the server
uvicorn app.main:app --reload
π Authentication Flow
POST /api/users/register : Create User
POST /api/users/login : Obtain JWT Token (Bearer)
Use the token in Authorization headers:
makefile
Copy
Edit
Authorization: Bearer your_token_here
π API Endpoints
Endpoint Method Description
/api/users/register POST Register User
/api/users/login POST Login & get JWT
/api/items/ POST Create Item
/api/items/ GET Get All Items
/api/items/{id} GET Get Item by ID
/api/items/{id} PUT Update Item by ID
/api/items/{id} DELETE Delete Item by ID
Swagger Docs available at:
π http://127.0.0.1:8000/docs
π¦ Production Deployment
Use uvicorn with gunicorn or hypercorn
Store sensitive config in .env file
Use a reverse proxy (Nginx, Caddy)
Serve React frontend separately or as static files
π License
This project is open source and free to use under the MIT License.