CRUD Application (MERN Stack) πLive Link
This is a CRUD (Create, Read, Update, Delete) application built using the MERN stack (MongoDB, Express.js, React.js, Node.js). It allows users to perform basic operations on user data, including creating new users, viewing user details, updating user information, and deleting users. This project also leverages Docker for containerization, making it easier to deploy and manage the application. The application is deployed on Vercel (Frontend) and Render (Backend).
- Create User: Add a new user with name, email, and password.
- Read User: View details of all users or a specific user.
- Update User: Modify existing user information.
- Delete User: Remove a user from the database.
- Responsive UI: The application is designed with a user-friendly interface using React and styled with Tailwind CSS.
- Backend API: Built with Node.js and Express.js, providing secure and efficient communication between the frontend and the MongoDB database.
- CORS Configuration: Allows frontend hosted on Vercel to communicate securely with the backend hosted on Render.
- React.js: A JavaScript library for building user interfaces.
- Tailwind CSS: A utility-first CSS framework for creating responsive, flexible layouts.
- Axios: A promise-based HTTP client for making API requests.
- Node.js: A JavaScript runtime for building server-side applications.
- Express.js: A minimalist web framework for Node.js, used to build the RESTful API.
- MongoDB: A NoSQL database for storing user data.
- Mongoose: An Object Data Modeling (ODM) library for MongoDB and Node.js.
- Bcrypt.js: A library to hash passwords for secure storage.
- Docker: Containerizes both the frontend and backend services for easy deployment and management.
- MongoDB Atlas: Cloud-hosted MongoDB for seamless and secure database management.
- Render: Backend deployment platform.
- Vercel: Frontend deployment platform.
- Postman: For testing and interacting with backend API endpoints.
- Node.js installed
- MongoDB (either locally or via MongoDB Atlas)
- Docker (Optional, for containerization)
git clone /~https://github.com/Varunyadavgithub/CRUD-app.git
cd CRUD-app
-
Navigate to the
backend
directory and install dependencies:cd backend npm install
-
Create a
.env
file inside thebackend
directory and add the following environment variables:DB_URI=your_mongo_database_uri PORT=3000 FRONTEND_URL=your_frontend_url
-
Start the backend server:
npm start
-
Navigate to the
frontend
directory and install dependencies:cd frontend npm install
-
Start the frontend development server:
npm start
This will start the frontend server on http://localhost:5173
.
-
Ensure the
docker-compose.yml
file is located at the root of the project. -
To build and run the Docker containers for both frontend, backend, and MongoDB services:
docker-compose up --build
-
The application will be accessible at
http://localhost:5173
after the containers are built and running.
- GET /api/v1/user/getusers: Get a list of all users.
- GET /api/v1/user/getuser/:id: Get a specific user by ID.
- POST /api/v1/user/create: Create a new user.
- PUT /api/v1/user/update/:id: Update an existing user by ID.
- DELETE /api/v1/user/delete/:id: Delete a user by ID.
- POST /api/v1/user/create:
{ "name": "John Doe", "email": "johndoe@example.com", "password": "password123" }
crud-app/
βββ backend/ # Backend application code
β βββ controllers/ # Controllers for handling API logic
β β βββ user.controller.js # Controller for user-related API actions
β βββ models/ # Database models (Mongoose models)
β β βββ user.model.js # User schema/model for MongoDB
β βββ routes/ # API route definitions
β β βββ user.route.js # Routes for handling user requests
β βββ utils/ # Utility functions
β β βββ connect_db.js # Function to connect to MongoDB
β β βββ error.js # Error handling utility
β βββ .env # Environment variables (e.g., database URI, secret keys)
β βββ .gitignore # Git ignore file to exclude sensitive files
β βββ Dockerfile # Dockerfile for building backend image
β βββ package-lock.json # Lock file for backend dependencies
β βββ package.json # Backend dependencies and scripts
β βββ server.js # Main entry point for the backend (server setup)
βββ frontend/ # Frontend application code
β βββ public/ # Public folder for static assets
β βββ src/ # Source code for React application
β β βββ assets/ # Static assets like images, fonts, etc.
β β βββ components/ # Reusable React components
β β β βββ Home.js # Home page component
β β β βββ ReadUser.js # Component to display user data
β β β βββ Spinner.js # Spinner/loading component
β β β βββ UpdateUser.js # Component to update user data
β β βββ App.js # Main React app component
β β βββ index.css # Global CSS styles for the React app
β β βββ main.jsx # React entry point (index.js in Vite)
β βββ .env # Environment variables for the frontend
β βββ .eslintrc.cjs # ESLint configuration file
β βββ .gitignore # Git ignore file for frontend
β βββ Dockerfile # Dockerfile for building frontend image
β βββ index.html # Main HTML file for the React app
β βββ package-lock.json # Lock file for frontend dependencies
β βββ package.json # Frontend dependencies and scripts
β βββ postcss.config.js # PostCSS configuration (if using PostCSS)
β βββ tailwind.config.js # Tailwind CSS configuration
β βββ vite.config.js # Configuration for Vite (Frontend build tool)
βββ docker-compose.yml # Docker Compose configuration for multi-container setup
βββ README.md # Project documentation
The project uses Docker Compose to simplify the setup and deployment of the app's frontend, backend, and MongoDB database services.
- docker-compose.yml: A configuration file that defines the frontend, backend, and MongoDB services, and how they interact with each other.
- Frontend: The frontend will run on
http://localhost:5173
. - Backend: The backend server will run on
http://localhost:3000
.
Both services can be run concurrently on different terminals or within Docker containers using Docker Compose.
-
Build and run containers:
docker-compose up --build
-
Stop the containers:
docker-compose down
For any questions or feedback, please contact:
- Name: Varun Yadav
- Email: yadav.varun056038@gmail.com
- LinkedIn: LinkedIn Profile
- GitHub: GitHub Profile
Happy Learning π±
Happy Coding π