- Windows 10 or Mac or Linux or Ubuntu, minimum memory requirement is 8 gb
- Go 1.16 or higher
- git
- Intellij Idea (Optional) or any other IDE for source code
- Download Go from (version depends on os) https://go.dev/dl/
- Set Go home (GO_HOME)
- Verify by typing on console go version
- Download intelij idea https://www.jetbrains.com/go/
There are different ways to run it locally:
- Import project into intelij idea for go and run from idea itself by right click on main.go
- Using command from console "go build" and "./hello-fresh-menu-planning-service" or "go run main.go"
- Using command from console "make docker.start"
In order to check application whether application is up or not you can hit the following url from local http://localhost:8080/swagger/index.html
Using command from console "ENV_PROFILE=test make test.integration"
Note: Integration tests are in inside package internal/adoptors/e2e_test, This is 1 integration test for few APIs, the idea is to demonstrate how testing can be done. so for others apis tests are ignored. (just for assignment purpose, since real production required with 80% coverage)
Using command from console "make generate.swagger"
currently, there are 3 profiles: default, docker, azure, you can add more based on env by keeping file on root folder such application-{profile_name}.yml
Service is deployed on Azure public cloud using docker, docker registry and postgres db (This is my public cloud)
- resource-group: jagwani-azure-resource-group
- location: centralus
- docker-registry: jagwaniazuredockerregistry
- docker-container: hellofreshaucontainer
- postgres-db-instance: azure-dev-postgres
so when you push the code on github it will automatically deploy on azure cloud which configured with above resources.
You can check with following swagger url.
http://azure-hellofresh-au-demo.eastus.azurecontainer.io:8080/swagger/index.html
Note: All apis are listed in swagger
- install azure cli using command: 'brew install azure-cli'
az login: 'login azure from command line'
create resource group by using following command 'az group create --name=jagwani-azure-resource-group --location=centralus'
create docker registry by using following command 'az acr create --resource-group jagwani-azure-resource-group --location centralus --name jagwaniazuredockerregistry --sku Basic'
create docker container on azure by using following command az container create --resource-group jagwani-azure-resource-group --name hellofreshaucontainer --image jagwaniazuredockerregistry.azurecr.io/hello-fresh-menu-planning-service --dns-name-label azure-hellofresh-au-demo --ports 8080
Get azure credentials by using following command
az ad sp create-for-rbac --name "myApp" --role contributor
--scopes /subscriptions/1cefad64-45a1-431d-af83-1478eb03a754/resourceGroups/jagwani-azure-resource-group
--sdk-auth
You can use above credentials to set up GitHub action or any pipeline where applicable.
The project structure is following the ddd hexagonal concept where packages are structured in adoptors, ports, infra and application For understanding hexagonal architecture please refer to the link or below link for getting bit of idea
http://tindaloscode.blogspot.com/2013/11/ddd-and-hexagonal-architecture.html
Here are the considerations while designing the apis:
- All orm mapping is inside in the infra package (infra are secondary adaptor whos goal is to communicate with external systems, such database or message system)
- Application folder contains ports, services and usecase
- Use cases are Individual usecase or flows which will used by FE and these use cases will further serve to the rest api via ports
- Ports can be in/out, but main goal here is to give access to the primary adoptors via ports such as rest apis
- Every use case will be places in separate go file. so different developers can work on different use case indepandly
- Service package will contain the business logic or any logic which can be used by use case or adoptors
- There is rest package which contains inside adaptor package, rest apis are primary adaptor
- There are dtos and mapper to convert request response objects into domain entities
- go (lang)
- gin (web framework for go)
- gorm (orm)
- docker
- docker-compose
- postgres
- swag
- jwt-go
- profiles
I have chosen gin over bee as web framework using following comparison
https://go.libhunt.com/compare-gin-vs-beego-astaxie
and GORM 2.0 over sqlx since it's rewritten from scratch, they improved many things (just for exploring purpose)