PhytoLab Server is a backend system designed for a healthcare SaaS platform. it provides a robust API for managing diagnostic laboratories (PhytoLabs), test catalogs, and patient reports. The system is built with a focus on clear role separation between administrators and laboratory operators.
- Lab Account Creation: Administrators can onboard new laboratories by creating dedicated accounts.
- Access Control: Secure authentication and management of laboratory credentials.
- Categorization: Organize tests into categories (e.g., Biochemistry, Hematology).
- Test Collections: Group related tests together for easier selection and reporting.
- Detailed Test Definitions: Define individual tests with reference ranges, units, and notes.
- Report Generation: Laboratories can create detailed diagnostic reports for patients.
- Patient Tracking: Maintain records of patient demographics (name, age, gender) and reference doctors.
- Data Collections: Manage historical test data and report collections.
- Runtime: Node.js
- Framework: Express.js (v5.1.0)
- Database: MongoDB with Mongoose (v8.16.0)
- Security:
- Environment Management: dotenv
- Development Tools: Nodemon, Prettier
src/
├── controllers/ # Business logic for each resource
├── db/ # Database connection logic
├── middlewares/ # Authentication middlewares
├── models/ # Mongoose schemas and models
├── routes/ # Express route definitions
├── utils/ # Standardized error and response helpers
├── app.js # Express app configuration
├── constants.js # Global constants and environment variables
└── index.js # Server entry point
The system uses JWT (JSON Web Tokens) for authentication. Tokens can be provided via:
- HTTP Cookies:
accessTokencookie. - Authorization Header:
Bearer <token>
There are two primary authorization levels:
verifyAdmin: Restricted to administrative tasks (lab management, catalog setup).verifyPhytolab: Restricted to lab-specific tasks (reporting, data entry).
- Lab management:
POST /phytolab,GET /phytolab,PUT /phytolab/:phytolab - Catalog management:
/testCategory,/testCollection,/tests
- Authentication:
POST /auth/login - Report management:
POST /report,GET /report/:reportId,PUT /report/:reportId
- Node.js installed
- MongoDB instance (local or Atlas)
-
Clone the repository
git clone <repository-url> cd lab-server
-
Install dependencies
pnpm install
-
Environment Configuration Create a
.envfile in the root directory based on.env.sample:PORT=8000 MONGODB_URI=your_mongodb_connection_string DB_NAME=phytolab JWT_SECRET=your_jwt_secret ADMIN_SECRET=your_admin_secret
-
Run the server
# Development mode pnpm dev # Production mode pnpm start
Contributions are welcome! Please ensure you follow the existing code style and run Prettier before submitting any pull requests.