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 🐳🙂


- 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 constructeduser_pb2.py
anduser_pb2_grpc.py
files. - routes/auth_handler.py: Defines the
encoding
anddecoding
ofJWT Tokens
. - routes/auth_bearer.py: Defines the
JWT_Bearer
Class and verifiesJWT Tokens
. - routes/app.py: Contains the
API end points
,JWT Authentication
, and properAPI Validations
for handling User APIS. - server/models.py: Defines the
User
andUserModel
andUserUpdateModel
models usingBeanie
andPydantic
. - app/server/db.py: Contains the
database initialization logic
. - server/app.py: Contains the
gRPC calls
,DB initiallization on startup
, andUser 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 theFastAPI
andMongoDB 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
-
User Registration CRUD Operations: • Create new user registration. • Read user information. • Update user information. • Delete user registration.
-
JWT Authentication:
- Implemented secure JWT authentication for user login and access control.
- Database Integration:
- Used Beanie (MongoDB ODM) to store and manage user information.
- Dockerization:
- Containerized the application using Docker for easy deployment and scalability. Its also deployed on Docker-Hub 🐳🙂
- Swagger Documentation:
- Provided comprehensive Swagger documentation for the API.
- PEP8 Standards of code:
- Followed PEP8 Standards of Python syntax
- Setup FastAPI Project:
- Initialized a new FastAPI project.
- Configured the project structure for microservices.
- User Registration CRUD Endpoints:
- Implemented endpoints for creating, reading, updating, and deleting user registrations.
- Ensured validation and error handling.
- JWT Authentication:
- Implemented JWT authentication for secure access.
- Created login and token generation endpoints.
- Secured CRUD endpoints using JWT authentication.
- Database Configuration:
- Setup MongoDB connection.
- Created pydantic models and schemas for user information.
- Integrated MongoDB with FastAPI for data operations.
- Dockerization:
- Created Dockerfile for the FastAPI application.
- Setup Docker Compose for multi-container setup (including MongoDB).
- Swagger Documentation:
- Added Swagger documentation for all the endpoints.
- Ensured all routes, models, and authentication are properly documented.
- Code Structure:
- Ensured modularity while coding.
- Followed PEP8 standards of coding throughout the project.
Docker Desktop
installed and up and running on your machine.
-
Clone the repository:
git clone https://github.com/cyber-evangelists/NADRA-User-Registration-Backend-Task/new/main?filename=README.md cd project-dir
-
Build and start the Docker containers:
docker-compose up --build
-
The FastAPI application will be available at
http://localhost:8000
.







- 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