# Hospital Management System (HMS) - Specification Document

## 1. Project Overview
- **Project Name**: Hospital Management System
- **Type**: Full-stack MERN Web Application
- **Core Functionality**: A comprehensive hospital management system with authentication, patient management, doctor management, appointments, and reports
- **Target Users**: Hospital administrators, doctors, and staff

## 2. Technology Stack

### Backend
- **Runtime**: Node.js
- **Framework**: Express.js
- **Database**: MongoDB with Mongoose ODM
- **Authentication**: JWT (JSON Web Tokens)
- **Password Hashing**: bcryptjs

### Frontend
- **Framework**: React.js with Vite
- **Routing**: React Router v6
- **HTTP Client**: Axios
- **State Management**: React Context API
- **UI Components**: Custom CSS with modern design

## 3. UI/UX Specification

### Color Palette
- **Primary**: #0066cc (Medical Blue)
- **Secondary**: #00a3cc (Light Blue)
- **Accent**: #00cc66 (Success Green)
- **Warning**: #ff9900 (Orange)
- **Danger**: #cc3300 (Red)
- **Background**: #f5f7fa (Light Gray)
- **Card Background**: #ffffff (White)
- **Text Primary**: #333333
- **Text Secondary**: #666666

### Typography
- **Font Family**: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif
- **Headings**: Bold, 24px-32px
- **Body**: Regular, 14px-16px

### Layout
- **Login Page**: Centered card with form
- **Dashboard**: Sidebar navigation + main content area
- **Cards**: White background, subtle shadow, rounded corners

### Responsive Breakpoints
- Desktop: > 1024px
- Tablet: 768px - 1024px
- Mobile: < 768px

## 4. Functionality Specification

### Authentication
- **Login**: Email and password authentication
- **Logout**: Clear token and redirect to login
- **Protected Routes**: All dashboard routes require authentication
- **Token Storage**: LocalStorage

### Dashboard
- Overview statistics (Total Patients, Doctors, Appointments)
- Quick action buttons
- Recent activity display

### Patient Management
- Add new patient
- View patient list
- Edit patient details
- Delete patient
- Search patients

### Doctor Management
- Add new doctor
- View doctor list
- Edit doctor details
- Delete doctor
- Search doctors

### Appointment Management
- Create new appointment
- View appointment list
- Update appointment status
- Cancel appointment
- Filter by status/date

### Reports
- Patient reports (total patients, new patients this month)
- Doctor reports (total doctors, specialty distribution)
- Appointment reports (total appointments, completed vs pending)
- Date-wise filtering
- Visual representation with statistics

## 5. API Endpoints

### Auth Routes
- POST /api/auth/login - User login
- POST /api/auth/register - User registration
- GET /api/auth/me - Get current user

### Patient Routes
- GET /api/patients - Get all patients
- POST /api/patients - Create patient
- PUT /api/patients/:id - Update patient
- DELETE /api/patients/:id - Delete patient

### Doctor Routes
- GET /api/doctors - Get all doctors
- POST /api/doctors - Create doctor
- PUT /api/doctors/:id - Update doctor
- DELETE /api/doctors/:id - Delete doctor

### Appointment Routes
- GET /api/appointments - Get all appointments
- POST /api/appointments - Create appointment
- PUT /api/appointments/:id - Update appointment
- DELETE /api/appointments/:id - Delete appointment

### Report Routes
- GET /api/reports/overview - Get dashboard overview
- GET /api/reports/patients - Get patient reports
- GET /api/reports/doctors - Get doctor reports
- GET /api/reports/appointments - Get appointment reports

## 6. Database Models

### User
```
javascript
{
  name: String,
  email: String (unique),
  password: String,
  role: String (enum: 'admin', 'doctor', 'staff'),
  createdAt: Date
}
```

### Patient
```
javascript
{
  name: String,
  age: Number,
  gender: String,
  phone: String,
  email: String,
  address: String,
  medicalHistory: String,
  createdAt: Date
}
```

### Doctor
```
javascript
{
  name: String,
  specialty: String,
  experience: Number,
  phone: String,
  email: String,
  qualification: String,
  createdAt: Date
}
```

### Appointment
```
javascript
{
  patient: ObjectId (ref: Patient),
  doctor: ObjectId (ref: Doctor),
  date: Date,
  time: String,
  status: String (enum: 'scheduled', 'completed', 'cancelled'),
  notes: String,
  createdAt: Date
}
```

## 7. Project Structure
```
HMS/
├── backend/
│   ├── config/
│   │   └── db.js
│   ├── middleware/
│   │   └── auth.js
│   ├── models/
│   │   ├── User.js
│   │   ├── Patient.js
│   │   ├── Doctor.js
│   │   └── Appointment.js
│   ├── routes/
│   │   ├── auth.js
│   │   ├── patients.js
│   │   ├── doctors.js
│   │   ├── appointments.js
│   │   └── reports.js
│   ├── .env
│   ├── server.js
│   └── package.json
├── frontend/
│   ├── public/
│   ├── src/
│   │   ├── components/
│   │   ├── context/
│   │   ├── pages/
│   │   ├── services/
│   │   ├── App.jsx
│   │   ├── main.jsx
│   │   └── index.css
│   ├── index.html
│   └── package.json
└── README.md
```

## 8. Acceptance Criteria

### Authentication
- [ ] User can login with email and password
- [ ] Invalid credentials show error message
- [ ] Successful login redirects to dashboard
- [ ] Logout clears session and redirects to login

### Dashboard
- [ ] Shows total counts of patients, doctors, appointments
- [ ] Displays recent appointments
- [ ] Shows quick action buttons

### Patient Management
- [ ] Can add new patient with all details
- [ ] Can view list of all patients
- [ ] Can edit patient information
- [ ] Can delete patient with confirmation

### Doctor Management
- [ ] Can add new doctor with all details
- [ ] Can view list of all doctors
- [ ] Can edit doctor information
- [ ] Can delete doctor with confirmation

### Appointments
- [ ] Can create new appointment
- [ ] Can view all appointments
- [ ] Can update appointment status
- [ ] Can cancel/delete appointment

### Reports
- [ ] Can view patient statistics
- [ ] Can view doctor statistics
- [ ] Can view appointment statistics
- [ ] Can filter by date range

### General
- [ ] No console errors
- [ ] Responsive design works on all devices
- [ ] All forms have validation
- [ ] Loading states displayed appropriately
