This is a starter backend project built with FastAPI following a clean and modular architecture.
It comes with ready-to-use Authentication (JWT), User module, database integration, and .env-based configuration β perfect as a foundation for larger projects.
.
βββ app
β βββ api/
β βββ core/
β β βββ config.py # Environment and settings configuration
β βββ db/
β β βββ database.py # Database connection (PostgreSQL or SQLite)
β βββ main.py # FastAPI entry point
β βββ modules/
β βββ auth/ # Authentication module
β β βββ dependencies.py
β β βββ routes.py
β β βββ schemas.py
β β βββ services.py
β βββ user/ # User module
β βββ models.py
β βββ routes.py
β βββ schemas.py
β βββ services.py
βββ database.db
βββ .env
βββ .env.example
βββ requirements.txt
βββ .ropeproject
β
Modular structure β auth and user separated cleanly
β
JWT authentication (login, register, protected routes)
β
Forgot/Reset password flow
β
CORS configuration via .env
β
PostgreSQL or SQLite support
β
Ready for /api/v1 route versioning
β
Auto-generated Swagger docs (/docs)
git clone https://github.com/your-username/fastapi-starter-backend.git
cd fastapi-starter-backendpython -m venv .venv
source .venv/bin/activate # Linux/Mac
# OR
.venv\Scripts\activate # Windowspip install -r requirements.txtCopy the .env.example to .env and update values:
cp .env.example .env.env example:
# App info
APP_TITLE=Modular FastAPI API
APP_DESCRIPTION=Backend API for Auth and User Modules
APP_VERSION=1.0.0
# Auth
SECRET_KEY=your_secret
ACCESS_TOKEN_EXPIRE_MINUTES=30
ALGORITHM=HS256
# Database
DATABASE_URL=postgresql+psycopg2://username:password@localhost:5432/your_db_name
# DATABASE_URL=sqlite:///database.db
# CORS
FRONTEND_URL=http://localhost:3000Use Python to generate a secure SECRET_KEY:
python -c "import secrets; print(secrets.token_hex(32))"Copy the output and paste it into .env as SECRET_KEY.
Make sure PostgreSQL is running (or use SQLite). Then create the database:
psql -U postgres -c "CREATE DATABASE your_db_name;"Or update .env to use SQLite for local development:
DATABASE_URL=sqlite:///./database.dbFrom the project root:
uvicorn app.main:app --reloadThe API will be available at:
- Swagger UI: http://127.0.0.1:8000/docs
- ReDoc: http://127.0.0.1:8000/redoc
| Endpoint | Method | Description |
|---|---|---|
/api/v1/auth/register |
POST | Register a new user |
/api/v1/auth/login |
POST | Login and get JWT token |
/api/v1/auth/forgot-password |
POST | Generate a password reset token |
/api/v1/auth/reset-password |
POST | Reset password using token |
Use the JWT token returned from login as a Bearer Token in protected routes like:
GET /api/v1/users/me
Authorization: Bearer <your_access_token>
- Add role-based access (Admin, User)
- Add email service integration for password reset
- Add unit tests and CI/CD
- Author : Ngusa
Contributions are welcome! If you'd like to improve this project, feel free to fork the repository, create a new branch, and submit a pull request.
Steps:
- Fork this repo
- Create your feature branch:
git checkout -b feature/your-feature - Commit your changes:
git commit -m 'Add some feature' - Push to the branch:
git push origin feature/your-feature - Open a pull request π
By contributing, you agree that your contributions will be licensed under the MIT License Β© 2025