Skip to content

whoismehfooz/AccessControl-API

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

3 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ” AccessControl API

A production-style authentication and role-based access control system built using FastAPI, JWT, SQLAlchemy, and Alembic.


πŸš€ Overview

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.


⚑ Features

πŸ‘€ User System

  • Register users
  • Secure password hashing
  • Fetch all users

πŸ” Authentication

  • JWT token generation
  • Secure login system
  • Token verification
  • Protected endpoints

πŸ‘‘ Authorization (RBAC)

  • Admin-only routes
  • Role validation
  • Permission-based access control

πŸ—„οΈ Database

  • SQLite integration
  • SQLAlchemy ORM
  • Alembic migrations

🧱 Tech Stack

  • ⚑ FastAPI
  • 🐍 Python
  • πŸ—„οΈ SQLite
  • 🧠 SQLAlchemy
  • πŸ”„ Alembic
  • πŸ” JWT Authentication
  • πŸ”’ pwdlib Password Hashing

πŸ“‚ Project Structure

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

πŸ”₯ API Endpoints

πŸ‘€ Users

Method Endpoint Description
POST /users/ Register user
GET /users/ Get all users

πŸ” Authentication

Method Endpoint Description
POST /auth/login Login & receive JWT token
GET /auth/me Get current authenticated user
GET /auth/admin Admin-only protected route

πŸ§ͺ Example Login Response

{
  "access_token": "your.jwt.token",
  "token_type": "bearer"
}

πŸ” Authentication Flow

User Login
    ↓
Credentials Verification
    ↓
JWT Token Generated
    ↓
Client Stores Token
    ↓
Protected Request with Bearer Token
    ↓
Token Verification
    ↓
Access Granted / Denied

πŸ‘‘ Role-Based Access Control

This API supports role-based authorization.

Example Roles

  • user
  • admin

Admin-only endpoints are protected using dependency-based authorization.


βš™οΈ Setup & Run

Clone Repository

git clone https://github.com/whoismehfooz/AccessControl-API.git
cd AccessControl-API

Create Virtual Environment

python -m venv venv
source venv/bin/activate

Install Dependencies

pip install -r requirements.txt

Run Migrations

alembic upgrade head

Start Server

uvicorn src.main:app --reload

πŸ“š Swagger Documentation

Open in browser:

http://127.0.0.1:8000/docs

🧠 What I Learned

  • JWT Authentication
  • Protected Routes
  • Role-Based Access Control
  • Dependency Injection
  • Database Migrations
  • Production-style FastAPI Structure
  • Git Branching Workflow

πŸš€ Future Improvements

  • Refresh Tokens
  • Email Verification
  • Password Reset
  • PostgreSQL Integration
  • Docker Deployment

πŸ‘¨β€πŸ’» Author

Building backend systems step-by-step with FastAPI πŸš€

About

πŸ‘‰ JWT authentication and role-based access control API built with FastAPI, SQLAlchemy, and Alembic.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors