
# 📌 Backend – MERN Stack Project

This is the **backend API** for the MERN stack application.
It is built using **Node.js**, **Express.js**, and **MongoDB (Mongoose)**, and provides RESTful APIs for authentication, user management, and application features.

---

## 🚀 Features

* User authentication (Keycloak-based login/register)
* Role-based access control
* CRUD APIs for core resources
* MongoDB integration with Mongoose
* Error handling & logging
* Environment-based configuration

---

## 🛠️ Tech Stack

* **Node.js** – JavaScript runtime
* **Express.js** – Web framework
* **MongoDB** – NoSQL database
* **Keycloak** – Authentication
* **CryptoJS** – Data hashing
* **dotenv** – Environment variables

---

## 📂 Project Structure

```
caredom-backend/

│── assets/                   # Static assets (images, templates, etc.)
│── config/                   # App & environment configuration files
│── database/                 # Database connection & migration scripts
│── helpers/                  # Utility/helper functions
│── keycloak/                 # Keycloak authentication integration
│── middlewares/              # Express middlewares (auth, validation, etc.)
│── modules/                  # Feature-based modular structure
│   ├── absence/              # Absence management module
│   │   ├── services/         # Service layer for business logic
│   │   │   ├── absenceExcel.js
│   │   │   ├── absencePdf.js
│   │   │   ├── addHolidayRequest.js
│   │   │   ├── getAbsenceReport.js
│   │   │   ├── getApprovedList.js
│   │   │   ├── getAttendanceDetailsList.js
│   │   │   ├── getHolidayReports.js
│   │   │   ├── getHolidayRequestByEmpId.js
│   │   │   ├── getHolidayRequestById.js
│   │   │   ├── getHolidayRequests.js
│   │   │   ├── holidayExcel.js
│   │   │   ├── holidayPdf.js
│   │   │   ├── updateHolidayRequest.js
│   │   ├── absence.controller.js   # Controller layer
│   │   ├── absence.repository.js   # Database repository layer
│   │   ├── absence.routes.js       # API routes
│   │   ├── index.js
│   │
│   ├── access/              # Access control module
│   ├── admin/               # Admin features
│   └── ... (other modules)
│
│── node_modules/            # Installed dependencies
│── postman/                 # Postman API collection(s)
│── temp/                    # Temporary files
│── utils/                   # Utility functions
│── .env                     # Environment variables
│── .eslintrc.js             # ESLint configuration
│── .gitignore               # Git ignore file
│── bucket.js                # Storage bucket integration
│── changeExpiredStatus.js   # Cron/script for updating expired status
│── index.js                 # Main entry point
│── package.json             # NPM dependencies & scripts
│── package-lock.json        # Dependency lock file
│── README.md                # Project documentation
│── routes.js                # Global route handling

```

---

## ⚙️ Installation & Setup

1. Clone the repository

   ```bash
   git clone https://github.com/your-username/your-repo.git
   cd backend
   ```

2. Install dependencies

   ```bash
   npm install
   ```

3. Setup environment variables in `.env` file

   # Server
   PORT==********
   SECRET_KEY=your-secret-key

   # Database
   MONGODB_URL=mongodb+srv://<username>:<password>@<cluster-url>/?retryWrites=true&w=majority

   # AWS (for S3 bucket)
   AWS_REGION==********
   AWS_ACCESS_KEY=your-aws-access-key
   AWS_SECRET_KEY=your-aws-secret-key
   AWS_S3_BUCKET==********

   # Authentication (Keycloak)
   KC_URL==********
   KC_AUTH_USER==********
   KC_AUTH_PASS=your-keycloak-password

   # Frontend/Backend URLs
   ONBOARD_FORM_URL=********
   API_BACKEND=********


4. Start the development server

   ```bash
   npm run dev
   ```

5. Build for production

   ```bash
   npm start
   ```

---