A production-style authentication and role-based access control system built using FastAPI, JWT, SQLAlchemy, and Alembic.
AccessControl API is a secure backend authentication system that implements:
- User registration
- Password hashing
- JWT authentication
- Protected routes
- Role-based access control (RBAC)
- Database migrations using Alembic
This project follows modular backend architecture and production-style authentication patterns.
- Register users
- Secure password hashing
- Fetch all users
- JWT token generation
- Secure login system
- Token verification
- Protected endpoints
- Admin-only routes
- Role validation
- Permission-based access control
- SQLite integration
- SQLAlchemy ORM
- Alembic migrations
- β‘ FastAPI
- π Python
- ποΈ SQLite
- π§ SQLAlchemy
- π Alembic
- π JWT Authentication
- π pwdlib Password Hashing
src/
βββ auth/
β βββ controllers.py
β βββ routers.py
β βββ schemas.py
β βββ utils.py
β
βββ user/
β βββ controllers.py
β βββ models.py
β βββ routers.py
β βββ schemas.py
β
βββ utils/
β βββ db.py
β βββ settings.py
β
βββ main.py
| Method | Endpoint | Description |
|---|---|---|
| POST | /users/ |
Register user |
| GET | /users/ |
Get all users |
| Method | Endpoint | Description |
|---|---|---|
| POST | /auth/login |
Login & receive JWT token |
| GET | /auth/me |
Get current authenticated user |
| GET | /auth/admin |
Admin-only protected route |
{
"access_token": "your.jwt.token",
"token_type": "bearer"
}User Login
β
Credentials Verification
β
JWT Token Generated
β
Client Stores Token
β
Protected Request with Bearer Token
β
Token Verification
β
Access Granted / Denied
This API supports role-based authorization.
useradmin
Admin-only endpoints are protected using dependency-based authorization.
git clone https://github.com/whoismehfooz/AccessControl-API.git
cd AccessControl-APIpython -m venv venv
source venv/bin/activatepip install -r requirements.txtalembic upgrade headuvicorn src.main:app --reloadOpen in browser:
http://127.0.0.1:8000/docs
- JWT Authentication
- Protected Routes
- Role-Based Access Control
- Dependency Injection
- Database Migrations
- Production-style FastAPI Structure
- Git Branching Workflow
- Refresh Tokens
- Email Verification
- Password Reset
- PostgreSQL Integration
- Docker Deployment
Building backend systems step-by-step with FastAPI π