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.
- 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_donestatus - Users support
is_activestatus - PostgreSQL database running in Docker
The application models a simple but secure user-note system:
User
βββ Notes
βββ Role (admin / user)
-
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
- Python
- FastAPI
- SQLAlchemy ORM
- Pydantic
- Alembic
- PostgreSQL
- Docker & Docker Compose
- JWT (python-jose)
- bcrypt (passlib)
- 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
- POST
/auth/registerβ Create new user (public) - POST
/auth/loginβ Obtain JWT token (public)
- GET
/users/meβ Get current user (authenticated) - PATCH
/users/meβ Update current user (authenticated)
- 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)
- GET
/admin/usersβ List all users (admin only) - GET
/admin/notesβ List all notes (admin only) - DELETE
/admin/users/{id}β Delete user (admin only)
git clone https://github.com/Adrode/fastapi_users_notes_api.git
cd users_notes_api- Create virtual environment
python -m venv env
source env/bin/activate
pip install -r requirements.txt- Start database
docker compose up -d- Run migrations
alembic upgrade head- Run server
uvicorn main:app --reloadAPI docs: http://127.0.0.1:8000/docs
- Clean separation between authentication and business logic
- Role-based access control implemented via dependencies
- Ownership validation on resource access
- PostgreSQL with Alembic migrations
- Backend API design with FastAPI
- JWT authentication & authorization
- Role-based access control
- Relational database modeling
- Secure CRUD API design