Skip to content

Adrode/users_and_notes_api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

61 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ“ Users & Notes API

Users & Notes API is a backend REST API for managing users and notes. It is built with FastAPI and demonstrates authentication, role-based authorization, and relational database modeling.

The project focuses on implementing secure user management, ownership-based access control, and admin-level permissions.

πŸš€ Key Features

  • JWT-based authentication (login/register)
  • Password hashing using bcrypt
  • Role-based access control (admin / user)
  • Users can manage only their own notes
  • Admin panel for managing all users and notes
  • Notes support is_done status
  • Users support is_active status
  • PostgreSQL database running in Docker

🧠 Domain Model Overview

The application models a simple but secure user-note system:

User
β”œβ”€β”€ Notes
└── Role (admin / user)

Core relationships

  • User β†’ Notes

    • Each user can create multiple notes
    • Notes are owned and accessible only by their creator
  • Role-based access

    • Admin users can access and manage all users and notes
    • Regular users are restricted to their own data

🧱 Tech Stack

  • Python
  • FastAPI
  • SQLAlchemy ORM
  • Pydantic
  • Alembic
  • PostgreSQL
  • Docker & Docker Compose
  • JWT (python-jose)
  • bcrypt (passlib)

πŸ” Authentication & Authorization

  • JWT tokens used for authentication
  • Passwords are hashed using bcrypt
  • Dependency injection protects endpoints
  • Role-based access control (admin / user)
  • Ownership checks prevent unauthorized access to notes

πŸ“‘ API Overview

Auth

  • POST /auth/register β€” Create new user (public)
  • POST /auth/login β€” Obtain JWT token (public)

Users

  • GET /users/me β€” Get current user (authenticated)
  • PATCH /users/me β€” Update current user (authenticated)

Notes

  • POST /notes/ β€” Create note (authenticated)
  • GET /notes/ β€” Get user notes (authenticated)
  • GET /notes/{id} β€” Get note by id (ownership required)
  • PATCH /notes/{id} β€” Update note (ownership required)
  • DELETE /notes/{id} β€” Delete note (ownership required)

Admin

  • GET /admin/users β€” List all users (admin only)
  • GET /admin/notes β€” List all notes (admin only)
  • DELETE /admin/users/{id} β€” Delete user (admin only)

βš™οΈ Setup & Run

1. Clone repository

git clone https://github.com/Adrode/fastapi_users_notes_api.git
cd users_notes_api
  1. Create virtual environment
python -m venv env
source env/bin/activate
pip install -r requirements.txt
  1. Start database
docker compose up -d
  1. Run migrations
alembic upgrade head
  1. Run server
uvicorn main:app --reload

API docs: http://127.0.0.1:8000/docs

🧩 Architecture Notes

  • Clean separation between authentication and business logic
  • Role-based access control implemented via dependencies
  • Ownership validation on resource access
  • PostgreSQL with Alembic migrations

🧠 What This Project Demonstrates

  • Backend API design with FastAPI
  • JWT authentication & authorization
  • Role-based access control
  • Relational database modeling
  • Secure CRUD API design

About

πŸ“ Users & Notes API is a REST API project for managing users and notes. Uses FastAPI, integrates PostgreSQL, presents role-based access and JWT authentication. First portfolio project :D.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors