Skip to content

A secure and scalable Notes Management API built using FastAPI, MongoDB, and JWT Authentication. This project provides RESTful endpoints for user registration, authentication, and CRUD operations on notes — all containerized using Docker for easy deployment.

Notifications You must be signed in to change notification settings

sudhakarzox/my-notes-fastapi

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

FastAPI Notes API

A secure, production-ready Notes API built with FastAPI, MongoDB, and JWT authentication. This service lets users sign up, log in, and manage notes (create, read, update, delete).

Features

  • ✅ User Authentication — Secure signup & login with JWT tokens
  • ✅ Notes CRUD — Create, read, update, and delete notes
  • ✅ MongoDB Integration — Async database operations using Motor
  • ✅ Password Hashing — Uses bcrypt for secure password storage
  • ✅ Dockerized — Easily deployable anywhere
  • ✅ Swagger Docs — Interactive API documentation
  • ✅ Environment Configs — .env based settings for secrets & DB

Setup Instructions

Prerequisites

Python 3.10+

MongoDB (local or Atlas)

Docker (optional for containerized setup)

1. Clone the Repository

git clone https://github.com/<your-username>/fastapi-notes-api.git
cd fastapi-notes-api

2. Create and Activate Virtual Environment

python -m venv venv
source venv/bin/activate   # macOS/Linux
venv\Scripts\activate      # Windows

3. Install Dependencies

pip install -r requirements.txt

4. Create .env File

Copy the example file:

    cp .env.example .env

Edit .env:

# MongoDB Root Credentials
MONGO_ROOT_USERNAME=root
MONGO_ROOT_PASSWORD=your_secure_root_password_here

# MongoDB Initial Admin User
MONGO_INIT_ADMIN_USERNAME=admin
MONGO_INIT_ADMIN_EMAIL=admin@yourdomain.com
MONGO_INIT_ADMIN_PASSWORD=your_pre_hashed_password_here  # Make sure this is pre-hashed

# FastAPI Settings
SECRET_KEY=your_secure_jwt_key_here

5. Run the Application

uvicorn app.main:app --reload

The app should be live at:
👉 http://localhost:8000

API Endpoints Overview

Authentication

Method	Endpoint	Description

POST	/auth/signup	Register a new user
POST	/auth/login	Log in & receive JWT token

Notes

  • Method Endpoint Description
  • GET /notes/ Get all notes for the user
  • POST /notes/ Create a new note
  • PUT /notes/{note_id} Update a note
  • DELETE /notes/{note_id} Delete a note

All /notes routes require an Authorization header: Authorization: Bearer <your_access_token>

Docker Setup

Build and Start Containers

docker-compose up --build

This spins up:

  • FastAPI app on port 8000
  • MongoDB on port 27017

API Documentation

FastAPI automatically generates documentation:

Authentication Flow

  • User Signup → /auth/signup → Passwords are hashed with bcrypt before saving.

  • User Login → /auth/login → Returns a JWT token with expiration.

  • Authorized Routes → /notes/* → Require Authorization: Bearer header.

Tech Stack

  • Layer Technology
  • Backend FastAPI
  • Database MongoDB (Motor async driver)
  • Auth JWT
  • Containerization Docker & Docker Compose
  • Language Python 3.11

Future Enhancements

  • Role-based permissions (Admin/User)
  • Refresh tokens for longer sessions
  • File attachments for notes
  • Integration tests with Pytest
  • Rate limiting & CORS policies

Author

Sudhakar P
Software Engineer | Cybersecurity Enthusiast
Certificates: CEH, CND, AZ-305, SC-100, AZ-500
[p.sudhakar963@gmail.com]

About

A secure and scalable Notes Management API built using FastAPI, MongoDB, and JWT Authentication. This project provides RESTful endpoints for user registration, authentication, and CRUD operations on notes — all containerized using Docker for easy deployment.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published