Skip to content

cyber-evangelists/User-Registration-Backend-Task

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

NADRA-User-Registration 🪪

This project demonstrates a FastAPI application using Beanie ODM (Object Document Mapper) for MongoDB. The project is containerized using Docker and Docker Compose for easy setup and deployment. Its also deployed on Docker-Hub 🐳🙂

Project Demonstration 📹

Product Reviews API

FlowChart of Microservices:

Screenshot 2024-06-30 at 5 42 59 PM

Project Structure 🧱

Screenshot 2024-06-30 at 5 00 35 PM
  • protos/user.proto: Defines the overall structure of the app schema and functionalities in a universal syntax. Its the very first step when working with grpcs. After defining the user.proto file, run the command (given in user.proto file) in the terminal to generate compiler constructed user_pb2.py and user_pb2_grpc.py files.
  • routes/auth_handler.py: Defines the encoding and decoding of JWT Tokens.
  • routes/auth_bearer.py: Defines the JWT_Bearer Class and verifies JWT Tokens.
  • routes/app.py: Contains the API end points, JWT Authentication, and proper API Validations for handling User APIS.
  • server/models.py: Defines the User and UserModel and UserUpdateModel models using Beanie and Pydantic.
  • app/server/db.py: Contains the database initialization logic.
  • server/app.py: Contains the gRPC calls, DB initiallization on startup, and User Data storage in DB from the endpoints.
  • main.py: The entry point for running the Uvicorn server.
  • Dockerfile: The Dockerfile for building the routes/server images.
  • docker-compose.yml: Docker Compose file for setting up the FastAPI and MongoDB services.
  • requirements.txt: Python dependencies required for the project.

Note: Most of the files are redundant and not defined explicitly above e.g. routes/models.py is not defined above as same file with same code is present in the server/models.py

Features Loaded ⚙️

  1. User Registration CRUD Operations: • Create new user registration. • Read user information. • Update user information. • Delete user registration.

  2. JWT Authentication:

  • Implemented secure JWT authentication for user login and access control.
  1. Database Integration:
  • Used Beanie (MongoDB ODM) to store and manage user information.
  1. Dockerization:
  1. Swagger Documentation:
  • Provided comprehensive Swagger documentation for the API.
  1. PEP8 Standards of code:
  • Followed PEP8 Standards of Python syntax

Major Tasks Performed: 🛠️

  1. Setup FastAPI Project:
  • Initialized a new FastAPI project.
  • Configured the project structure for microservices.
  1. User Registration CRUD Endpoints:
  • Implemented endpoints for creating, reading, updating, and deleting user registrations.
  • Ensured validation and error handling.
  1. JWT Authentication:
  • Implemented JWT authentication for secure access.
  • Created login and token generation endpoints.
  • Secured CRUD endpoints using JWT authentication.
  1. Database Configuration:
  • Setup MongoDB connection.
  • Created pydantic models and schemas for user information.
  • Integrated MongoDB with FastAPI for data operations.
  1. Dockerization:
  • Created Dockerfile for the FastAPI application.
  • Setup Docker Compose for multi-container setup (including MongoDB).
  1. Swagger Documentation:
  • Added Swagger documentation for all the endpoints.
  • Ensured all routes, models, and authentication are properly documented.
  1. Code Structure:
  • Ensured modularity while coding.
  • Followed PEP8 standards of coding throughout the project.

Getting Started 🏃

Prerequisites 📋

  • Docker Desktop installed and up and running on your machine.

Installation 🛠️

  1. Clone the repository:

    git clone https://github.com/cyber-evangelists/NADRA-User-Registration-Backend-Task/new/main?filename=README.md
    cd project-dir
  2. Build and start the Docker containers:

    docker-compose up --build
  3. The FastAPI application will be available at http://localhost:8000.

API Endpoints ⚡

Screenshot 2024-06-30 at 5 29 10 PM Screenshot 2024-06-30 at 5 31 39 PM Screenshot 2024-06-30 at 5 32 14 PM Screenshot 2024-06-30 at 5 32 40 PM Screenshot 2024-06-30 at 5 33 06 PM Screenshot 2024-06-30 at 5 50 27 PM

Model Schemas 🧩

Screenshot 2024-06-30 at 5 26 26 PM

Notes 📒

  • Ensure MongoDB is running and accessible for the FastAPI application to function correctly.
  • The mongo_url in server/db.py is set to connect to a MongoDB instance at host.docker.internal.

This project was made with 💖 by Saad Abdur Razzaq under the supervision of Sir Husnain

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 3

  •  
  •  
  •