This project is a simple forum web application where users can register, log in, create, edit, and view posts. It includes different roles for users, such as regular users and admins, with different levels of access and functionalities. Admins can approve users, grant admin rights, and manage posts and user data, while regular users can create and manage their own posts.
-
Backend:
-
Node.js (Express.js)
-
MySQL for database management
-
-
Frontend:
-
React for building the user interface
-
Bootstrap for styling
-
-
Authentication:
- JSON Web Tokens (JWT) for securing routes and user authentication
-
Deployment:
- ngrok for tunneling the backend to be publicly accessible during development
-
User Registration: Users can create a new account by providing a username, email, and password.
-
User Login: After registration, users can log in using their credentials.
-
Create Posts: Users can create new posts, including a title, body, and optional file link.
-
Edit Posts: Users can edit the posts they have created.
-
View Posts: Users can view posts created by other users.
-
Search Posts: Users can search for posts by title or body content.
-
User Management: Admins can approve new users, grant them admin rights, and manage their roles.
-
Export User Data: Admins can export user data to a CSV file.
-
Post Management: Admins can edit or delete any posts in the system.
The MySQL database consists of two main tables:
-
users: Stores user information including username, email, password (hashed using bcrypt), and role (user or admin).
-
posts: Stores posts, including the title, body, and associated user email. It also has a field indicating whether the post was created by an admin.
Node.js (version 14 or later)
MySQL (version 8 or later)
ngrok (optional, for tunneling)
Clone the repository:
git clone <repository-url>
cd <repository-directory>
Navigate to the backend directory and install dependencies:
cd backend
npm install
Set up the database:
-
Make sure you have MySQL running.
-
Import the init.sql script to create the necessary database and tables:
mysql -u <your-username> -p < init.sql
node src/app.js
cd frontend
npm install
REACT_APP_HOST=http://localhost:5000
npm start
.
├── backend/ # Backend application (Node.js, Express, MySQL)
│ ├── src/
│ │ ├── app.js # Main entry point for the backend
│ ├── init.sql # SQL script for setting up the database
│ └── ...
├── frontend/ # Frontend application (React)
│ ├── public/
│ ├── src/
│ │ ├── pages/ # All page components
│ │ ├── App.js # Main entry point for React application
│ │ └── ...
├── start.sh # Script to start both backend and frontend
└── ...
REACT_APP_HOST: The URL of the backend API.
The application uses JWT (JSON Web Token) for handling authentication. On login, the backend generates a token that the frontend stores in the browser's localStorage. This token is then used to authenticate the user on subsequent requests.