Building an online booking application to sell their products.
├───audit-service
│ ├───api // handler incoming request
│ ├───config
│ ├───db
│ ├───dto
│ ├───logic
│ ├───storage // maping entity
│ └───utils
├───booking-service
│ ├───api
│ ├───config
│ ├───db
│ │ └───migrations
│ ├───dto
│ ├───logic
│ ├───repo
│ ├───restclient
│ ├───storage
│ └───utils
├───doc
│ ├───image
│ └───planuml
└───webapp
├───assets
├───css
└───js
In current solution. I only use single database for 2 service: booking-service and audit-service. For best practice, We should split to 2 database independenly:
- bookingdb: branchs, product table.
- auditdb: audits.
-
Golang >= 1.20
-
PostgresSQL
-
Golang Migration CLI
go install -tags 'postgres' github.com/golang-migrate/migrate/v4/cmd/migrate@latest -
Creat database with name bookingdb
-
Download all package for booking service
cd booking-service go mod tidy -
Run migration data, change database server info on your machine.
migrate -database postgres://{user}:{pass}@{host}/bookingdb?sslmode=disable -path db/migrations upIn case You do not use migration cli, please run manualy all script in db/migrations
-
Download all package for audit service
cd audit-service go mod tidy
- Booking-service
-
Change file booking-service/.env.example to booking-service/.env and change database info for postgres sql:
DATABASE_URL=postgres://{user}:{pass}@{host}:5432/bookingdb AUDIT_SERVICE=http://localhost:8081 PORT=8080Note that: In case we do not config AUDIT_SERVICE enviroiment parameter, the booking-savice will save audit info to database directly without call audit-service api.
-
Start booking-service:
go run main.go
- Audit-service
- Change file booking-service/.env.example to booking-service/.env and change database info for postgres sql:
DATABASE_URL=postgres://{user}:{pass}@{host}:5432/bookingdb - Start audit-service:
go run main.go
-
Run web
-
Unit test
- Some test case was implemented in booking-service/logic:
cd booking-service/logic go test -v
- Database
- Using PostgresSQL for reason:
- It was used popular
- Support dynamic type as json, can query with json format
- Relational database.
- Using PostgresSQL for reason:
- Arch
- Apply micro-service arch for easy to scale, and easy to maintaince, and also we are clearly the boundary context: booking and audit.
- Application
- Only focus one thing: make the application/service become abstraction as much as posiple:
- Follow SOLID principle to implement service
- Apply DI for easy to maintain and testing
- Only focus one thing: make the application/service become abstraction as much as posiple:
Gorm: MIT License
Gin: MIT License
DotEnv: MIT License





