Service Design
As shown in this diagram, the Trend Service consumes “search book“ events from the queue, analyzes them and lists the “trendy“ books to the users.
Our trend service should have at least 2 components:
- Consumer: It consumes and analyzes events from the queue.
- API Server: It lists trends to the users.
We‘ll have 3 services in this tutorial, but we don‘t have to make 3 repositories since they're all written in Python. Let's try the monorepo.
Monorepo
A monorepo, short for "monolithic repository," is a software development approach where multiple projects or components of a system are stored within a single repository.
We need to structure the project like this:
.
├── LICENSE
├── README.md
├── requirements.txt
└── service
├── domain
│ └── model
│ ├── __init__.py
│ ├── book.py
│ └── trend.py
├── recommendation
│ └── main.py
├── trend
│ └── main.py
└── web
├── adapter
│ ├── router.py
│ └── templates
│ └── index.html
├── application
│ ├── __init__.py
│ ├── dto
│ │ ├── __init__.py
│ │ └── book.py
│ ├── executor
│ │ ├── __init__.py
│ │ └── book_operator.py
│ └── wire_helper.py
├── config.yml
├── domain
│ └── gateway
│ ├── __init__.py
│ └── book_manager.py
├── infrastructure
│ ├── config
│ │ ├── __init__.py
│ │ └── config.py
│ ├── database
│ │ ├── __init__.py
│ │ └── mysql.py
│ └── mq
│ ├── __init__.py
│ ├── helper.py
│ └── kafka.py
└── main.py
Restructure the folders and files
- Create service/ directory and move the whole web/ directory into service/.
- Create service/domain/model dir. We‘ll use it to put the public models for all 3 servcies.
- Move all files in service/web/domain/model to service/domain/model. Update its related import paths as well.
For example, in service/web/domain/gateway/book_manager.py:
...
from ....domain.model import Book
...