Project developed for technical evaluation in the selection process for the Junior DevOps position at TMaior.
Backend application developed for practical purposes using Clean aArchitecture + object-oriented programming paradigm + SOLID principles. This application is a API Restfull developed with Node.js + TypeScript + MongoDB ATLAS + Prisma ORM + Docker. For the pipelines I used Github Actions for the continuous integration and delivery processes.
Note: To follow the step-by-step instructions for running the application on your machine, you need to have knowledge of terminal commands, Git and GitHub commands, and npm package manager commands, as well as navigating between folders using the terminal.
1º step: clone the repository to your machine from GitHub.
git clone https://github.com/Marlinsk/tmaior-test-marlon-backend-application.git
2º step: Navigate to the project folder.
cd tmaior-test-marlon-backend-application
3º step: Create .env file before run npm install in the terminal.
DATABASE_URL=mongodb+srv://USERNAME:PASSWORD@HOST/DATABASE
Note: After creating the file, insert the credentials to connect to the MongoDB Atlas database.
4º step: Run the command in the terminal to install the project dependencies.
npm install
5º step: Run the command in the terminal to generate prisma client.
npx prisma generate
6º step: Run the command in the terminal to connect to MongoDB ATLAS.
npx prisma db push
7º step: Execute the command to build the application.
npm run build
Without the dist file generated by the build, the application will not work.
8º step: Run the command in the terminal to start the application, and feel free to test and play around.
npm run start
Now, you just need to access it using a request tool or consume it; the application is running on localhost:5000.
Note: You need to have Docker on your machine and have a basic understanding of terminal commands. Having all of that, let's get started.
1º step: Inside the project folder, run the following command in the terminal to create the Docker image.
docker build -t backend-app:latest .
2º step: Run the command in the terminal for list your images.
docker images
After that, look for the IMAGE ID of your image name and copy it.
3º step: Run the command in the terminal for app works.
docker run -p 5000:5000 --name app-container backend-app:latest
Command to list the running containers
docker ps
To stop a specific container
docker stop app-container
Note: To stop all running containers, you can simply use docker stop.
To remove specific container
docker rm app-container
To remove specific image
docker rmi backend-app:latest
Note: Must have knowledge of creating cloud environments.
To run the application using Docker in Cloud, create and open the docker-compose.yml in environment, copy this example file and modify the variables. Add the name of the Docker image you created along with its version. Additionally, include the same MongoDB Atlas connection URL from your .env file in the environment section.
version: '3'
services:
app:
container_name: simple-api
image: backend-app:latest
ports:
- '5000:5000'
environment:
DATABASE_URL: 'mongodb+srv://USERNAME:PASSWORD@HOST/DATABASE'
Note: During the build process using github actions, the environment variable is not copied into the container during the process, so in docker-compose the value of the environment variable is passed.
After doing this, run the following command to bring up the container. Make sure everything is done according to the step-by-step before proceeding.
To start the services defined in your docker-compose.yml file:
docker-compose up
or
To start the services defined in your docker-compose.yml file:
docker-compose up -d
Now, you have an application running in a Docker container. You just need to access it using a request tool or consume it; the application is running on localhost:5000.
To start and rebuild the containers, forcing them to be rebuilt (useful when you make changes to your Dockerfile or application code):
docker-compose up --build
To stop and remove the containers defined in your docker-compose.yml file:
docker-compose down
Note: To stop all running containers, you can simply use docker stop.
To start all stopped containers defined in your docker-compose.yml file, you can use the following command:
docker-compose start
To view the logs of the services:
docker-compose logs
Documentation for the API request routes.
POST Create a post:
Create a post.
Example request body:
{
"title": "Hello world!",
"text": "hello world!"
}
/posts
GET Find post by ID:
Get the post by ID specified.
/posts/:id
GET Find all posts:
List all posts
/posts
PUT Update post:
Update post by specified ID
Example request body:
{
"title": "Hello world!",
"text": "hello world!"
}
/posts/:id
DELETE Remove post:
Remove post by specified ID
/posts/:id
This application is divided into two parts back end and front end, to access the front end repository, the link below takes you to the front end application repository.
Link: https://github.com/Marlinsk/tmaior-test-marlon-frontend-application