位馃幆 Hexagonal Architecture + DDD + CQRS applied in Scala using Akka HTTP
Project showing up how you could implement a HTTP API with Scala.
This is the first iteration of the project where you will find a very Object Oriented approach. We've followed the Ports & Adapters (or Hexagonal Architecture) Software Architecture using trait
s as the domain contracts/ports in order to be implemented by the infrastructure adapters.
One of the goals of this project is to serve as an example for the course on Scala HTTP API (Spanish) illustrating how to implement several concepts you would commonly find in any production application. In order to accomplish so, we have implemented the following 5 endpoints:
GET /status
: Application status health check.POST /videos
: Create new video inserting it into the database and publishing the video_created
domain event to the message queue.GET /videos
: Obtain all the system videos.POST /users
: Create new user inserting it into the database and publishing the user_registered
domain event to the message queue.GET /users
: Obtain all the system users.git clone https://github.com/CodelyTV/cqrs-ddd-scala-example.git cqrs-ddd-scala-example
cp .env.dist .env
docker-compose up -d
sbt createDbTables
sbt
t
app/run mooc-api
(if you run the app from outside SBT: sbt "app/run mooc-api"
)curl http://localhost:8080/status
There's one Git hook included. It's inside the doc/hooks
folder and it will run the prep
SBT task before pushing to any remote.
This prep
task is intended to run all the checks you consider before pushing. At this very moment, it try to compile and check the code style rules with ScalaFmt.
You can define what this task does modifying the prep
task in the build.sbt
file. We like the approach of just running 1 single SBT task as the hook instead of multiple tasks because it's more efficient (the hook doesn't have to run SBT multiple times), and also because this way we can control the pre push tasks with the SBT alias defined at the build.sbt
without altering the hooks.
In order to install this hook, just cd doc/hooks
and run ./install-hooks.sh
.
We've added a logging mechanism thanks to logback and logstash-logback-encoder in order to:
var/log/app_log.json
var/log/app_log-%d{yyyy-MM-dd}.gz
filesIf you want more information on the logging policies and appenders, take a look at the logback.xml.
We use SBT Native Packager in order to package the app in single Jar file that you can execute.
sbt universal:packageBin
.unzip target/universal/codelytv-cqrs-ddd-scala-example-1.0.zip -d ~/var/www/
which will contain:
bin/
: All the executable binaries of our main classes in Unix and Windows (bat) formatlib/
: All the project dependencies jar files.~/var/www/codelytv-cqrs-ddd-scala-example-1.0/bin/codelytv-cqrs-ddd-scala-example
~/var/www/codelytv-cqrs-ddd-scala-example-1.0/bin/codelytv-cqrs-ddd-scala-example -Dconfig.resource=application/$CONFIG_PATH
~/var/www/codelytv-cqrs-ddd-scala-example-1.0/bin/codelytv-cqrs-ddd-scala-example -Dconfig.resource=application/$CONFIG_PATH -- -appParam
This hopefully helpful utility has been developed by CodelyTV and contributors.
We'll try to maintain this project as simple as possible, but Pull Requests are welcome!
The MIT License (MIT). Please see License for more information.