Technologies | Project | Solution | Configuration | Build and Run | Developing
Gfood is an app for managing food delivery which was designed following a mudular monolith architecture. This project was based on this original monolith.
A modular monolith is an architecture more close to microsservices and therefore it has several benefits regarding reusability, dependency management, observability and teams workflow.
Gfood was designed in several modules, each with its own responsability:
- gfood-application: The app itself which depends on all modules to run.
- gfood-*-service: Domain service which provides business functionality.
- gfood-*-service-api: API definitions for consumers of the domain service.
- gfood-common: Common components reused by others.
- gfood-domain: Domain classes and repositories that map database structures.
- gfood-end-to-end-tests: Integration tests of all functionalities.
- gfood-flyway: Migrations that create gfood database structures.
- gfood-swagger: Swagger UI configuring all gfood APIs.
Each project generates its own jar file, which are dependencies of gfood-application. The following diagram shows gfood in terms of its services and related functionalities:
Gfood requires a mysql database for persisting data, so you have to configure an user and database as folows:
$ sudo mysql
CREATE USER 'user'@'%' IDENTIFIED BY '123456';
GRANT ALL PRIVILEGES ON *.* TO 'user'@'%' WITH GRANT OPTION;
exit
$ mysql -u user -p
CREATE DATABASE gfood;
exit
On building phase, the tables will be created by migrations configured using Flyway.
For building and testing, execute the script:
$ ./build-and-test.sh
For building and running, execute the script:
$ ./build-and-run.sh
The APIs will be available in Swagger-UI: http://localhost:8080/swagger-ui.html.
Adding more functionality to gfood requires following the steps below to maintain consistency with modular monolith architecture:
- Create a new spring boot project for the new service (ex: gfood-payment-service)
- Create a new spring boot project for the service api (ex: gfood-payment-service-api)
- Import the new ServiceConfig class in
GfoodApplication
- Create new domain classes and repositories inside
gfood-domain
- Create any common class inside
gfood-common
- Create new migrations inside
gfood-flyway
- Add unit tests inside the new service project
- Add integration tests inside gfood-end-to-end-tests
- Change scripts to build and test/run the new projects