unicod3 / horreum

Horreum, is an application to manage products and their stock informations.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Logo Horreum

From Wikipedia, the free encyclopedia;

A horreum (plural: horrea) was a type of public warehouse used during the ancient Roman period. Although the Latin term is often used to refer to granaries, Roman horrea were used to store many other types of consumables; the giant Horrea Galbae in Rome were used not only to store grain but also olive oil, wine, foodstuffs, clothing and even marble...

https://en.wikipedia.org/wiki/Horreum

Following the ancient Roman correspondence Horreum, is an application to manage products and their stock informations.

Contents

  1. Architectural Design

  2. Project structure

  3. Database Diagram

  4. Installation & Usage

  5. Key Concepts

    5.1 Services

    5.2 Server

    5.3 Rest API

    5.4 Events

    5.5 Migrations

    5.6 Testing

Architectural Design

Every application prone to the architectural changes while time goes on and needs changes and Horreum no exception to that, to address those concerns Horreum uses C4 Modelling.

In order to keep the architectural changes manageable over time, I've used C4-PlantUML to document architectural structure, they can be found under docs/c4model folder.

For the sake of the demo I only designed System Context and Container Level.

1.System Context 2.Horreum Container
drawing drawing

Project Structure

Horreum uses Standard Go Project Layout for the structural design.

Database Diagram

drawing

Installation & Usage

If you have the docker installed you can just run the command below, and it will do the rest

docker-compose up

After you complete the installation steps Horreum spins up an http server at the port 8080 you can just hit the link below to get start to use swagger:

http://localhost:8080/swagger/index.html

Key Concepts

Services

There are 4 internal services:

  • WarehouseService
  • OrderService
  • ArticleService
  • ProductService

Which implements their own interfaces:

  • WarehouseRepository
  • OrderRepository
  • ArticleRepository
  • ProductRepository

All the services implements CRUD operations over their related Struct.

Server

api/server package lets Horreum to spin up a HTTP and a Streaming server.

To handle the dependency injection it also introduces a Handler struct which can be used through the application runtime.

type Handler struct {
	WarehouseService *warehouse.WarehouseService
	OrderService     *order.OrderService
	ArticleService   *article.ArticleService
	ProductService   *product.ProductService
}

Rest API

Horreum uses Open API as api standard, every controller needs to have open api specs included by design, to give you a quick info you can see the below:

What is the OpenAPI Specification?

The OpenAPI Specification, formerly known as the Swagger Specification, is the world’s standard for defining RESTful interfaces. The OAS enables developers to design a technology-agnostic API interface that forms the basis of their API development and consumption.

https://swagger.io/solutions/getting-started-with-oas/

Events

Aside from the CRUD operations; Horreum spins up an streaming message bus over channels this helps Horreum to be more event driven.

Thus OrderService publishes a new Event whenever one of the below happens:

  • OrderCreated
    • Handler: Decreases the product stock information accordingly
  • OrderUpdated
  • OrderDeleted
    • Handler: Increases the product stock information accordingly

To provide streaming bus feature Horreum uses the github.com/ThreeDotsLabs/watermill projects and wraps that under the pkg/streamer package.

Migrations

Horreum uses pkg/dbclient package to handle migrations and database related tasks.

dbclient under the hood wraps up github.com/upper/db/v4 package and provides orm-like api to internal application.

Another aspect of the database is of course the managing the migrations, to do that Horreum uses github.com/pressly/goose/v3 package to manage them.

All the generated migrations can be found under the pkg/dbclient/migrations folder.

Testing

Horreum uses github.com/stretchr/testify to handle assertion inside the tests no need to mention that mocking is another important aspect of the testing to handle that need Horreum uses github.com/vektra/mockery library which can automaticaly generate mocks over existing interfaces.

About

Horreum, is an application to manage products and their stock informations.


Languages

Language:Go 99.3%Language:Makefile 0.5%Language:Dockerfile 0.3%