Skip to content

Commit

Permalink
setup: first setup with base structure and packages
Browse files Browse the repository at this point in the history
  • Loading branch information
sahdoio committed Jan 26, 2024
0 parents commit 4bbc96a
Show file tree
Hide file tree
Showing 193 changed files with 18,971 additions and 0 deletions.
11 changes: 11 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
.vscode
.idea
.env

# Generated by MacOS
.DS_Store
**/.DS_Store

# Certificates
*.crt
*.key
22 changes: 22 additions & 0 deletions api/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
APP_PORT=3001
NODE_ENV=development

DB_DRIVER=postgres
# DB_HOST=localhost
DB_HOST=shorturl-db
DB_PORT=5432
DB_USERNAME=admin
DB_PASSWORD=secret
DB_NAME=shorturl

DB_TEST_DRIVER=postgres
DB_TEST_HOST=shorturl-test-db
DB_TEST_PORT=5433
DB_TEST_USERNAME=admin
DB_TEST_PASSWORD=secret
DB_TEST_NAME=shorturl-test

JWT_KEY=%#OfjeojofwjfO%J#%O%J#O%J325j230523532892fiwdfhihIHSIHSIF@FIFH
HASH_PADDING=r@i23IHTI23THI2GigH2IGH239332532dsvdDSGIHGDSI@#i23H5932H5923HT9HSDIIGI3H2ri#TH23IHI23%#%%#23%23WEGUGSD222I11I4BJCSBJSBjfwbiufeueu@T#23huwegbubwug2b3i2#T@I3htwe

APP_HOST=http://localhost:3000
16 changes: 16 additions & 0 deletions api/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
node_modules
dist
coverage
yarn-error.log
.vscode
.idea
.env
todo.txt

# Generated by MacOS
.DS_Store
**/.DS_Store

# Certificates
*.crt
*.key
10 changes: 10 additions & 0 deletions api/.sequelizerc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// .sequelizerc

const { resolve } = require('path');

module.exports = {
'config': resolve('src/config/sequelize.json'),
'models-path': resolve('src/app/implementations/database/entities'),
'seeders-path': resolve('src/app/implementations/database/seeders'),
'migrations-path': resolve('src/app/implementations/database/migrations')
};
94 changes: 94 additions & 0 deletions api/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
# ShorURL API #

This is an API Rest developed with NodeJs, TypeScript and Clean Architecture.

* node version: 18.18.0
* Database: PostgreSQL
* TypeScript
* Tests made with Jest
* Containers with Docker

### How do I get set up? ###

* .env

Rename or copy the .env.example to .env

cp .env.example .env

The .env is configured to use docker database setup

* build app

In the app root (the same dir where is located the package.json and this README) run:

docker compose up --build -d

Just to make sure node_modules was really installed run npm install

docker exec shorturl npm i

To check docker live logging:

docker-compose logs -f --tail 10

You should see the following containers active:

![alt text](./docs/dockerps.png)


### Database Setup ###

Before start to test the application you should run the migrations and seeder to setup the development database and the test database as well to run the integration tests

* Running migration for development

docker exec shorturl npx sequelize-cli db:migrate

![alt text](./docs/migration.png)

* Running migration for test

docker exec shorturl npx sequelize-cli db:migrate --env test

* Running seeders for development

docker exec shorturl npx sequelize-cli db:seed:all

![alt text](./docs/seed.png)

* Running seeders for test

docker exec shorturl npx sequelize-cli db:seed:all --env test

* The final result:

![alt text](./docs/database.png)

### How to run unit tests? ###

* Normal test

docker-compose exec shorturl npx jest

![alt text](./docs/tests.png)

* With coverage

docker-compose exec shorturl npx jest --coverage

Terminal version

![alt text](./docs/tests-coverage.png)

Html version

![alt text](./docs/tests-coverage-html.png)

* Postman Project

See [Postman Collection](./docs/collection.json)

### Who do I talk to? ###

* Lucas sahdo - [email protected]
52 changes: 52 additions & 0 deletions api/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
version: '3'

networks:
shorturl-network:
driver: bridge
ipam:
driver: default

services:
shorturl:
container_name: shorturl
image: shorturl
build:
context: .
dockerfile: ./docker/api.Dockerfile
volumes:
- './:/var/www/app'
- '/var/www/app/node_modules'
environment:
- npm_config_unsafe_perm=true
ports:
- "3030:3000"
networks:
- shorturl-network

shorturl-db:
container_name: shorturl-db
image: postgres
environment:
POSTGRES_DB: shorturl
POSTGRES_USER: admin
POSTGRES_PASSWORD: secret
PGDATA: /data/postgres
ports:
- "5432:5432"
restart: unless-stopped
networks:
- shorturl-network

shorturl-test-db:
container_name: shorturl-test-db
image: postgres
environment:
POSTGRES_DB: shorturl-test
POSTGRES_USER: admin
POSTGRES_PASSWORD: secret
PGDATA: /data/postgres
ports:
- "5433:5432"
restart: unless-stopped
networks:
- shorturl-network
15 changes: 15 additions & 0 deletions api/docker/api.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
FROM node:18.18.0

WORKDIR /var/www/app

RUN apt-get update && apt-get -f -y install unzip wget curl vim

COPY package.json /var/www/app

RUN ls -lha ../ & pwd

RUN npm install

EXPOSE 3000

CMD ["npm", "run", "dev"]
Loading

0 comments on commit 4bbc96a

Please sign in to comment.