You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A complete full-stack web application built with the PERN stack (PostgreSQL, Express.js, React.js, Node.js) that allows users to rate and review stores. The application features a robust role-based authentication system for Normal Users, Store Owners, and System Administrators.
✨ Features
Role-Based Access Control:
Normal Users: Can register, log in, browse/filter stores, submit/update ratings, and manage their profile.
Store Owners: Have a dedicated dashboard to view their store's average rating and see a list of all ratings submitted.
System Administrators: Can manage all users and stores, view site-wide statistics, and assign store owners.
RESTful API: A secure and scalable backend built with Express.js.
Modern Frontend: A responsive and interactive UI built with React, Vite, and Tailwind CSS.
Data Persistence: All data is stored in a PostgreSQL database.
🧠 Key Concepts & Architecture
This project was built using modern best practices for scalable and maintainable full-stack applications.
Full-Stack Separation: The application is split into a backend RESTful API and a frontend Single-Page Application (SPA). This separation allows for independent development and scaling.
JWT for Stateless Authentication: User authentication is handled using JSON Web Tokens (JWT). On login, the server issues a signed token which is then sent with every protected request, making the system stateless and secure.
Role-Based Access Control (RBAC): Backend middleware checks the user's role (encoded in the JWT) to ensure that only authorized users can access protected endpoints (e.g., admin-only pages).
Password Hashing with bcrypt: User passwords are never stored in plain text. They are securely hashed using the bcrypt algorithm before being saved to the database.
Client-Side State Management (React Context): A global AuthContext provides authentication status and user data throughout the application, avoiding the need for "prop drilling".
Efficient Data Fetching (TanStack Query): The frontend uses TanStack (React) Query to manage all API data fetching, which handles caching, loading states, error states, and automatic data refetching.
🛠️ Setup and Installation
Prerequisites
Node.js (v18 or higher)
PostgreSQL
A code editor like VS Code
A terminal (WSL is recommended on Windows)
Backend Setup
Navigate to the backend directory:
cd backend
Create a .env file. You can copy .env.example if it exists, or create it from scratch with your PostgreSQL connection details and a JWT_SECRET.
Install dependencies:
npm install
Set up your PostgreSQL database, user, and tables as described in the project documentation.
Run the development server:
npm run dev
The backend will be running on http://localhost:5000.
Frontend Setup
Navigate to the frontend directory:
cd frontend
Create a .env file with the following content:
VITE_API_URL=http://localhost:5000/api
Install dependencies:
npm install
Run the development client:
npm run dev
The frontend will be running on http://localhost:5173.
📄 API Documentation
Auth Routes
Endpoint
Description
Access
POST /api/auth/register
Registers a new 'user'.
Public
POST /api/auth/login
Logs in a user and returns a JWT.
Public
PUT /api/auth/password
Updates the logged-in user's password.
Authenticated
User Routes
Endpoint
Description
Access
GET /api/users
Gets a list of all users. Supports filtering.
Admin
GET /api/users/:id
Gets details for a single user.
Admin
PUT /api/users/:id
Updates a user's details and role.
Admin
Store Routes
Endpoint
Description
Access
GET /api/stores
Gets a list of all stores. Supports filtering.
Authenticated
POST /api/stores
Creates a new store.
Admin
GET /api/stores/:id
Gets details and ratings for a single store.
Authenticated
Rating & Dashboard Routes
Endpoint
Description
Access
POST /api/ratings
Submits or updates a rating for a store.
User
GET /api/ratings/my-store
Gets dashboard data for a store owner.
Store Owner
GET /api/dashboard/admin
Gets statistics for the admin dashboard.
Admin
🔑 How to Create Test Accounts
Normal User: Use the /register page on the website to create a normal user account.
Admin User:
First, register a new user via the website (e.g., admin@example.com).
Then, connect to your PostgreSQL database and run the following SQL command to promote them:
UPDATE users SET role ='admin'WHERE email ='admin@example.com';
About
A complete full-stack web application built with the PERN stack (PostgreSQL, Express.js, React.js, Node.js) that allows users to rate and review stores. The application features a robust role-based authentication system for Normal Users, Store Owners, and System Administrators.