A comprehensive fleet management application with frontend and backend components. This guide explains how to compile the code, set up the database, and deploy the application on AWS Kubernetes Service (EKS).
-
User Management:
- Add, authenticate, and remove users.
-
Vehicle Management:
- Add new vehicles with attributes like license plate, make, model, year, and status.
- Update the status of vehicles (e.g., Available, In Maintenance, In Use).
- Retrieve a list of all vehicles.
-
Trip Management:
- Start and end trips with information such as vehicle ID, user ID, start and end times, and locations.
- Retrieve all trips, including their details.
-
Fuel Log Management:
- Add fuel logs with details like vehicle ID, date, fuel amount, and cost.
- Retrieve all fuel logs or logs for a specific vehicle.
-
Maintenance Log Management:
- Add maintenance logs with attributes like vehicle ID, date, and description.
- Retrieve maintenance logs for a specific vehicle or all logs.
-
Compliance Records Management:
- Add compliance records with details like type (e.g., Inspection, Certification), date, and description.
- Retrieve compliance records for specific vehicles or all compliance records.
-
Dashboard Metrics (Frontend Feature):
- Provides a summary view with metrics like active vehicles, completed trips, ongoing trips, fuel consumption, and maintenance alerts.
-
React-Based UI:
- User-friendly interfaces for managing vehicles, trips, fuel logs, maintenance logs, and compliance records.
- Navigation through pages like Dashboard, Reports, Vehicles, and Trips.
-
Data Interaction:
- Ability to add, edit, delete, and view records via forms and tables.
-
Reports:
- Generate and download reports in PDF and Excel formats.
-
Authentication:
- Basic login functionality.
-
Database Integration:
- Uses SQLite for data storage.
- Structured database schema for users, vehicles, trips, fuel logs, maintenance logs, and compliance records.
-
API Endpoints:
- RESTful API for communication between the frontend and backend.
-
Logging:
- Centralized logging mechanism using a Logger class.
-
Configuration Management:
- Configuration handled via JSON files for settings like database connection and logging levels.
-
Unit Testing:
- Unit tests for core managers like
VehicleManager
,FuelLogManager
,MaintenanceLogManager
,ComplianceManager
,TripManager
, andUserManager
.
- Unit tests for core managers like
-
AWS CLI Installed
Install and configure AWS CLI with your credentials:aws configure
-
kubectl Installed
Install kubectl to manage the Kubernetes cluster:curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl" chmod +x kubectl sudo mv kubectl /usr/local/bin/
-
eksctl Installed
Install eksctl to create and manage the EKS cluster:brew tap weaveworks/tap brew install weaveworks/tap/eksctl
-
Docker Installed
Install Docker for building and pushing images:sudo apt-get install docker.io
-
GitHub Repository Access
Clone your repository locally:git clone https://github.com/<your-username>/Fleet-Management.git cd Fleet-Management
-
Navigate to the backend directory:
cd backend
-
Compile the C++ backend code:
- Using
g++
:g++ -o backend main.cpp
- Using
make
(if a Makefile is available):make
- Using
-
Start the backend server:
./backend
-
Ensure the backend server is running on
http://localhost:5000
.
If the backend requires a database, follow these steps:
-
Install PostgreSQL:
sudo apt-get update sudo apt-get install postgresql postgresql-contrib
-
Start PostgreSQL Service:
sudo service postgresql start
-
Create a Database:
sudo -u postgres psql CREATE DATABASE fleet_management; \\q
-
Update Backend Configuration: Update the database connection string in the backend configuration file (e.g.,
config.json
ormain.cpp
).
-
Navigate to the frontend directory:
cd frontend
-
Install dependencies:
npm install
-
Build the Docker image:
docker build -t fleet-frontend .
-
Push the Docker image to AWS ECR:
docker tag fleet-frontend:latest <your-aws-account-id>.dkr.ecr.us-west-2.amazonaws.com/fleet-frontend:latest docker push <your-aws-account-id>.dkr.ecr.us-west-2.amazonaws.com/fleet-frontend:latest
-
Ensure all required npm packages are listed in
package.json
underdependencies
anddevDependencies
. Add the following if needed:"dependencies": { "react": "^19.0.0", "react-dom": "^19.0.0", "react-router-dom": "^7.1.1", "file-saver": "^2.0.5", "xlsx": "^0.18.5", "webpack": "^5.97.1", "webpack-cli": "^6.0.1", "html-webpack-plugin": "^5.6.3" }, "devDependencies": { "babel-loader": "^9.1.2", "css-loader": "^7.1.2", "style-loader": "^4.0.0", "@babel/core": "^7.26.0", "@babel/preset-env": "^7.26.0", "@babel/preset-react": "^7.26.3" }
-
Create the EKS cluster:
eksctl create cluster --name fleet-management-cluster --region us-west-2 --nodes 2
-
Verify the cluster is running:
kubectl get nodes
Create the following Kubernetes manifests in a k8s/
directory:
namespace.yaml
apiVersion: v1
kind: Namespace
metadata:
name: fleet-management
backend-deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: fleet-backend
namespace: fleet-management
spec:
replicas: 2
selector:
matchLabels:
app: fleet-backend
template:
metadata:
labels:
app: fleet-backend
spec:
containers:
- name: fleet-backend
image: <your-aws-account-id>.dkr.ecr.us-west-2.amazonaws.com/fleet-backend:latest
ports:
- containerPort: 5000
backend-service.yaml
apiVersion: v1
kind: Service
metadata:
name: fleet-backend
namespace: fleet-management
spec:
selector:
app: fleet-backend
ports:
- protocol: TCP
port: 5000
targetPort: 5000
type: ClusterIP
frontend-deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: fleet-frontend
namespace: fleet-management
spec:
replicas: 2
selector:
matchLabels:
app: fleet-frontend
template:
metadata:
labels:
app: fleet-frontend
spec:
containers:
- name: fleet-frontend
image: <your-aws-account-id>.dkr.ecr.us-west-2.amazonaws.com/fleet-frontend:latest
ports:
- containerPort: 3000
frontend-service.yaml
apiVersion: v1
kind: Service
metadata:
name: fleet-frontend
namespace: fleet-management
spec:
selector:
app: fleet-frontend
ports:
- protocol: TCP
port: 80
targetPort: 3000
type: LoadBalancer
-
Apply the namespace:
kubectl apply -f k8s/namespace.yaml
-
Apply the backend manifests:
kubectl apply -f k8s/backend-deployment.yaml kubectl apply -f k8s/backend-service.yaml
-
Apply the frontend manifests:
kubectl apply -f k8s/frontend-deployment.yaml kubectl apply -f k8s/frontend-service.yaml
-
Check the status of pods:
kubectl get pods -n fleet-management
-
Get the frontend LoadBalancer URL:
kubectl get svc -n fleet-management
Use the
EXTERNAL-IP
for the frontend service to access the application in your browser.
- Access the frontend URL from the LoadBalancer.
- Navigate through the application (e.g.,
/vehicles
,/fuel-logs
). - Verify interactions with the backend.
- Setup CI/CD Pipelines: Automate builds and deployments using GitHub Actions.
- Add Monitoring: Use Prometheus and Grafana for application monitoring.
- Secure APIs: Use Kubernetes Secrets for sensitive configurations.
- CORS Errors: Add appropriate headers in the backend.
- Deployment Failures: Check pod logs:
kubectl logs <pod-name> -n fleet-management
- Database Issues: Verify PostgreSQL service is running and accessible.
Happy Deployment! 🚀