Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Challenge Bravo #307

Open
wants to merge 43 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
858146e
Algoritmo base para conversão de moedas
nadoneves Feb 19, 2024
76c7b56
Adicionando .gitignore
nadoneves Feb 19, 2024
ee6215b
Construído o servidor base da aplicação
nadoneves Feb 19, 2024
4319dfb
Update .gitignore
nadoneves Feb 19, 2024
c3b8d01
Validando query paramenters na rota principal
nadoneves Feb 19, 2024
f94a072
Adicionando helmet ao servidor
nadoneves Feb 19, 2024
dfe42b8
Aplicando API rate limite e script yml para stress teste
nadoneves Feb 19, 2024
914d109
Adicionando docker ao projeto
nadoneves Feb 19, 2024
9b65f29
Add redis e mysql ao projeto
nadoneves Feb 20, 2024
bc2187f
Criando workers para manter o mysql e o redis atualizados
nadoneves Feb 20, 2024
111c0df
Refatorando o ambiente em docker
nadoneves Feb 20, 2024
aa240af
Refatorando docker para ordenar os starts seguindo a arquitetura dese…
nadoneves Feb 20, 2024
5dbdfa2
Consultando dados no redis e fazendo a conversão
nadoneves Feb 21, 2024
ea91767
FIX: tratando exceções ao realizar uma conversão
nadoneves Feb 22, 2024
a441fca
Aumentando a atualização das moedas para 5 minutos
nadoneves Feb 22, 2024
72fa1a2
Corrigindo o healthcheck do mysql para computadores mais fracos
nadoneves Feb 22, 2024
7212780
REF: algoritmo de conversão de moeda
nadoneves Feb 23, 2024
d57410b
Cadastrando nova moeda
nadoneves Feb 23, 2024
ae28a4d
Removendo moeda
nadoneves Feb 23, 2024
be446bc
Atualizando banco de dados
nadoneves Feb 24, 2024
b7ace14
Validando remoção de moedas default
nadoneves Feb 24, 2024
3468953
REF: validações, formatações e melhorando as requisições para o redis
nadoneves Feb 24, 2024
980b1d3
REF: adicionando propriedade crypto ao criar uma nova meda
nadoneves Feb 24, 2024
9376735
REF: delete para o novo formato do redis
nadoneves Feb 24, 2024
7f57f93
REF: status code 404
nadoneves Feb 24, 2024
98135f9
Adicionando teste unitário com jest
nadoneves Feb 24, 2024
4316bfb
Adicionando rota para swagger
nadoneves Feb 24, 2024
882e635
FIX: corrigindo swagger parameter string
nadoneves Feb 24, 2024
14b4986
FIX: corrigindo novo formato do redis ao criar uma nova moeda
nadoneves Feb 24, 2024
0d2f367
README e desenhos com drawio
nadoneves Feb 27, 2024
b5ee5ef
REF: readme
nadoneves Feb 27, 2024
c944c0c
REF: readme
nadoneves Feb 27, 2024
dacffe5
Melhorando o readme
nadoneves Feb 27, 2024
bfb6151
Refatorando variaveis de ambiente
nadoneves Feb 27, 2024
6220075
Refatorando variaveis de ambiente
nadoneves Feb 27, 2024
89693bf
FIX: alterando api publica devido ao encerramento das atividades da a…
nadoneves Feb 28, 2024
d8a042d
REF: alterando variaveis e requests para promise.all
nadoneves Feb 28, 2024
5a26834
FIX: commit após o redis invalidando o processo do worker
nadoneves Feb 28, 2024
6ca44e2
Organizando test unitario e adicionando teste de integração
nadoneves Feb 28, 2024
27ec38f
Organizando melhor o README
nadoneves Feb 28, 2024
d6b0089
Corrigindo bugs no algoritmo de conversão de moedas.
nadoneves Feb 29, 2024
c68ba40
Refatorando retorno de casas decimais
nadoneves Feb 29, 2024
8b0a9b2
Atualizando diagrama de sequencia da API
nadoneves Feb 29, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
node_modules
npm-debug.log
.DS_Store
.git
.gitignore
.env
notes.txt
mysql_data
sql
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
node_modules
package-lock.json
notes.txt
.env
mysql_data
7 changes: 7 additions & 0 deletions Dockerfile.backend
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
FROM node:18
WORKDIR /app
COPY package*.json ./
RUN npm install
COPY . .
EXPOSE 3000
CMD ["npm", "start"]
7 changes: 7 additions & 0 deletions Dockerfile.worker
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
FROM node:18
WORKDIR /app
COPY package*.json ./
RUN npm install
COPY models/ models/
COPY workers/ workers/
CMD ["node", "workers/currencys.js"]
138 changes: 81 additions & 57 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,82 +1,106 @@
# <img src="https://avatars1.githubusercontent.com/u/7063040?v=4&s=200.jpg" alt="Hurb" width="24" /> Bravo Challenge

[[English](README.md) | [Portuguese](README.pt.md)]
Para esse desafio foi usada a seguinte arquitetura:

Build an API, which responds to JSON, for currency conversion. It must have a backing currency (USD) and make conversions between different currencies with **real and live values**.
<p>
<img src="./docs/Architecture.png" alt="Architecture" />
</p>

The API must convert between the following currencies:
## Diagramas de sequência

- USD
- BRL
- EUR
- BTC
- ETH
### Worker

Other coins could be added as usage.
<p>
<img src="./docs/Sequence-Worker.png" alt="[UML] Sequence - Worker" />
</p>

Ex: USD to BRL, USD to BTC, ETH to BRL, etc...
### API

The request must receive as parameters: The source currency, the amount to be converted and the final currency.
<p>
<img src="./docs/Sequence-API.png" alt="[UML] Sequence - Worker" />
</p>

Ex: `?from=BTC&to=EUR&amount=123.45`
## Containers (docker):

Also build an endpoint to add and remove API supported currencies using HTTP verbs.
### db

The API must support conversion between FIAT, crypto and fictitious. Example: BRL->HURB, HURB->ETH
Banco de dados MySQL responsável por persistir os dados em um estado sólido.

"Currency is the means by which monetary transactions are effected." (Wikipedia, 2021).
### redis

Therefore, it is possible to imagine that new coins come into existence or cease to exist, it is also possible to imagine fictitious coins such as Dungeons & Dragons coins being used in these transactions, such as how much is a Gold Piece (Dungeons & Dragons) in Real or how much is the GTA$1 in Real.
Banco de dados em memória (volátil) que dará melhor desempenho e velocidade em nosso response.

Let's consider the PSN quote where GTA$1,250,000.00 cost R$83.50 we clearly have a relationship between the currencies, so it is possible to create a quote. (Playstation Store, 2021).
### worker

Ref:
Wikipedia [Institutional Website]. Available at: <https://pt.wikipedia.org/wiki/Currency>. Accessed on: 28 April 2021.
Playstation Store [Virtual Store]. Available at: <https://store.playstation.com/pt-br/product/UP1004-CUSA00419_00-GTAVCASHPACK000D>. Accessed on: 28 April 2021.
Serviço responsável por manter o db e o redis sempre atualizados com dados reais. O tempo de atualização default é de 5 minutos, porém esse parâmetro pode ser alterado atualizando o docker-compose.yml

You can use any programming language for the challenge. Below is the list of languages ​​that we here at Hurb have more affinity:
### app

- JavaScript (NodeJS)
- Python
- Go
- Ruby
- C++
- PHP
Nosso servidor backend escrito em NodeJS utilizando o framework [ExpressJS](https://expressjs.com/pt-br/).

## Requirements

- Fork this challenge and create your project (or workspace) using your version of that repository, as soon as you finish the challenge, submit a _pull request_.
- If you have any reason not to submit a _pull request_, create a private repository on Github, do every challenge on the **main** branch and don't forget to fill in the `pull-request.txt` file. As soon as you finish your development, add the user `automator-hurb` to your repository as a contributor and make it available for at least 30 days. **Do not add the `automator-hurb` until development is complete.**
- If you have any problem creating the private repository, at the end of the challenge fill in the file called `pull-request.txt`, compress the project folder - including the `.git` folder - and send it to us by email.
- The code needs to run on macOS or Ubuntu (preferably as a Docker container)
- To run your code, all you need to do is run the following commands:
- git clone \$your-fork
- cd \$your-fork
- command to install dependencies
- command to run the application
- The API can be written with or without the help of _frameworks_
- If you choose to use a _framework_ that results in _boilerplate code_, mark in the README which piece of code was written by you. The more code you make, the more content we will have to rate.
- The API needs to support a volume of 1000 requests per second in a stress test.
- The API needs to include real and current quotes through integration with public currency quote APIs
## Executando o projeto

## Evaluation criteria
Para execução do projeto basta executarmos o comando:
```shell
docker compose up
```

- **Organization of code**: Separation of modules, view and model, back-end and front-end
- **Clarity**: Does the README explain briefly what the problem is and how can I run the application?
- **Assertiveness**: Is the application doing what is expected? If something is missing, does the README explain why?
- **Code readability** (including comments)
- **Security**: Are there any clear vulnerabilities?
- **Test coverage** (We don't expect full coverage)
- **History of commits** (structure and quality)
- **UX**: Is the interface user-friendly and self-explanatory? Is the API intuitive?
- **Technical choices**: Is the choice of libraries, database, architecture, etc. the best choice for the application?
A ordem de execução será a seguinte:
1. redis
2. mysql
3. worker
4. app (com delay de 10 segundos, para que dê tempo do worker realizar as atualizações)

## Doubts
Para encerramento dos serviços:
```shell
docker compose down
```

Any questions you may have, check the [_issues_](https://github.com/HurbCom/challenge-bravo/issues) to see if someone hasn't already and if you can't find your answer, open one yourself. new issue!
Se precisar alterar o fonte, envs, ou algum outro arquivo, para rebuildar os serviços, basta executar o comando abaixo:
```shell
docker compose up --build
```

Godspeed! ;)
## API

<p align="center">
<img src="ca.jpg" alt="Challange accepted" />
</p>
> [!IMPORTANT]
> É necessário que os containers estejam em execução a partir deste momento

O projeto estará executando na porta padrão 3000.

O endereço padrão para testes:
```
http://localhost:3000/
```

### Documentação
A documentação da API foi escrita utilizando a [OpenAPI 3.0 Specification](https://swagger.io/docs/specification/about/) e se encontra no endereço:
```
http://localhost:3000/api-docs/
```
ou

[resume-doc.md](resume-doc.md)

### Observações

Para formatação monetária é utilizado o padrão brasileiro.

Para moedas correntes foi utilzado o padrão de duas casas decimais, exemplo:

```json
{
"BRL": "R$ 1,00",
"USD": "US$ 0,20"
}
```

para criptomoedas, utilizamos dez casas decimais:

```json
{
"BRL": "R$ 1,0000000000",
"BTC": "BTC 0,0000033427"
}
```
82 changes: 0 additions & 82 deletions README.pt.md

This file was deleted.

Binary file removed ca.jpg
Binary file not shown.
Loading