Skip to content
This repository has been archived by the owner on Dec 2, 2024. It is now read-only.

Commit

Permalink
Migrate to clean arch
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinmmartins committed Jul 13, 2024
1 parent d28b036 commit 6ea5c58
Show file tree
Hide file tree
Showing 30 changed files with 117 additions and 112 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/BuildApp.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ on:
branches:
- main
pull_request:
branches:
- main


jobs:
Expand Down
25 changes: 21 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,9 @@ The diagram contains:

## Architecture

This project follows the models proposed by Hexagonal Architecture
This project follows the models proposed by Clean Architecture

![Source: https://making.ndd.tech/reflex%C3%B5es-sobre-o-uso-de-orms-em-dom%C3%ADnios-complexos-parte-2-d7f0ac937121](https://miro.medium.com/v2/resize:fit:521/1*vrXUudR0NzRESXmZl_cHoA.png)
![Source: https://blog.geisonbiazus.com/static/image/architecture.png](https://blog.geisonbiazus.com/static/image/architecture.png)

## Swagger

Expand Down Expand Up @@ -114,11 +114,28 @@ The order of execution is:
2. secret > you should update the secret value with the database password
3. deployment
4. hpa
5. secret

5. service

You can forward the port with the following command:

```bash
kubectl port-forward svc/tech-challenge-service 4000:80 -n dev
```

### Kubernates Architecture

![Diagram](deploy/diagram/kubernates-diagram.png)

## Project structure

- `cmd`: Application entry point directory for the application's main entry points, dependency injection, or commands. The web subdirectory contains the main entry point to the REST API.
- `internal`: Directory to contain application code that should not be exposed to external packages.
- `core`: Directory that contains the application's core business logic.
- `cart`: Directory contains definition of the entity's heights, interfaces, repository and service of the entity Cart.
- `customer`: Directory contains definition of the entity's heights, interfaces, repository and service of the entity Customer.
- `order`: Directory contains definition of the entity's heights, interfaces, repository and service of the entity Order.
- `product`: Directory contains definition of the entity's heights, interfaces, repository and service of the entity Product.
- `adapters`: Directory to contain external services that will interact with the application core.
- `db`: Directory contains the implementation of the repositories.
- `rest`: Directory that contains the definition of the application's controllers and handlers for manipulating data provided by the controller
- `domainerrors`: Directory that contains the definition of the application's domain errors.
9 changes: 5 additions & 4 deletions cmd/http/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,17 @@ package main

import (
"fmt"
"github.com/pangolin-do-golang/tech-challenge/internal/application/cart"
"github.com/pangolin-do-golang/tech-challenge/internal/application/order"
"github.com/pangolin-do-golang/tech-challenge/internal/application/product"
"log"
"os"

"github.com/joho/godotenv"
_ "github.com/pangolin-do-golang/tech-challenge/docs"
dbAdapter "github.com/pangolin-do-golang/tech-challenge/internal/adapters/db"
"github.com/pangolin-do-golang/tech-challenge/internal/adapters/rest/server"
"github.com/pangolin-do-golang/tech-challenge/internal/core/cart"
"github.com/pangolin-do-golang/tech-challenge/internal/core/customer"
"github.com/pangolin-do-golang/tech-challenge/internal/core/order"
"github.com/pangolin-do-golang/tech-challenge/internal/core/product"
"gorm.io/driver/postgres"
"gorm.io/gorm"
)
Expand All @@ -29,7 +30,7 @@ func main() {
}

customerRepository := dbAdapter.NewPostgresCustomerRepository(db)
customerService := cart.NewService(customerRepository)
customerService := customer.NewService(customerRepository)

productRepository := dbAdapter.NewPostgresProductRepository(db)
productService := product.NewProductService(productRepository)
Expand Down
Binary file added deploy/diagram/kubernates-diagram.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
52 changes: 26 additions & 26 deletions docs/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ const docTemplate = `{
"post": {
"description": "Adds a Product to Customer's Cart",
"consumes": [
"application/json"
"core/json"
],
"produces": [
"application/json"
"core/json"
],
"tags": [
"Cart"
Expand Down Expand Up @@ -56,10 +56,10 @@ const docTemplate = `{
"post": {
"description": "Edits a Product from Customer's Cart",
"consumes": [
"application/json"
"core/json"
],
"produces": [
"application/json"
"core/json"
],
"tags": [
"Cart"
Expand Down Expand Up @@ -93,10 +93,10 @@ const docTemplate = `{
"post": {
"description": "Removes a Product from Customer's Cart",
"consumes": [
"application/json"
"core/json"
],
"produces": [
"application/json"
"core/json"
],
"tags": [
"Cart"
Expand Down Expand Up @@ -126,10 +126,10 @@ const docTemplate = `{
"get": {
"description": "Get all customer's list",
"consumes": [
"application/json"
"core/json"
],
"produces": [
"application/json"
"core/json"
],
"tags": [
"Customer"
Expand All @@ -150,10 +150,10 @@ const docTemplate = `{
"post": {
"description": "Create a new customer",
"consumes": [
"application/json"
"core/json"
],
"produces": [
"application/json"
"core/json"
],
"tags": [
"Customer"
Expand Down Expand Up @@ -191,10 +191,10 @@ const docTemplate = `{
"get": {
"description": "Get a customer by cpf",
"consumes": [
"application/json"
"core/json"
],
"produces": [
"application/json"
"core/json"
],
"tags": [
"Customer"
Expand Down Expand Up @@ -226,10 +226,10 @@ const docTemplate = `{
"put": {
"description": "Update a customer by id",
"consumes": [
"application/json"
"core/json"
],
"produces": [
"application/json"
"core/json"
],
"tags": [
"Customer"
Expand Down Expand Up @@ -272,10 +272,10 @@ const docTemplate = `{
"delete": {
"description": "Delete a customer by id",
"consumes": [
"application/json"
"core/json"
],
"produces": [
"application/json"
"core/json"
],
"tags": [
"Customer"
Expand Down Expand Up @@ -304,10 +304,10 @@ const docTemplate = `{
"get": {
"description": "Get all order's list",
"consumes": [
"application/json"
"core/json"
],
"produces": [
"application/json"
"core/json"
],
"tags": [
"Order"
Expand All @@ -328,10 +328,10 @@ const docTemplate = `{
"post": {
"description": "Create order from Cart",
"consumes": [
"application/json"
"core/json"
],
"produces": [
"application/json"
"core/json"
],
"tags": [
"Order"
Expand Down Expand Up @@ -369,10 +369,10 @@ const docTemplate = `{
"get": {
"description": "Get a order by ID",
"consumes": [
"application/json"
"core/json"
],
"produces": [
"application/json"
"core/json"
],
"tags": [
"Order"
Expand Down Expand Up @@ -407,10 +407,10 @@ const docTemplate = `{
"/product": {
"get": {
"consumes": [
"application/json"
"core/json"
],
"produces": [
"application/json"
"core/json"
],
"tags": [
"Product"
Expand Down Expand Up @@ -450,10 +450,10 @@ const docTemplate = `{
"/product/{id}": {
"delete": {
"consumes": [
"application/json"
"core/json"
],
"produces": [
"application/json"
"core/json"
],
"tags": [
"Product"
Expand Down
Loading

0 comments on commit 6ea5c58

Please sign in to comment.