https://github.com/marlinsk/tmaior-test-marlon-backend-application
A backend project with clean architecture + SOLID + TDD and CD/CD process
https://github.com/marlinsk/tmaior-test-marlon-backend-application
babel cicd clean-architecture deployment docker docker-container docker-image dockerfile express-js mongodb nodejs pipeline process solid tdd test-automation tests typescript
Last synced: 3 months ago
JSON representation
A backend project with clean architecture + SOLID + TDD and CD/CD process
- Host: GitHub
- URL: https://github.com/marlinsk/tmaior-test-marlon-backend-application
- Owner: Marlinsk
- Created: 2022-09-27T02:41:44.000Z (almost 4 years ago)
- Default Branch: main
- Last Pushed: 2023-11-08T02:20:23.000Z (over 2 years ago)
- Last Synced: 2025-01-06T06:44:02.203Z (over 1 year ago)
- Topics: babel, cicd, clean-architecture, deployment, docker, docker-container, docker-image, dockerfile, express-js, mongodb, nodejs, pipeline, process, solid, tdd, test-automation, tests, typescript
- Language: HTML
- Homepage:
- Size: 217 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
Awesome Lists containing this project
README
# Technical test TMaior
Project developed for technical evaluation in the selection process for the Junior DevOps position at TMaior.
## The objective of this project version
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.
## Tutorial
**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.
### Cloning and setting up the project
**1º step: clone the repository to your machine from GitHub.**
```bash
git clone https://github.com/Marlinsk/tmaior-test-marlon-backend-application.git
```
**2º step: Navigate to the project folder.**
```bash
cd tmaior-test-marlon-backend-application
```
**3º step: Create .env file before run npm install in the terminal.**
```bash
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.**
```bash
npm install
```
**5º step: Run the command in the terminal to generate prisma client.**
```bash
npx prisma generate
```
**6º step: Run the command in the terminal to connect to MongoDB ATLAS.**
```bash
npx prisma db push
```
**7º step: Execute the command to build the application.**
```bash
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.**
```bash
npm run start
```
Now, you just need to access it using a request tool or consume it; the application is running on **localhost:5000.**
## Creating a Docker image of the application
**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.**
```bash
docker build -t backend-app:latest .
```
**2º step: Run the command in the terminal for list your images.**
```bash
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.**
```bash
docker run -p 5000:5000 --name app-container backend-app:latest
```
### Other docker commands
Command to list the running containers
```bash
docker ps
```
To stop a specific container
```bash
docker stop app-container
```
**Note:** To stop all running containers, you can simply use **docker stop.**
To remove specific container
```bash
docker rm app-container
```
To remove specific image
```bash
docker rmi backend-app:latest
```
## Run aplication in Cloud with docker-composer
**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.
```bash
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:
```bash
docker-compose up
```
or
To start the services defined in your docker-compose.yml file:
```bash
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.**
### Other docker commands
To start and rebuild the containers, forcing them to be rebuilt (useful when you make changes to your Dockerfile or application code):
```bash
docker-compose up --build
```
To stop and remove the containers defined in your docker-compose.yml file:
```bash
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:
```bash
docker-compose start
```
To view the logs of the services:
```bash
docker-compose logs
```
## Application Routes
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
## See also the front end application
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