A full-stack web application for managing and tracking workplace injury reports with role-based access control.
CareTrack is a comprehensive injury tracking system that allows organizations to:
- Log and manage injury reports
- Track injury severity and details
- Implement role-based access control (Admin vs User)
- Maintain a secure, centralized database of incidents
- User Authentication: Secure JWT-based login system
- Role-Based Access Control (RBAC):
- Users: Can create and view injury reports
- Admins: Full access including delete capabilities
- Injury Management: Create, view, and delete injury reports
- Real-time Updates: Dynamic UI that reflects changes immediately
- Responsive Design: Mobile-friendly interface
- RESTful API: Clean, well-documented API endpoints
- React 18
- Axios for API calls
- CSS3 for styling
- Local Storage for session management
- Node.js
- Express.js
- MySQL Database
- JWT for authentication
- Bcrypt for password hashing
- Git & GitHub for version control
- Nodemon for development
- dotenv for environment configuration
Before you begin, ensure you have the following installed:
git clone https://github.com/yourusername/caretrack.git
cd caretrack# Navigate to server directory
cd server
# Install dependencies
npm install
# Create .env file
cp .env.example .env
# Edit .env with your configuration
# DB_HOST=localhost
# DB_USER=root
# DB_PASSWORD=your_password
# DB_NAME=injury_tracker
# JWT_SECRET=your_secret_key
# PORT=5000# Login to MySQL
mysql -u root -p
# Run the schema
source ../database/schema.sql
# Or manually create the database
CREATE DATABASE injury_tracker;
USE injury_tracker;
# Then paste the contents of schema.sql# Navigate to client directory
cd ../client
# Install dependencies
npm installTerminal 1 - Backend:
cd server
npm run devServer will run on http://localhost:5000
Terminal 2 - Frontend:
cd client
npm startApplication will open at http://localhost:3000
cd client
npm run buildThe application comes with two test accounts:
| Username | Password | Role |
|---|---|---|
| admin | password123 | Admin |
| user | password123 | User |
Login to the system
Request:
{
"username": "admin",
"password": "password123"
}
Response:
{
"token": "jwt_token_here",
"user": {
"id": 1,
"username": "admin",
"role": "admin"
}
}Get all injury reports (requires authentication)
Headers: Authorization: Bearer {token}Create a new injury report (requires authentication)
Request:
{
"title": "Slip and Fall",
"description": "Employee slipped in cafeteria",
"severity": 3
}Delete an injury report (admin only)
Headers: Authorization: Bearer {token}caretrack/
βββ client/ # React frontend
β βββ public/
β βββ src/
β β βββ components/ # React components
β β β βββ Login.js
| | | βββ Login.css
β β β βββ AddInjury.js
β β β βββ InjuryList.js
β β βββ services/ # API service layer
β β β βββ api.js
β β βββ App.js
β β βββ App.css
β β βββ index.js
β βββ package.json
β
βββ server/ # Express backend
β βββ config/
β β βββ database.js # DB connection
β βββ middleware/
β β βββ auth.js # JWT middleware
β βββ routes/
β β βββ auth.js # Auth routes
β β βββ injuries.js # Injury routes
β βββ .env # Environment variables
β βββ index.js # Server entry point
β βββ package.json
β
βββ database/
β βββ schema.sql # Database schema
β
βββ .gitignore
βββ README.md
- Password Hashing: Bcrypt with salt rounds
- JWT Authentication: Secure token-based auth
- RBAC: Role-based permission system
- Input Validation: Server-side validation
- SQL Injection Protection: Parameterized queries
- CORS Configuration: Controlled cross-origin requests
-
Test Authentication:
- Login with user account
- Login with admin account
- Test invalid credentials
-
Test User Functions:
- Create injury reports
- View all reports
- Verify delete button is hidden
-
Test Admin Functions:
- Login as admin
- Delete injury reports
- Verify RBAC enforcement
Import the following collection or test manually:
# Health check
GET http://localhost:5000/api/health
# Login
POST http://localhost:5000/api/auth/login
Body: {"username": "admin", "password": "password123"}
# Get injuries (use token from login)
GET http://localhost:5000/api/injuries
Headers: Authorization: Bearer {your_token}Issue: Database connection error
Solution: Check .env file credentials and ensure MySQL is running
mysql -u root -p
Issue: Port 5000 already in use
Solution: Change PORT in server/.env to another port (e.g., 5001)
Issue: CORS errors
Solution: Ensure cors() middleware is enabled in server/index.js
Issue: Token authentication fails
Solution: Check JWT_SECRET matches between login and verification
- Docker containerization
- CI/CD pipeline with GitHub Actions
- Cloud deployment (AWS/Azure)
This project is licensed under the MIT License - see the LICENSE file for details.