Skip to content

Repository files navigation

Hospital Backend API

A Node.js/Express backend API for a hospital management system. This API handles doctors, appointments, and user authentication. It uses MySQL for database storage and includes file upload capabilities.

Features

  • User Authentication: Secure JWT-based authentication.
  • Doctors Management: Endpoints to manage doctor profiles.
  • Patient Management: Endpoints for patients to register, login, and manage profiles.
  • Appointments: Schedule and manage patient appointments with role-based access.
  • Payments: Integrated Stripe and Razorpay checkout sessions with automated webhook verification.
  • File Uploads: Supports uploading files (e.g., doctor images).
  • Error Handling: Centralized error handling middleware.

Tech Stack

  • Node.js & Express.js for the server environment.
  • MySQL2 for database connection and queries.
  • JWT (jsonwebtoken) for authorization.
  • Bcryptjs for password hashing.
  • Multer for handling file uploads.
  • Jest & Supertest for unit and integration testing.

Folder Structure

src/
├── modules/
│   ├── appointment/          # Appointment logic
│   │   ├── appointment.controller.js
│   │   ├── appointment.model.js
│   │   ├── appointment.routes.js
│   │   └── __tests__/
│   ├── auth/                 # Authentication logic
│   │   ├── auth.controller.js
│   │   ├── auth.routes.js
│   │   └── __tests__/
│   ├── doctor/               # Doctor logic
│   │   ├── doctor.controller.js
│   │   ├── doctor.model.js
│   │   ├── doctor.routes.js
│   │   └── __tests__/
│   ├── patient/              # Patient logic
│   │   ├── patient.controller.js
│   │   ├── patient.model.js
│   │   ├── patient.routes.js
│   │   └── __tests__/
│   ├── payment/              # Payment logic
│   │   ├── payment.controller.js
│   │   ├── payment.routes.js
│   │   └── __tests__/
│   └── user/                 # Core User data
│       ├── user.model.js
│       └── __tests__/
├── config/
├── middleware/
├── utils/
└── app.js

Prerequisites

  • Node.js
  • MySQL Server

Installation

  1. Install dependencies:

    npm install
  2. Environment Variables: Check the .env file in the root directory to configure database and authentication variables (e.g., PORT, DB_HOST, DB_USER, DB_PASSWORD, DB_NAME, JWT_SECRET).

  3. Database Setup: Ensure your MySQL server is running and the database schema is created as per your configuration.

Running the Application

  • Development Mode: (uses nodemon to restart on changes)
    npm run dev
  • Production Mode:
    npm start

Testing

Run tests using Jest:

npm test
  • Watch mode: npm run test:watch
  • Coverage report: npm run test:coverage

API Endpoints (Overview)

  • Auth: /api/auth - Register and authenticate users.
  • Doctors: /api/doctors - Manage doctor records.
  • Patients: /api/patients - Manage patient records.
  • Appointments: /api/appointments - Book and manage appointments.
  • Payments: /api/payments - Stripe and Razorpay integrations and webhooks.
  • Health Check: / and /test-db - Verify server and database connectivity.
  • Static Uploads: /uploads - Access uploaded files.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages