|
1 | | -# API Transferências Financeiras |
| 1 | +# Financial Transfers API |
2 | 2 |
|
3 | | -Este projeto consiste em uma API RESTful para gerenciamento de clientes e realização de transferências financeiras. |
| 3 | +This project consists of a RESTful API for customer management and financial transfers. |
4 | 4 |
|
5 | | -O princípio [KISS](https://en.wikipedia.org/wiki/KISS_principle) (*Keep It Simple, Stupid!*) foi adotado para manter simplicidade, clareza e facilitar a manutenção do projeto. |
6 | | - |
7 | | -## Tecnologias e Requisitos |
| 5 | +## Technologies and Requirements |
8 | 6 |
|
9 | 7 | * **Java 25** |
10 | 8 | * **Spring Boot 4** |
11 | 9 | * **H2** |
12 | 10 | * **Maven** |
13 | 11 |
|
14 | | -## Como Executar a Aplicação |
| 12 | +## How to Run the Application |
15 | 13 |
|
16 | | -1. **Pré-requisitos**: Certifique-se de ter o **JDK 21** e o **Maven** instalados. |
17 | | -2. **Clone o repositório**: |
| 14 | +1. **Prerequisites**: Make sure you have **JDK 21** and **Maven** installed. |
| 15 | +2. **Clone the repository**: |
18 | 16 |
|
19 | 17 | ```bash |
20 | 18 | git clone https://github.com/barcellos-pedro/api-transferencia.git |
21 | 19 | cd api-transferencia |
22 | 20 | ``` |
23 | 21 |
|
24 | | -3. **Compile e execute**: |
25 | | - |
26 | | -Para rodar com o perfil padrão |
| 22 | +1. **Compile and run**: |
27 | 23 |
|
28 | 24 | ```bash |
29 | 25 | mvn spring-boot:run |
30 | 26 | ``` |
31 | 27 |
|
32 | | -Para rodar com o perfil **dev** que já possui alguns registros no banco de dados |
33 | | -```bash |
34 | | -mvn spring-boot:run -Dspring-boot.run.profiles=dev |
35 | | -``` |
36 | | - |
37 | | -4. **Acesse a API**: A aplicação estará disponível em `http://localhost:8080`. |
38 | | -5. **Documentação Interativa (Swagger)**: Acesse `http://localhost:8080/swagger-ui/index.html` para testar os endpoints |
39 | | - no navegador |
| 28 | +1. **Access the API**: The application will be available at `http://localhost:8080`. |
| 29 | +2. **Interactive Documentation (Swagger)**: Access `http://localhost:8080/swagger-ui/index.html` to test the endpoints |
| 30 | + in the browser |
40 | 31 |
|
41 | | -## Endpoints Principais |
| 32 | +## Main Endpoints |
42 | 33 |
|
43 | | -A API segue o padrão RESTful e versionamento via URL (`/v1/...`): |
| 34 | +The API follows RESTful patterns and URL versioning (`/v1/...`): |
44 | 35 |
|
45 | | -**Clientes**: |
| 36 | +**Customers**: |
46 | 37 |
|
47 | | -* `GET /v1/customers`: Listagem geral de clientes. |
48 | | -* `POST /v1/customers`: Cadastro de novo cliente. |
49 | | -* `GET /v1/customers/{account}`: Busca Cliente por número de conta. |
50 | | -* `GET /v1/customers/{account}/transfers`: Histórico ordenado por data decrescente, incluindo falhas. |
51 | | -* `POST /v1/customers/{account}/transfers`: Realiza transferência entre contas (Limite de R$ 10.000,00). |
| 38 | +* `GET /v1/customers`: General customer listing. |
| 39 | +* `POST /v1/customers`: Register new customer. |
| 40 | +* `GET /v1/customers/{account}`: Search Customer by account number. |
| 41 | +* `GET /v1/customers/{account}/transfers`: History ordered by descending date, including failures. |
| 42 | +* `POST /v1/customers/{account}/transfers`: Perform transfer between accounts (Limit of R$ 10,000.00). |
52 | 43 |
|
53 | | -## Endpoints adicionais |
| 44 | +## Additional Endpoints |
54 | 45 |
|
55 | | -* `GET /api-docs` - Especificação OpenAPI em JSON. |
56 | | -* `GET /actuator/health`: Check da saúde da aplicação. |
57 | | -* `GET /swagger-ui/index.html`: Interface visual para testar os endpoints da API. |
| 46 | +* `GET /api-docs` - OpenAPI specification in JSON. |
| 47 | +* `GET /actuator/health`: Application health check. |
| 48 | +* `GET /swagger-ui/index.html`: Visual interface to test API endpoints. |
58 | 49 |
|
59 | | -## Monitoramento e Documentação |
| 50 | +## Monitoring and Documentation |
60 | 51 |
|
61 | | -A API utiliza o Spring Boot Actuator para fornecer métricas e estados de saúde, essencial para ambientes de produção e |
62 | | -observabilidade. |
| 52 | +The API uses Spring Boot Actuator to provide metrics and health status, essential for production environments and |
| 53 | +observability. |
63 | 54 |
|
64 | | -**(Endpoints de Diagnóstico (Actuator)** |
| 55 | +**Diagnostic Endpoints (Actuator)** |
65 | 56 |
|
66 | | -| Endpoint | Descrição | Utilidade | |
67 | | -|-----------------------|--------------------|----------------------------------------------------------| |
68 | | -| GET /actuator/health | Saúde da Aplicação | Verifica se o App, DB e Disco estão operacionais. | |
69 | | -| GET /actuator/metrics | Métricas | Lista métricas disponíveis (JVM, CPU, Requisições HTTP). | |
70 | | -| GET /actuator/info | Informações | Dados personalizados sobre a versão e build do projeto. | |
| 57 | +| Endpoint | Description | Purpose | |
| 58 | +|-----------------------|--------------------|---------------------------------------------------------| |
| 59 | +| GET /actuator/health | Application Health | Checks if App, DB and Disk are operational. | |
| 60 | +| GET /actuator/metrics | Metrics | Lists available metrics (JVM, CPU, HTTP Requests). | |
| 61 | +| GET /actuator/info | Information | Custom data about project version and build. | |
71 | 62 |
|
72 | | -## Decisões de Engenharia & Arquitetura |
| 63 | +## Engineering & Architecture Decisions |
73 | 64 |
|
74 | | -### 1. Resiliência no Histórico |
| 65 | +### 1. History Resilience |
75 | 66 |
|
76 | | -Transferências sem sucesso também são armazenadas. Para garantir que o registro de falha seja |
77 | | -persistido mesmo quando a transação financeira sofrer rollback, utilizei a propagação **`REQUIRES_NEW`** no serviço de |
78 | | -auditoria. Isso garante a integridade do histórico para conformidade bancária. |
| 67 | +As requested, unsuccessful transfers are also stored. To ensure that the failure record is |
| 68 | +persisted even when the financial transaction suffers rollback, I used **`REQUIRES_NEW`** propagation in the audit |
| 69 | +service. This guarantees the integrity of the history for banking compliance. |
79 | 70 |
|
80 | | -### 2. Controle de Concorrência |
| 71 | +### 2. Concurrency Control |
81 | 72 |
|
82 | | -Para atender ao requisito de controle de concorrência na operação de transferência, foi implementado: |
| 73 | +To meet the concurrency control requirement in the transfer operation, the following was implemented: |
83 | 74 |
|
84 | | -* **Optimistic Locking** com `@Version` quando dois processos tentam debitar da mesma conta simultaneamente. |
| 75 | +* **Pessimistic Locking** (or **Optimistic Locking** with `@Version`): To avoid the "Lost Update" problem when |
| 76 | + two processes try to debit from the same account simultaneously. |
85 | 77 |
|
86 | | -### 3. Validação de Regras de Negócio |
| 78 | +### 3. Business Rules Validation |
87 | 79 |
|
88 | | -As regras de saldo suficiente e limite máximo de R$ 10.000,00 por operação foram centralizadas na camada de serviço, |
89 | | -garantindo que o estado do banco de dados permaneça consistente. |
| 80 | +The rules of sufficient balance and maximum limit of R$ 10,000.00 per operation were centralized in the service layer, |
| 81 | +ensuring that the database state remains consistent. |
90 | 82 |
|
91 | | -## Testes |
| 83 | +## Tests |
92 | 84 |
|
93 | | -A cobertura de testes foi priorizada para garantir a confiabilidade das transferências: |
| 85 | +Test coverage was prioritized to ensure the reliability of transfers: |
94 | 86 |
|
95 | | -* **Testes CI/CD**: Execução dos testes unitários e de integração na pipeline após cada commit. |
96 | | -* **Testes Unitários**: Validação de lógica de negócio e cálculos de saldo. |
97 | | -* **Testes de Integração**: Fluxo completo de transferência simulando concorrência e rollback de banco de dados. |
| 87 | +* **Unit Tests**: Validation of business logic and balance calculations. |
| 88 | +* **Integration Tests**: Complete transfer flow simulating concurrency and database rollback. |
98 | 89 |
|
99 | | -Execute os testes com: |
| 90 | +Run the tests with: |
100 | 91 |
|
101 | 92 | ```bash |
102 | 93 | mvn test |
103 | 94 | ``` |
104 | 95 |
|
105 | | -## Base do Projeto |
| 96 | +## Project Base |
106 | 97 |
|
107 | | -O projeto foi estruturado utilizando o [Spring Initializr](https://start.spring.io). |
| 98 | +The project was structured using [Spring Initializr](https://start.spring.io). |
108 | 99 |
|
109 | | -**Stack Tecnológica e Dependências** |
| 100 | +**Technology Stack and Dependencies** |
110 | 101 |
|
111 | | -Abaixo, os principais componentes selecionados para atender aos requisitos da API: |
| 102 | +Below, the main components selected to meet the API requirements: |
112 | 103 |
|
113 | 104 | <img width="1710" height="654" alt="image" src="https://github.com/user-attachments/assets/35a7e8da-9396-4ad3-944b-87a0fa95573a" /> |
114 | | - |
115 | | -## Requisitos |
116 | | - |
117 | | -Confira mais detalhes sobre os [requisitos](./docs/REQUISITOS.md) em `docs/REQUISITOS.md` |
118 | | - |
0 commit comments