Skip to content

MuhammadMasab002/appoint-a-doc

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

59 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Appoint-A-Doc: Doctor Appointment Booking System

Welcome to the official documentation for Appoint-A-Doc, a full-stack MERN web application. This document provides an in-depth look at the architecture, features, database design, API boundaries, and operational guidelines for the platform.


1. Introduction

Project Name: Appoint-A-Doc
Purpose: Appoint-A-Doc is a comprehensive digital healthcare platform designed to streamline the process of scheduling, tracking, and managing doctor appointments. It bridges the gap between healthcare providers and patients by offering an accessible, easy-to-use booking interface.

Problem Statement: Booking doctor appointments traditionally involves long phone calls, manual scheduling, and unexpected wait times. Clinics struggle to manage overlapping appointments, leading to administrative inefficiencies and patient frustration.

Proposed Solution: A centralized web application where patients can effortlessly discover specialists, view real-time availability, and book appointments. Concurrently, it empowers doctors to manage their schedules and allows administrators to oversee platform operations smoothly.

Target Users:

  • Patients: Individuals seeking medical consultation and booking appointments.
  • Doctors: Healthcare professionals managing their consultation hours and patient interactions.
  • Admin: System administrators responsible for platform oversight, user management, and analytics.

2. Features Overview

Patient Features

  • Registration & Login: Secure authentication using email and password.
  • Browse Doctors: View a directory of available medical professionals.
  • Filter/Search: Search for doctors by specialty, name, or availability.
  • Book Appointment: Select preferred dates and time slots for consultation.
  • View Appointment History: Keep track of upcoming and past appointments.
  • Cancel/Reschedule: Ability to modify bookings based on clinic policies.

Doctor Features

  • Profile Management: Update specialty, experience, fees, and bio.
  • Availability Management: Set working days, hours, and appointment slot durations.
  • Appointment Handling: View, accept, reject, or mark appointments as completed.
  • Patient Interaction: View patient consultation reasons and medical history context.

Admin Features

  • Dashboard Overview: High-level metrics showing total users, doctors, and appointments.
  • Manage Users: View and block/unblock patient accounts.
  • Manage Doctors: Approve/reject doctor registrations to enforce quality control.
  • Manage Appointments: Oversee system-wide bookings to resolve disputes.
  • Reports & Analytics: Track revenue (if applicable) and platform usage statistics.

3. Tech Stack

The application is built using the MERN stack. Here is the rationale behind each technology:

  • Frontend: React.js
    • Why: Component-based architecture allows for reusable UI elements. Virtual DOM ensures blazing fast rendering.
  • Backend: Node.js + Express.js
    • Why: Asynchronous, event-driven architecture handles concurrent API requests efficiently. Express simplifies REST API creation.
  • Database: MongoDB
    • Why: NoSQL document database schema provides flexibility for evolving data models like user profiles and appointment records.
  • Authentication: JSON Web Tokens (JWT) & Bcrypt.js
    • Why: Stateless authentication ensures scalability. Bcrypt securely hashes passwords before storage.
  • Styling: Tailwind CSS
    • Why: Utility-first CSS framework enables rapid UI development and ensures consistent, responsive design without leaving the HTML/JSX files.
  • State Management: Redux Toolkit (or React Context API)
    • Why: Provides centralized global state management for the user's authentication status, theme preferences, and cached fetched data.

4. System Architecture

High-Level Architecture

Appoint-A-Doc follows a standard Client-Server architecture based on the REST standard.

  1. Client (React): Renders the UI and sends HTTP requests via tools like Axios.
  2. Server (Express/Node): Intercepts requests, validates logic, and communicates with the database.
  3. Database (MongoDB): Stores all persistent data securely in the cloud (Atlas).

Client-Server Flow

  1. User interacts with the UI.
  2. React dispatches an API call (e.g., POST /api/appointments/book).
  3. The Express router intercepts the request and passes it to the Auth Middleware to verify the JWT.
  4. If authorized, the Controller executes business logic (e.g., checking if the slot is free).
  5. The Controller queries MongoDB via Mongoose.
  6. The response JSON is returned to the client to update the UI state.

5. Database Design

Collections Overview

The database uses normalized and embedded documents where appropriate.

1. Users Collection (Patients & Admins)

  • _id: ObjectId
  • name: String
  • email: String (Unique)
  • password: String (Hashed)
  • role: String (patient, admin)
  • createdAt: Date

2. Doctors Collection

  • _id: ObjectId
  • userId: ObjectId (Ref -> Users, optional depending on architecture)
  • name: String
  • email: String (Unique)
  • password: String (Hashed)
  • specialty: String
  • experience: Number
  • consultationFee: Number
  • availability: Array of Objects (Day, Start Time, End Time)
  • status: String (pending, approved, rejected)

3. Appointments Collection

  • _id: ObjectId
  • patientId: ObjectId (Ref -> Users)
  • doctorId: ObjectId (Ref -> Doctors)
  • date: Date
  • timeSlot: String
  • status: String (pending, confirmed, cancelled, completed)
  • reasonForVisit: String
  • createdAt: Date

6. API Documentation

Base URL: /api/v1

Auth APIs

  • POST /auth/register - Register a new user/patient.
  • POST /auth/login - Authenticate user & receive JWT token.
  • POST /auth/doctor-register - Apply for a doctor account.

Patient APIs (Requires User JWT)

  • GET /user/profile - Fetch patient profile.
  • GET /user/appointments - Get all appointments specific to the logged-in patient.
  • POST /user/appointments/book - Book a new appointment.
    • Request Body: { doctorId, date, timeSlot, reasonForVisit }
  • PUT /user/appointments/cancel/:id - Cancel an existing appointment.

Doctor APIs (Requires Doctor JWT)

  • GET /doctor/appointments - Get assigned appointments.
  • PUT /doctor/appointments/:id/status - Accept/reject appointments.
    • Request Body: { status: 'confirmed' | 'cancelled' }
  • PUT /doctor/profile - Update availability and fees.

Admin APIs (Requires Admin JWT)

  • GET /admin/doctors - Get list of all doctors (pending and approved).
  • PUT /admin/doctors/approve/:id - Approve a pending doctor.
  • GET /admin/users - Fetch all users in the system.

7. Frontend Structure

src/
├── assets/          # Static files (images, icons)
├── components/      # Reusable UI components (Navbar, Footer, Modal, Button)
├── context/         # React Context (or /store for Redux)
├── pages/           # Route level components
│   ├── Home/
│   ├── Login/
│   ├── Dashboard/   # Contains sub-views for roles
│   └── Booking/
├── services/        # API call handlers (Axios setups)
├── utils/           # Helper functions (date formatting, validators)
├── App.js           # Main app layout and routing (React Router)
└── index.js         # Entry point

Routing Strategy: React Router DOM is utilized. Routes are encapsulated by Higher Order Components (HOCs) like <ProtectedRoute> and <AdminRoute> to prevent unauthorized access.


8. Backend Structure

server/
├── config/          # Environment and DB setup (db.js)
├── controllers/     # Route logic separating HTTP req/res from DB operations
├── middlewares/     # Auth checks, Error Handling, Request Validators
├── models/          # Mongoose Schema definitions
├── routes/          # API endpoint declarations
├── utils/           # Helpers (JWT signers, Password hashers)
└── server.js        # Entry point for Express application

Architecture Pattern: MVC (Model-View-Controller) structure where the 'View' is handled externally by the React application. Controllers act as the glue between HTTP Routes and Database Models.


9. Authentication & Authorization

  • Flow:
    1. User submits credentials via the login form.
    2. Server verifies bcrypt password hash.
    3. Server signs a JSON Web Token (JWT) containing the user's id and role.
    4. Token is returned to the client and stored (typically in LocalStorage or HttpOnly cookies).
  • Authorization: For protected endpoints, the client attaches the JWT as a Bearer Token in the Authorization header. A backend authMiddleware intercepts requests, decodes the token, and attaches the user data to req.user. Role-based middleware enforces strict boundaries (e.g., isAdmin middleware blocks non-admins).

10. Key Functional Workflows

1. Booking an Appointment

  • Patient navigates to standard Doctor List via Frontend.
  • Applies filters (e.g., "Cardiologist").
  • Views doctor's profile and available slots generated by backend logic.
  • Submits booking form. Server validates if the slot is still available.
  • If valid, a new document is inserted in the Appointments collection with status pending.

2. Doctor Accepting/Rejecting

  • Doctor logs in and views their dashboard.
  • Fetches all appointments where doctorId matches their ID.
  • Clicks "Accept" on a pending appointment.
  • Endpoint PUT /doctor/appointments/:id/status is called, mutating status to confirmed.

3. Admin Managing Users

  • Admin logs in, accessing the secure /admin route.
  • Views the list of all newly registered doctors with pending status.
  • Clicks "Verify", mutating the doctor's status to approved, allowing the doctor to appear in patient searches.

11. UI/UX Overview

  • Design Approach: Minimalist and modern. Emphasis on clean whitespace, intuitive navigation, and clear calls-to-action (CTAs).
  • Responsiveness: Tailwind CSS enforces a mobile-first design, utilizing CSS grid and flexbox to adapt the layout for mobile, tablet, and desktop views.
  • Accessibility: Semantic HTML forms, contrast-compliant colors, and clear error state indicators ensure usability for all demographics.

12. Installation & Setup Guide

Prerequisites

  • Node.js (v16+ recommended)
  • MongoDB (Local instance or Atlas cluster URI)
  • Git

Installation Steps

  1. Clone the repository:

    git clone https://github.com/yourusername/appoint-a-doc.git
    cd appoint-a-doc
  2. Backend Setup:

    cd server
    npm install
    # Create a .env file and configure variables
    npm run dev
  3. Frontend Setup:

    cd client
    npm install
    # Create a .env file (for Vite/React env variables)
    npm start

    The application should now be running locally on http://localhost:3000 (Frontend) and http://localhost:5000 (Backend API).


13. Deployment Guide

  • Database: MongoDB Atlas (DBaaS). Set up a free cluster, whitelist IP 0.0.0.0/0, and grab the connection string.
  • Backend: Hosted on Render or Heroku.
    • Connect the GitHub repository.
    • Set the root directory to /server.
    • Add the Environment Variables to the deployer's dashboard.
  • Frontend: Hosted on Vercel or Netlify.
    • Connect the GitHub repository.
    • Set the root directory to /client.
    • Ensure the build command is npm run build.

14. Testing

  • Manual Testing: Exhaustive Role-Based manual testing utilizing Postman for APIs and direct browser interaction for frontend workflows. Testing scenarios include unauthorized access attempts, overlapping booking submissions, and incorrect password handling.
  • Unit/Integration Testing: (If implemented) Jest and Supertest could be used to write tests for backend endpoints to verify successful DB insertions and correct status code emissions. React frontend can be tested using React Testing Library.

15. Security Considerations

  • Password Hashing: Passwords are never stored in plain text. Bcrypt.js hashes all user credentials.
  • JWT Security: Tokens rely on strong signing secrets.
  • Input Validation: Backend validation (e.g., using express-validator or Joi) rejects malicious payloads to prevent NoSQL injection.
  • API Protection: CORS configured strictly. Cross-Site Scripting (XSS) mitigated through React's native data escaping.

16. Performance Optimization

  • Database Indexing: Created indexes on frequently searched fields like doctor's specialty and appointment dates to decrease read latency.
  • Lazy Loading (Frontend): React Suspense and React.lazy() defer the loading of heavy dashboard components until required.
  • API Optimization: Pagination is implemented on doctors-list and appointment-history APIs to limit data over-fetching.

17. Future Improvements

  • Stripe/Razorpay Integration: Allow patients to pay consultation fees online during the booking phase.
  • Video Consultation: Integrate WebRTC or Zoom API for seamless remote online appointments.
  • Email/SMS Notifications: Notify users automatically of booking confirmations or cancellations via SendGrid or Twilio.
  • Mobile Application: Bridge the frontend into a React Native mobile app for iOS/Android accessibility.

18. Challenges & Solutions

  • Challenge: Preventing overlapping appointments (Double Booking).
    • Solution: Configured the backend controller to aggressively query the database for the exact doctorId, date, and timeSlot prior to confirming an insertion. Put database constraints where essentially needed using transactional logic.
  • Challenge: Complex State Management across three disparate roles (Admin, Doctor, Patient).
    • Solution: Employed global state management (Redux) decoupled into feature slices matching the user roles, preventing UI bleeding and simplifying route protection.

Conclusion

Appoint-A-Doc effectively demonstrates a powerful, end-to-end MERN stack solution. It provides substantial utility for both patients needing straightforward booking workflows and medical professionals desiring administrative relief. The modular architecture, clear API design, and robust security protocols make this a scalable and production-ready application suitable for modern clinical needs.

About

MERN Stack Doctor Appointment Booking App using React JS, MongoDB, Express and Node JS | Compete Full Stack React JS project

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors