A full-stack doctor appointment booking platform with three distinct user roles: Users, Doctors, and Admins. Built with modern web technologies for a seamless healthcare appointment management experience.
- User Registration & Authentication: Secure signup and login with JWT tokens
- Profile Completion Flow: New users must complete their profile (phone, gender, birthdate, address) before accessing protected routes
- Browse Doctors: View all available doctors or filter by speciality
- Book Appointments: Schedule appointments with preferred doctors
- Manage Appointments: View, confirm, or cancel appointments
- Profile Management: Update personal information and profile picture
- Doctor Dashboard: View all appointments assigned to the doctor
- Appointment Management: Mark appointments as Completed or Cancelled
- Patient Information: Access patient details for appointments
- Profile Management: Update doctor profile, speciality, fees, and availability
- Doctor Management: Add new doctors to the system
- View All Appointments: Monitor all appointments across the platform
- View All Doctors: Manage and view all registered doctors
- Dashboard Analytics: Overview of platform statistics
- React 18 - UI library
- Vite - Build tool and dev server
- React Router DOM - Client-side routing
- TailwindCSS - Utility-first CSS framework
- Axios - HTTP client
- JWT Decode - Token management
- Node.js - Runtime environment
- Express.js - Web framework
- MongoDB - NoSQL database
- Mongoose - MongoDB object modeling
- JWT - Authentication tokens
- Bcryptjs - Password hashing
- Multer - File upload handling
DoctorAppointment/
βββ client/ # React frontend application
β βββ src/
β β βββ Components/ # Reusable UI components
β β βββ context/ # React context providers
β β βββ pages/ # Page components
β β β βββ user/ # User-facing pages
β β β βββ doctor/ # Doctor dashboard pages
β β β βββ admin/ # Admin dashboard pages
β β βββ App.jsx # Main app component
β β βββ main.jsx # Entry point
β βββ package.json
β
βββ server/ # Express backend API
βββ controller/ # Route controllers
βββ models/ # MongoDB models
βββ routes/ # API routes
βββ middleware/ # Custom middleware
βββ db/ # Database connection
βββ error/ # Error handling
βββ public/ # Static files (images)
βββ populate.js # Database seeding script
βββ AddAdmin.js # Admin user creation script
βββ App.js # Server entry point
- Node.js v18+ (v25.1.0 tested)
- MongoDB instance (local or MongoDB Atlas)
- npm or yarn package manager
git clone <repository-url>
cd DoctorAppointment# Install server dependencies
cd server
npm install
# Install client dependencies
cd ../client
npm installCreate a .env file in the server/ directory:
# MongoDB Connection String
MONGO_URI=
# JWT Configuration
JWT_SECRET=your_super_secret_jwt_key_change_this_in_production
JWT_LIFETIME=30d
# Server Port (optional, defaults to 3000)
PORT=5000Run the populate script to add sample doctors:
cd server
node populate.jsThis will create 15 sample doctors with different specialities.
Create an admin user for testing:
cd server
node AddAdmin.jsOpen two terminal windows:
Terminal 1 - Start Backend Server:
cd server
npm run devThe server will run on http://localhost:5000 (or your configured PORT)
Terminal 2 - Start Frontend Client:
cd client
npm run devThe client will run on http://localhost:5173
Build the frontend for production:
cd client
npm run build
npm run preview- User Registration: Users sign up with name, email, and password
- Profile Completion: After registration, users are automatically logged in and redirected to complete their profile
- Login: Existing users log in and are redirected based on profile completion status
- Protected Routes: Routes are protected based on:
- Authentication status (valid JWT token)
- Profile completion status (for user routes)
Tokens are stored in localStorage:
userToken- For regular usersdoctorToken- For doctorsadminToken- For administrators
-
User Protected Routes: Require authentication AND complete profile
/my-profile/my-appoinments/appoinments/:docId
-
Doctor Protected Routes: Require doctor authentication
/doctor/*
-
Admin Routes: Require admin authentication
/admin/*
POST /api/auth/user/register- Register new userPOST /api/auth/user/login- User login (returnstokenandisProfileComplete)
GET /api/users/docters- Get all doctors (public)GET /api/users/doctors/:speciality- Get doctors by speciality (public)GET /api/users/doctor/:docId- Get doctor by ID (public)GET /api/users/getuser- Get current user profile (auth required)PATCH /api/users/profile- Update user profile (auth required)POST /api/users/bookappointments- Book appointment (auth required)GET /api/users/appointments/user- Get user appointments (auth required)PATCH /api/users/appointments/cancel- Cancel appointment (auth required)PATCH /api/users/appointments/confirm- Confirm appointment (auth required)
GET /api/doctors- Get doctor profileGET /api/doctors/appointments- Get doctor's appointmentsPATCH /api/doctors/profile- Update doctor profilePATCH /api/doctors/appointments/:appointmentId/status- Update appointment statusPOST /api/doctors/user- Get user profiles by IDs
GET /api/admin/all-doctors- Get all doctorsGET /api/admin/all-appointments- Get all appointmentsPOST /api/admin/add-doctor- Add new doctor (multipart form data)
{
name: String (required),
email: String (required, unique),
password: String (required, hashed),
role: String (enum: ["Admin", "NormalUser"]),
phone: String (optional),
gender: String (enum: ["Male", "Female", "Other"]),
birthdate: Date (optional),
address: {
line1: String,
line2: String
},
image: String,
appointments: [ObjectId]
}{
name: String (required),
email: String (required, unique),
password: String (required, hashed),
image: String,
speciality: String (required),
degree: String,
experience: Number,
about: String,
fees: Number (required),
phone: String,
address: Object,
availability: String,
createdBy: ObjectId
}{
doctor: ObjectId (required, ref: "Doctor"),
user: ObjectId (required, ref: "User"),
slotTime: Date (required),
status: String (enum: ["Pending", "Confirmed", "Completed", "Cancelled"]),
fees: Number (required),
userName: String,
doctorName: String,
userBithdate: Date,
speciality: String
}/- Home page/doctors- Browse all doctors/doctors/:speciality- Filter doctors by speciality/login- User login/signup- User registration/about- About page/contact- Contact page
/complete-profile- Profile completion form/my-profile- User profile management/my-appoinments- User appointments list/appoinments/:docId- Book appointment with specific doctor
/doctor/login- Doctor login/doctor- Doctor dashboard/doctor/appointment- Doctor appointments/doctor/doctorprofile- Doctor profile
/admin/login- Admin login/admin- Admin dashboard/admin/all-appointment- All appointments/admin/add-doctor- Add new doctor/admin/all-doctors- All doctors list
- JWT-based authentication
- Password hashing with bcryptjs
- Protected routes with middleware
- Profile completion validation
- CORS configuration
- Input validation
Permission Denied Error:
chmod +x server/node_modules/.bin/*MongoDB Connection Error:
- Verify
MONGO_URIin.envfile - Ensure MongoDB is running
- Check connection string format
Node.js Compatibility:
- Tested with Node.js v25.1.0
- If you encounter
buffer-equal-constant-timeerrors, reinstall dependencies:
cd server
rm -rf node_modules package-lock.json
npm installDependencies Not Found:
cd client
npm installPort Already in Use:
- Change PORT in server
.env - Update CORS origin in
server/App.jsif needed
- Profile completion is enforced for users accessing protected routes
- Doctors are seeded using
populate.jsscript - Image uploads are handled via Multer and stored in
server/public/ - All API responses follow a consistent format:
{ success: boolean, data: ... }
Doctor Appointment Booking System
Current Status: β Fully functional with profile completion flow, three-role authentication, and appointment management system.