- Overview
- Technologies Used
- Project Structure
- Installation
- API Documentation
- Authentication
- Event System
- Database Models
- Contributing
This system provides a comprehensive solution for recording, managing, and monitoring birth and death records. It includes user authentication with role-based access, anonymous data handling for privacy compliance, and real-time event notifications for new records.
- Node.js - JavaScript runtime
- Express.js - Web framework
- MongoDB - NoSQL database
- Mongoose - MongoDB object modeling
- JWT - JSON Web Tokens for authentication
- bcrypt - Password hashing
- Server-Sent Events - Real-time notifications
- react - Javascript framework to crate robust single page apps react-router-dom - React router to navigate between pages
- axios - A promise-based HTTP Client for node.js and the browser
- tailwindcss - An open source CSS framework
The project follows a modular architecture:
βββ config/
β βββ db.js # Database connection configuration
βββ controllers/
β βββ AnonymController.js # Anonymous records management
β βββ authController.js # User authentication
β βββ RecordController.js # Records CRUD operations
β βββ UserController.js # User management
βββ middleware/
β βββ authMiddleware.js # Authentication middleware
βββ models/
β βββ Anonym.js # Anonymous data schema
β βββ Record.js # Record schema
β βββ User.js # User schema
βββ routes/
β βββ authRoutes.js # Authentication routes
β βββ eventRoutes.js # SSE event routes
β βββ recordRoutes.js # Record management routes
β βββ userRoutes.js # User management routes
βββ server.js # Main application entry point
-
Clone the repository:
git clone <repository-url> cd <project-folder>
-
Install dependencies:
npm install
-
Create a
.env
file in the root directory with the following variables:PORT=5000 MONGO_URI=<your-mongodb-connection-string> JWT_SECRET=<your-jwt-secret-key>
-
Start the server:
npm start
The system uses JWT (JSON Web Token) for authentication. Tokens are issued upon successful login and have a 7-day expiration period.
Protected Routes: Many endpoints require authentication. Include the JWT token in the request headers:
Method | Endpoint | Description | Request Body | Response |
---|---|---|---|---|
POST | /api/auth/login |
Authenticate a user | { PhoneNumber, Password } |
JWT token and user data |
POST | /api/auth/register-employee |
Register a new employee | { PhoneNumber, Password, Organization, FullName, Role } |
JWT token and user data |
POST | /api/auth/register-researcher |
Register a new researcher (DSP only) | { PhoneNumber, Password, Organization, FullName, Role } |
JWT token and user data |
GET | /api/auth/employee |
Get authenticated employee data | - | Employee object |
Method | Endpoint | Description | Request Body/Params | Response |
---|---|---|---|---|
POST | /api/death-record |
Create death record (hospital) | Death record data | Created record |
POST | /api/birth-record |
Create birth record (hospital) | Birth record data | Created record |
GET | /api/hospital/death-record |
Get all hospital death records | - | Array of records |
GET | /api/hospital/birth-record |
Get all hospital birth records | - | Array of records |
Method | Endpoint | Description | Request Body/Params | Response |
---|---|---|---|---|
GET | /api/asp/death-record |
Get all ASP death records | - | Array of records |
GET | /api/asp/birth-record |
Get all ASP birth records | - | Array of records |
POST | /api/asp/approve-birth-record/:recordId |
Approve a birth record | URL param recordId |
Success message |
POST | /api/asp/reject-birth-record/:recordId |
Reject a birth record | URL param recordId |
Success message |
POST | /api/asp/approve-death-record/:recordId |
Approve a death record | URL param recordId |
Success message |
POST | /api/asp/reject-death-record/:recordId |
Reject a death record | URL param recordId |
Success message |
Method | Endpoint | Description | Request Body/Params | Response |
---|---|---|---|---|
GET | /api/dsp/death-record |
Get all DSP death records | - | Array of records |
GET | /api/dsp/birth-record |
Get all DSP birth records | - | Array of records |
Method | Endpoint | Description | Response |
---|---|---|---|
GET | /api/death-anonym |
Get anonymized death records | Array of records |
GET | /api/birth-anonym |
Get anonymized birth records | Array of records |
GET | /api/death-anonym/cvs |
Download death anonymized data as CSV | CSV file |
GET | /api/birth-anonym/cvs |
Download birth anonymized data as CSV | CSV file |
Method | Endpoint | Description | Response |
---|---|---|---|
GET | /api/statistics/birth-death |
Get birth and death statistics | Statistics object |
Method | Endpoint | Description | Response |
---|---|---|---|
GET | /api/birth-record/:id/pdf |
Generate PDF for birth record | PDF file |
GET | /api/death-record/:id/pdf |
Generate PDF for death record | PDF file |
Method | Endpoint | Description | Request Body | Response |
---|---|---|---|---|
POST | /api/organization |
Create a new organization | Organization data | Created organization |
The application implements Server-Sent Events (SSE) for real-time updates:
Method | Endpoint | Description | Response |
---|---|---|---|
GET | /api/eventsDeath |
Subscribe to death events | SSE stream |
GET | /api/eventsBirth |
Subscribe to birth events | SSE stream |
Subscribing to Events (Client Example):
const deathEventSource = new EventSource('/api/eventsDeath');
deathEventSource.onmessage = function(event) {
const data = JSON.parse(event.data);
console.log('New death record:', data);
};
const birthEventSource = new EventSource('/api/eventsBirth');
birthEventSource.onmessage = function(event) {
const data = JSON.parse(event.data);
console.log('New birth record:', data);
};
- PhoneNumber: Unique phone number (required)
- Password: Hashed password (required)
- Organization: User's organization
- FullName: User's full name
- Role: User role (admin/standard user)
- ArabicFullName: Full name in Arabic (required)
- LatinFullName: Full name in Latin script (required)
- BirthDate: Date of birth (defaults to current date if not provided)
- City: City of birth or residence (required)
- Wilaya: Province/region name (required)
- Gender: Gender ("Male" or "Female") (required)
- parents:
- fatherName: Father's name (optional)
- motherName: Mother's name (optional)
- SignedBy: Name of the official who signed the record (required)
- DateOfDeath: Date of death (optional, defaults to null)
- PlaceOfDeath: Place where death occurred (optional)
- CauseOfDeath: Cause of death (optional)
Stores anonymized data with the following fields:
- BirthDate: Date of birth
- City: City of birth/residence
- Wilaya: Province/state
- Gender: Gender
- SignedBy: Official who signed the record
- DateOfDeath: Date of death (if applicable)
- PlaceOfDeath: Place of death (if applicable)
- CauseOfDeath: Cause of death (if applicable)
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature
) - Commit your changes (
git commit -m 'Add some amazing feature'
) - Push to the branch (
git push origin feature/amazing-feature
) - Open a Pull Request