All Projects → CodelyTV → Scala Ddd Example

CodelyTV / Scala Ddd Example

Licence: mit
🎯 λ Hexagonal Architecture + DDD + CQRS applied in Scala using Akka HTTP

Programming Languages

scala
5932 projects

Projects that are alternatives of or similar to Scala Ddd Example

ecommerce
A project for exploring Akka with Scala
Stars: ✭ 24 (-72.09%)
Mutual labels:  akka, akka-http, sbt
Microservices Sample
Sample project to create an application using microservices architecture
Stars: ✭ 167 (+94.19%)
Mutual labels:  logstash, rabbitmq, logback
Pfelk
pfSense/OPNsense + ELK
Stars: ✭ 417 (+384.88%)
Mutual labels:  logstash, travis
Akka Http Session
Web & mobile client-side akka-http sessions, with optional JWT support
Stars: ✭ 429 (+398.84%)
Mutual labels:  akka, akka-http
Scala Logging
Convenient and performant logging library for Scala wrapping SLF4J.
Stars: ✭ 804 (+834.88%)
Mutual labels:  sbt, logback
scala-web-development
Scala Web 开发 - 使用 Akka
Stars: ✭ 42 (-51.16%)
Mutual labels:  akka, akka-http
Akka Grpc
Akka gRPC
Stars: ✭ 361 (+319.77%)
Mutual labels:  akka, akka-http
Akka Http Microservice
Example of http (micro)service in Scala & akka-http
Stars: ✭ 701 (+715.12%)
Mutual labels:  akka, akka-http
Scale
Another example of a REST API with Akka HTTP
Stars: ✭ 23 (-73.26%)
Mutual labels:  akka, akka-http
Spring Boot Microservice Eureka Zuul Docker
Spring-Boot rest microservices using Eureka, Zuul, Docker. Monitoring with logstash, logback, elasticsearch, kibana
Stars: ✭ 45 (-47.67%)
Mutual labels:  logstash, logback
Spark As Service Using Embedded Server
This application comes as Spark2.1-as-Service-Provider using an embedded, Reactive-Streams-based, fully asynchronous HTTP server
Stars: ✭ 46 (-46.51%)
Mutual labels:  akka, akka-http
typebus
Framework for building distributed microserviceies in scala with akka-streams and kafka
Stars: ✭ 14 (-83.72%)
Mutual labels:  akka, akka-http
kamon-akka-http
Kamon integration for metrics, context and distributed tracing with Akka HTTP
Stars: ✭ 75 (-12.79%)
Mutual labels:  akka, akka-http
Logstash Gelf
Graylog Extended Log Format (GELF) implementation in Java for all major logging frameworks: log4j, log4j2, java.util.logging, logback, JBossAS7 and WildFly 8-12
Stars: ✭ 360 (+318.6%)
Mutual labels:  logstash, logback
ssl-config
SSL configuration logic, extracted from Play's WS (for use in Akka et al).
Stars: ✭ 65 (-24.42%)
Mutual labels:  akka, akka-http
Akka Http Json
Integrate some of the best JSON libs in Scala with Akka HTTP
Stars: ✭ 530 (+516.28%)
Mutual labels:  akka, akka-http
Akka Http
The Streaming-first HTTP server/module of Akka
Stars: ✭ 1,163 (+1252.33%)
Mutual labels:  akka, akka-http
akka-http-actor-per-request
Example akka application that uses the actor per request model
Stars: ✭ 16 (-81.4%)
Mutual labels:  akka, akka-http
jwt-akka-http
An example how to implement a very simple authentication and authorization with Akka HTTP. Related to https://blog.codecentric.de/en/2017/09/jwt-authentication-akka-http
Stars: ✭ 23 (-73.26%)
Mutual labels:  akka, akka-http
Es Cqrs Shopping Cart
A resilient and scalable shopping cart system designed using Event Sourcing (ES) and Command Query Responsibility Segregation (CQRS)
Stars: ✭ 19 (-77.91%)
Mutual labels:  akka, akka-http

CodelyTV Scala HTTP API

License Build Status Coverage Status

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 traits as the domain contracts/ports in order to be implemented by the infrastructure adapters.

Contents

Endpoints

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.

Libraries and implementation examples

Feature Library Implementation examples
Build tool SBT Dependencies, configuration & build.sbt
Style formatting ScalaFmt Rules
HTTP server Akka HTTP Routes definition, server implementation,
Video POST controller & its corresponding acceptance test
JSON marshalling Spray JSON User & User attributes marshallers
Database integration Doobie Video repository & its corresponding integration test
Domain events publishing Akka RabbitMQ Publisher implementation & its corresponding integration test
Infrastructure management Docker Docker Compose definition
Logging ScalaLogging
+ Logback
+ Logstash encoder
Logback configuration, logger implementation & its corresponding integration test
Command line command Scopt Database tables creation script
Distribution/deploy SBT Native packager Build & deploy instructions
Continuous Integration Travis CI Travis definition
Acceptance tests Akka HTTP TestKit Previously specified acceptance tests
Integration tests ScalaTest Previously specified integration tests
Unit tests ScalaTest
+ ScalaMock
Video creator use case test
Continuous Integration Travis CI
+ SBT Coveralls
Travis definition

Environment setup

Install the needed tools

  1. Clone this repository: git clone https://github.com/CodelyTV/cqrs-ddd-scala-example.git cqrs-ddd-scala-example
  2. Download and install Docker compose. We'll need it in order to run all the project infrastructure.
  3. Download and install SBT

Prepare the application environment

  1. Copy the Docker environment variables config file and tune it with your desired values: cp .env.dist .env
  2. Start Docker and bring up the project needed containers: docker-compose up -d
  3. Create the database tables in your Docker MySQL container: sbt createDbTables

Run the tests and start the HTTP server

  1. Enter into the SBT console: sbt
  2. Run the tests: t
  3. Start the local server: app/run mooc-api (if you run the app from outside SBT: sbt "app/run mooc-api")
  4. Request for the server status: curl http://localhost:8080/status
  5. Take a look at the courses related to this repository (Spanish) just in case you're interested into them!

Pre-push Git hook

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.

Logs

We've added a logging mechanism thanks to logback and logstash-logback-encoder in order to:

  • Output the log records through the standard output channel (usually, your terminal :P)
  • Store the log records in JSON format in a log file available at var/log/app_log.json
  • Compress the historical log files into var/log/app_log-%d{yyyy-MM-dd}.gz files
  • Delete compressed historical logs older than 10 days

If you want more information on the logging policies and appenders, take a look at the logback.xml.

Deploy

We use SBT Native Packager in order to package the app in single Jar file that you can execute.

  1. Create the universal package: sbt universal:packageBin.
  2. Extract the generated zip: 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) format
    • lib/: All the project dependencies jar files.
  3. Run the main app binary:
    • Without specifying any parameters (OK for this example app): ~/var/www/codelytv-cqrs-ddd-scala-example-1.0/bin/codelytv-cqrs-ddd-scala-example
    • Specifying parameters for the JVM: ~/var/www/codelytv-cqrs-ddd-scala-example-1.0/bin/codelytv-cqrs-ddd-scala-example -Dconfig.resource=application/$CONFIG_PATH
    • Specifying application parameters: ~/var/www/codelytv-cqrs-ddd-scala-example-1.0/bin/codelytv-cqrs-ddd-scala-example -Dconfig.resource=application/$CONFIG_PATH -- -appParam

About

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!

License

The MIT License (MIT). Please see License for more information.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].