Professional Documents
Culture Documents
Project Documentation
Project Documentation
Github link:
https://github.com/zuhebahmed88091/Assignment.git
Frontend
In this section, I will provide an in-depth description of the frontend codebase for our React
application.
- Functionality:
- Manages the authentication state using the `isAuthenticated` state variable, ensuring
proper access control throughout the application.
- Components Used:
- Renders child components such as `Login`, `Signup`, and `Home` based on the
defined routes.
- Props:
- Functionality:
- Checks the authentication status to determine whether the user is logged in.
- Props:
- Functionality:
- Initiates a POST request to the backend for user authentication, ensuring secure
communication.
- Navigates users to the home page upon successful login, enabling seamless transition
within the application.
- Dependencies:
- Utilizes the Axios library for making asynchronous HTTP requests to the backend API.
- Leverages the `useNavigate` hook from React Router for programmatic navigation.
- Props:
- Functionality:
- Presents a well-designed form for users to input their name, email, and desired
password.
- Dispatches a POST request to the backend for user registration, securely transmitting
user data.
- Guides users back to the login page after successful registration, streamlining the user
journey.
- Dependencies:
- Relies on React Router's `useNavigate` hook for navigation within the application.
- Props:
- None.
- Functionality:
- Implements comprehensive validation rules for email, password, and name fields to
ensure data integrity.
- Provides immediate feedback to users by returning error messages for invalid inputs.
- Enhances user experience by identifying and addressing input errors, fostering usability
and trust.
- Dependencies:
- None.
- Functionality:
- Renders the `App` component within the root HTML element, kickstarting the
application.
- Configures strict mode to detect and address potential issues during development,
enhancing code quality and stability.
- **Dependencies:**
Backend
In this section, I'll provide detailed documentation for the backend codebase of our
application.
Server.js:
1. Server Setup:
- Description: The `server.js` file initializes the backend server using Express.js, defining
routes and handling incoming requests.
- Functionality:
- Implements middleware for parsing JSON data and enabling CORS (Cross-Origin
Resource Sharing).
- Dependencies:
- Requires the Express.js framework for building the server.
2. Database Connection:
- Description: The backend establishes a connection to the MySQL database to perform
CRUD operations on user data.
- Functionality:
- Uses the MySQL package to create a connection pool with the MySQL database.
- Provides database credentials such as host, user, password, and database name.
- Dependencies:
- Relies on the MySQL package for interacting with the MySQL database.
- Functionality:
- Accepts POST requests containing user registration data (name, email, password).
- Inserts the user data into the MySQL database after validation.
- Responds with success or error messages based on the outcome of the registration
process.
- Dependencies:
- Dependencies:
5. Environment Configuration:
- Functionality:
- Defines environment variables for database host, user, password, and database name.
- Ensures sensitive information such as database credentials are not hard-coded into the
codebase.
- Dependencies:
- None.
Frontend DockerFile
FROM node:18.17.1
I selected the Node.js version 18.17.1 as the base image for my Docker container. This
specific version of Node.js will ensure compatibility with my frontend application.
WORKDIR /usr/src/app
I set the working directory within the container to `/usr/src/app`. This directory will serve
as the base directory for all subsequent commands in the Dockerfile.
COPY . /usr/src/app
I copied all the remaining files and directories from the root directory of my local
machine into the `/usr/src/app` directory inside the container. This includes all the
frontend application code and any other files necessary for its execution.
EXPOSE 3000
I specified that the container will listen on port 3000. Although this instruction doesn't
actually publish the port, it informs Docker that this port will be used by my frontend
application.
FROM node:20-alpine
I chose to start my Dockerfile with a base image that provides Node.js version 20 running
on Alpine Linux. Alpine is a lightweight distribution, which helps keep my container small
and efficient.
WORKDIR /usr/src/app
I set the working directory within the container to `/usr/src/app`. This is where I'll be
copying my application files and where subsequent commands will be executed.
EXPOSE 8801
I specified that my container will listen on port 8801. Although this instruction doesn't
actually publish the port, it informs Docker that this port will be used by my application.
CMD ["npm", "start"]
Finally, I set the default command to run when the container starts. It executes `npm
start`, assuming that the `start` script is defined in the `scripts` section of my
`package.json` file. This command will kickstart my Node.js application inside the
container, allowing it to be accessed externally on port 8801.
version: "3.8"
This indicates the version of Docker Compose file syntax I'm using.
services:
Here, I define the services that will run as part of my Docker Compose setup.
frontend:
build:
context: .
dockerfile: ./Frontend/frontend/Dockerfile
For the `frontend` service, I specify how to build it using the Dockerfile located at
`./Frontend/frontend/Dockerfile`. The `context: .` tells Docker to use the current
directory as the build context.
volumes:
- ./Frontend/frontend/:/usr/src/app
- /usr/src/app/node_modules/
I mount two volumes into the container: one for the local frontend directory mapped to
`/usr/src/app` inside the container, and another for the `node_modules` directory to
avoid overwriting it with the local `node_modules`.
ports:
- "3000:3000"
This line exposes port 3000 on the host and forwards it to port 3000 inside the container,
making the frontend accessible.
depends_on:
- backend
I specify that the `frontend` service depends on the `backend` service. Docker Compose
will ensure that the `backend` service is started before the `frontend` service.
backend:
build:
context: .
dockerfile: ./Backend/Dockerfile
Similar to the frontend service, I define the configuration for the `backend` service and
specify how to build it using its Dockerfile located at `./Backend/Dockerfile`.
ports:
- "8801:8801"
This line exposes port 8801 on the host and forwards it to port 8801 inside the container,
enabling access to the backend service.
depends_on:
- database
I specify that the `backend` service depends on the `database` service. Docker Compose
will ensure that the `database` service is started before the `backend` service.
environment:
- DB_HOST=database
- DB_USER=root
- DB_PASSWORD=zuheb101625
- DB_NAME=signup
These lines set environment variables for the `backend` service, configuring the database
connection details.
database:
image: mariadb:10.4.32
For the `database` service, I specify to use the `mariadb:10.4.32` Docker image from
Docker Hub.
ports:
- "3306:3306"
This line exposes port 3306 on the host and forwards it to port 3306 inside the container,
allowing access to the MariaDB database.
environment:
MYSQL_ROOT_PASSWORD: zuheb101625
MYSQL_DATABASE: signup
These lines set environment variables for configuring the MariaDB root password and the
database name.
volumes:
- ./data:/var/lib/mysql
This line mounts a volume named `data` into the container for persistent storage of the
database.
volumes:
data:
Finally, I define a volume named `data` which is used by the `database` service for
persistent storage.
Docker Run(Linux):
2. Install Git:
sudo apt install git
- Install Git, a version control system, which is required for cloning the project repository.
git --version
- Check the version of Git to verify that it's installed correctly.
6. Clone Repository:
mkdir Assignment
cd Assignment/
git clone https://github.com/zuhebahmed88091/Assignment.git
- Create a directory named `Assignment`, navigate into it, and clone the repository
containing the project files.
cd Assignment
- Enter the cloned project directory.
docker --version
- Verify the Docker installation by checking its version.
9. Remove Conflicting Docker Packages:
docker --version
- Check the installed Docker version to confirm successful installation.
sudo docker ps
- List all running Docker containers to ensure they are up and healthy.
18. Access MySQL Container:
mysql -u root -p
- Log into MySQL server with the root user and prompts for password as per backend
configuration(zuheb101625)
20. Create Database and Table:
- After entering my name, email, and password to sign up, redirected to the login page.
Upon successful login with credentials, gain access to the application's features.
22. View Container Logs:
- Follow the installation wizard instructions, leaving the default settings unchanged.
git –version
- On the Configuration page of the installation wizard, ensure that the "Use WSL 2 instead
of Hyper-V" option is selected or deselected based on the preference for the backend.
- Follow the instructions on the installation wizard, authorizing the installer if prompted,
and proceed with the installation.
- Sign out and sign back in for the changes to take effect.
4. Clone Repository:
- Open Command Prompt or Git Bash.
cd path\to\desired\directory
- Clone the repository using Git:
cd Assignment
docker-compose up -d --build
- Use the following command to enter the MySQL container's bash shell:
mysql -u root -p
- Log into MySQL server with the root user and prompts for password as per backend
configuration(zuheb101625)
- After entering my name, email, and password to sign up, redirected to the login page.
Upon successful login with credentials, gain access to the application's features.
11. View Container Logs:
- Open Command Prompt or PowerShell.
docker-compose down
- Use this command for closing the container
Conclusion:
In this comprehensive documentation, I've provided detailed insights into both the
frontend and backend components of our application, along with instructions for setting
up the development environment using Docker on both Linux and Windows operating
systems.
For the frontend, I elaborated on the key components such as `App`, `Home`, `Login`,
and `Signup`, highlighting their functionalities and dependencies. Additionally, I outlined
the form validation logic and the entry point for the React application.
Moving on to the backend, I described the essential aspects of the `server.js` file,
including server setup, database connection, and endpoints for user registration and login.
I also emphasized the importance of environment configuration for secure database
connections.
Furthermore, I provided Dockerfiles for both frontend and backend, detailing the Docker
build process and container setup. Additionally, I explained the Docker Compose file
configuration for orchestrating multiple services, such as frontend, backend, and
database, within a single environment.
Lastly, I presented step-by-step instructions for running the application using Docker on
Linux and Windows systems, covering everything from installing dependencies to
accessing the frontend interface and viewing container logs.