Skip to content

Commit

Permalink
First architecture and structure draft
Browse files Browse the repository at this point in the history
Describe the directory layout and describe the architecture of a
greenfield microservice with mapping to our internal structures.

Change-Id: Ib20b84d04f54dd6013b4cb20dd3bf4a5e546483d
Signed-off-by: Roman Mohr <[email protected]>
  • Loading branch information
rmohr committed Oct 12, 2016
1 parent 723d4db commit 41098f0
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 1 deletion.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

## Hacking

Before you start coding, the [Project structure overview](docs/structure.md)
should help you understanding the project and the microservices layout.

### Setup

First make sure you have [govendor](https://github.com/kardianos/govendor)
Expand All @@ -21,6 +24,12 @@ export PATH=$PATH:$GOPATH/bin

### Building

First clone the project into your `$GOPATH`:

```bash

```

To build the whole project, type

```bash
Expand Down
53 changes: 53 additions & 0 deletions docs/structure.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# Project structure

```bash
cmd # all the app wiring and app specific data is here, but no logic
cmd/appA # first app
cmd/appA/README.md # info about function, deplying, testing, debugging, ...
cmd/appA/Dockerfile # to build a container
cmd/appA/appA.go # wire the app (all logic in pkg/appA)
cmd/appB # second app
cmd/appB/mydata # for packaging data with docker, put it the Dockerfile context
cmd/appB/mydata/sampleyaml.yaml
cmd/appB/appB.go # wire the app (all logic in pkg/apB)
cmd/appB/Dockerfile # to build a container
pkg # generally useful packages and app packages with logic are here
pkg/entities # entities for microservice internal use and microservice internal communication
pkg/entities/my_entity.go
pkg/middleware # go-kit middlewares can be stored here
pkg/middleware/my_middleware.go
pkg/appB # logic for appB
pkg/appB/rest # do the rest wiring
pkg/appB/services # app services (some bound to endpoints, some just used internally)
pkg/appB/endpoints # DTOs, encoding, decoding, closing the gap between external communication (e.g. REST and service calls)
pkg/stuff # this should be useful for all services
pkg/other_stuff # this should be useful for all services
```

# Microservice structure

## Communicating with the external world

| abstract layer | internal location | task | error codes | direction |
|--------------------------|-------------------|---------------------------------------------------|-----------------|-----------|
| REST LAYER | mux (gorilla) | routing | 500, 404, ... | request |
| REST LAYER | TODO | authentication | 401 | request |
| REST LAYER | decode (gokit) | unmarshal json/xml to RequestDTO | 400 | request |
| REST LAYER | decode (gokit) | syntactic validation of json/xml (govalidator) | 400 | request |
| TRANSPORT AGNOSTIK LAYER | endpoint (gokit) | RequestDTO to entity mapping | 500 | request |
| TRANSPORT AGNOSTIK LAYER | endpoint (gokit) | service parameter validation, precondition checks | 400, 404, 403 | request |
| SERVICE LAYER | internal service | service parameter validation (precond package) | 500 | request |
| SERVICE LAYER | internal service | execution | 500, ... (TODO) | request |
| TRANSPORT AGNOSTIK LAYER | endpoint (gokit) | execution result examination | 500, ... (TODO) | response |
| TRANSPORT AGNOSTIK LAYER | endpoint (gokit) | result to ResponseDTO mapping | 500 | response |
| REST LAYER | encode (gokit) | marshal json/xml to ResponseDTO | 500 | response |

## Microservice internal communication

TODO, but to describe the basic idea: There will be core entities which can be stored in etcd. These core entities belong to virt-controller.
All other componenets can ask virt-controller via it's REST api for data from etcd. virt-controller then provides a DTO representation. For instance a call for fetching all VMs would have the following flow:

1) REST GET /get/me/my/vms
2) virt-controller loads the VMs from etcd
3) virt-cntroller translates the VM into a v1.VM DTO representation
4) virt-controller returns this v1.VM representation to the caller
2 changes: 1 addition & 1 deletion pkg/virt-controller/services/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ package services
import (
"github.com/go-kit/kit/log"
"github.com/go-kit/kit/log/levels"
"html"
"io"
"kubevirt/core/pkg/entities"
"kubevirt/core/pkg/precond"
"strings"
"text/template"
"html"
)

type TemplateService interface {
Expand Down

0 comments on commit 41098f0

Please sign in to comment.