Introduction to Go Clean Architecture
Go Clean Architecture is a comprehensive solution tailored for managing various banking tasks. Developed with a user-friendly approach, this project enables users to perform banking operations such as creating and listing accounts, checking account balances, conducting transfers between accounts, and keeping track of transfer records.
Architecture
The project aims to implement the principles of clean architecture, which focuses on creating systems that are easy to understand, maintain, and enhance. Clean architecture separates the system into different layers, each with distinct responsibilities, promoting modularity and scalability. For those unfamiliar with clean architecture, ample resources such as blog articles by renowned experts are available to explain these concepts.
Practical Use Case: Creating an Account
An illustrative example within this architecture is the process of creating a new account. The architecture facilitates a seamless integration of various layers to manage and execute this process effectively.
Requirements and Dependencies
To run Go Clean Architecture, users need to have Docker and Docker-compose installed on their systems.
Getting Started
To get started with Go Clean Architecture, follow these simple commands:
-
Initialize Environment Variables:
make init
-
Start the API in Development Mode:
make up
-
Run Tests within a Container:
make test
-
Run Tests Locally (Requires Golang installed):
make test-local
-
Run Coverage Reports:
make test-report
make test-report-func
-
View Logs:
make logs
API Endpoints
The application provides several API endpoints to interact with its functionalities:
Endpoint | HTTP Method | Description |
---|---|---|
/v1/accounts | POST | Create accounts |
/v1/accounts | GET | List accounts |
/v1/accounts/{{account_id}}/balance | GET | Find balance account |
/v1/transfers | POST | Create transfer |
/v1/transfers | GET | List transfers |
/v1/health | GET | Health check |
Testing API Endpoints with curl
Here's how to use curl
to test various API endpoints:
-
Creating a New Account:
- Request:
curl -i --request POST 'http://localhost:3001/v1/accounts' \ --header 'Content-Type: application/json' \ --data-raw '{ "name": "Test", "cpf": "070.910.584-24", "balance": 100 }'
- Response:
{ "id":"5cf59c6c-0047-4b13-a118-65878313e329", "name":"Test", "cpf":"070.910.584-24", "balance":100, "created_at":"2020-11-02T14:50:46Z" }
- Request:
-
Listing Accounts:
- Request:
curl -i --request GET 'http://localhost:3001/v1/accounts'
- Response:
[ { "id": "5cf59c6c-0047-4b13-a118-65878313e329", "name": "Test", "cpf": "070.910.584-24", "balance": 100, "created_at": "2020-11-02T14:50:46Z" } ]
- Request:
-
Fetching Account Balance:
- Request:
curl -i --request GET 'http://localhost:3001/v1/accounts/{{account_id}}/balance'
- Response:
{ "balance": 100 }
- Request:
-
Creating a New Transfer:
- Request:
curl -i --request POST 'http://localhost:3001/v1/transfers' \ --header 'Content-Type: application/json' \ --data-raw '{ "account_origin_id": "{{account_id}}", "account_destination_id": "{{account_id}}", "amount": 100 }'
- Response:
{ "id": "b51cd6c7-a55c-491e-9140-91903fe66fa9", "account_origin_id": "{{account_id}}", "account_destination_id": "{{account_id}}", "amount": 100, "created_at": "2020-11-02T14:57:35Z" }
- Request:
-
Listing Transfers:
- Request:
curl -i --request GET 'http://localhost:3001/v1/transfers'
- Response:
[ { "id": "b51cd6c7-a55c-491e-9140-91903fe66fa9", "account_origin_id": "{{account_id}}", "account_destination_id": "{{account_id}}", "amount": 100, "created_at": "2020-11-02T14:57:35Z" } ]
- Request:
Git Workflow
The project follows the Gitflow workflow, a branching model which allows for organized management of feature development, releases, and hotfixes.
Current Status
The project is currently in development, and users can expect ongoing improvements and enhancements.
Author
The Go Clean Architecture project was developed by Gabriel Sabadini Facina, who shares his work and contributions on GitHub.
License
This project is licensed under the MIT License, granting users freedom to use, modify, and distribute the software while promoting an open-source community.
By providing a clear and organized structure to its facilities, Go Clean Architecture stands as a robust tool, suitable for those looking to efficiently handle banking operations within a clean architectural framework.