yojimat / vehicles-tracking-case

Vehicles tracking use case: system that create routes and trace vehicles in real time.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Case: Vehicles Tracking

Projects in this repo create a vehicles tracking platform. The platform will be able to trace the vehicles in real time and store the trace in the database.
It will calculate vehicles fares based on the distance that vehicles will travel.
If the projects had CI/CD they should have their own repositories. Therefore, they could be deployed independently, by git webhooks or other tools.

Architecture

Vehicles Tracking Architecture

Technologies

Projects

Vehicles Tracking Interface

The Next.js framework show the interface vehicles routes and where they are after the trip started; also is Backend For FrontEnd(BFF).

Setup

Commands used to bootstrap the project.

npx create-next-app --typescript

Usage

Start the application:

cd nextjs-bff
npm install
npm run dev

API

The Nest.js framework provide the API for the platform, having features like: Redis as storage for job queues to have better resilience, WebSockets for real time full-duplex communication between the API and BFF.
You will need to create a file called .env at the root of the project and an account at google to use the maps API like this:
GOOGLE_MAPS_API_KEY = <YOUR_GOOGLE_MAPS_API_KEY>

Setup

Commands used to bootstrap the project.

npm install -g @nestjs/cli
nest new nestjs-api
cd nestjs-api 
npm install @prisma/client
npx prisma init #Change the .env file the prisma file.
npx prisma generate # This command must be executed every time that schema.prisma is changed.
npx nest generate module prisma
npx nest generate service prisma
npx nest generate resource # Create the CRUD of routes.
npx nest generate module maps
npx nest generate controller maps/places
npx nest generate service maps/places
npx nest generate controller maps/directions
npx nest generate service maps/directions
npx nest generate service routes/routes-driver
npx nest generate gateway routes/routes-websocket

Usage

Using the API with Docker Compose:

cd nestjs-api
docker compose down --volumes
docker compose up --build

Access http://localhost:3000/routes.
There is a file at the root of the project that is called api.http that you can use to test the application with the plugin of VSCode called REST Client.
When the request is made, Nest.js will consume the request/message and show it on the console.
You can use Prisma Studio to see the data in the database.

npx prisma studio

Tests

# unit tests
$ npm run test
# e2e tests
$ npm run test:e2e
# test coverage
$ npm run test:cov

Apache Kafka

The Apache Kafka is a message broker that will be used to send messages between the microservice and the API.

Usage

Using the Apache Kafka with Docker Compose:

cd kafka
docker compose down # Run this command to clean files that may generate errors in the next command.
docker compose up

Usage

Using the Apache Kafka with Docker Compose:

cd kafka
docker compose down # Run this command to clean files that may generate errors in the next command.
docker compose up

Vehicles Fares Microservice

The microservice calculate the fares of vehicles based on the distance of the route, that the vehicles will travel.

Setup

Commands used to bootstrap the project.

mkdir go-microservice
cd go-microservice
go mod init github.com/yojimat/vehicles-tracking-case/go

Usage

cd go-microservice
go run cmd/freight/main.go

Dashboards & System Metrics

The dashboards are made by the application Grafana and the metrics collected by Prometheus. To run these applications see the docker-compose.yml file outside of the projects.

Authors and acknowledgment

Thanks to the professors of full cycle course that helped to create and bootstrap this project.

About

Vehicles tracking use case: system that create routes and trace vehicles in real time.


Languages

Language:TypeScript 72.6%Language:Go 17.2%Language:CSS 7.8%Language:JavaScript 1.4%Language:Dockerfile 1.0%