Skip to content

Commit

Permalink
chore: add preface
Browse files Browse the repository at this point in the history
  • Loading branch information
girdharshubham committed May 13, 2023
1 parent 05819d4 commit eb00fe0
Show file tree
Hide file tree
Showing 17 changed files with 262 additions and 45 deletions.
22 changes: 22 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Build Storm Shadow
on:
push:
branches:
- main
permissions:
contents: read
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up JDK 11
uses: actions/setup-java@v3
with:
java-version: '19'
distribution: 'graal'
cache: 'sbt'
- name: Run tests
run: sbt test
- name: Upload dependency graph
uses: scalacenter/sbt-dependency-submission@ab086b50c947c9774b70f39fc7f6e20ca2706c91
34 changes: 27 additions & 7 deletions .scalafmt.conf
Original file line number Diff line number Diff line change
@@ -1,7 +1,27 @@
version = "3.7.3"
runner.dialect = scala213
fileOverride {
"glob:**/shadow/src/main/scala/**" {
runner.dialect = scala3
}
}
version = 3.7.3
maxColumn = 120

align.preset = more
align.multiline = true
align.stripMargin = true

continuationIndent.defnSite = 2
assumeStandardLibraryStripMargin = true
danglingParentheses.preset = true
docstrings = JavaDoc
lineEndings = preserve
includeCurlyBraceInSelectChains = false
spaces.inImportCurlyBraces = false
optIn.annotationNewlines = true

rewrite.rules = [Imports, RedundantBraces, SortModifiers]
rewrite.imports.sort = original

docstrings.wrap = yes
docstrings.style = Asterisk

newlines.afterInfix = keep
rewrite.rules = [RedundantParens]
trailingCommas = "always"
runner.dialect = Scala213Source3
docstrings.wrapMaxColumn = 80
26 changes: 25 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,25 @@
# reactive-app-modernization-with-scala
# reactive-app-modernization-with-scala

## Project: Storm Shadow

The business people have just decided, without talking to tech at all 🤮, that they want to ship their product in the
next
10 hours - we only have 2 tech guys around, and we don't want to get fired, so we need to get this done real quick. We
will deliver this with [Nothing But Logic](https://www.kalix.io/) and remove all complexities of the back end by
inferring all infrastructure needs from our code.

Remember - We have to focus solely on the business logic of this extremely crude architecture they have provided us
with.

## Architecture

```mermaid
graph LR
A[Ingetor] --> B[Processor] --> C[Carrier]
D[Manager] -->|Manage Ingestion Rules| A
D -->|Manage Processing Rules| B
D -->|Manage Delivery Rules| C
U[User] --> D
```

> Seminar conducted for the graduating class of 2023[MCA] at Guru Gobind Singh Indraprastha University, New Delhi
51 changes: 47 additions & 4 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -1,11 +1,54 @@
import Dependencies._

ThisBuild / scalaVersion := "2.13.10"
ThisBuild / organization := "extremeprogramming"
ThisBuild / version := "1.0.0-M1"
ThisBuild / licenses += ("GPL", url("https://www.gnu.org/licenses/gpl-3.0.en.html"))
ThisBuild / developers += Developer(
"girdharshubham",
"Shubham Girdhar",
"girdharshubham@hotmail.com",
url("https://github.com/girdharshubham"),
)

lazy val auth = (project in file("auth"))
ThisBuild / javacOptions ++= Seq(
"-source",
"1.19",
"-target",
"1.19",
"-Xlint:unchecked",
"-Xlint:deprecation",
)

ThisBuild / scalacOptions ++= Seq(
"-deprecation",
"-encoding",
"UTF-8",
"-feature",
"-language:existentials",
"-language:higherKinds",
"-language:implicitConversions",
"-unchecked",
"-Xlint",
"-Ywarn-dead-code",
"-Ywarn-numeric-widen",
"-Ywarn-value-discard",
)

lazy val rams = (project in file("."))
.aggregate(manager, ingestor, processor, carrier)

lazy val manager = (project in file("manager"))
.enablePlugins(KalixPlugin)
.settings(
libraryDependencies ++= Seq(
"org.scalatest" %% "scalatest" % "3.2.15" % Test
)
libraryDependencies ++= Seq(scalatest),
)

lazy val ingestor = project in file("ingestor")
// .enablePlugins(KalixPlugin)

lazy val processor = project in file("processor")
// .enablePlugins(KalixPlugin)

lazy val carrier = project in file("carrier")
// .enablePlugins(KalixPlugin)
7 changes: 7 additions & 0 deletions carrier/src/main/scala/extremeprogramming/carrier/App.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package extremeprogramming.carrier

object App {
def main(args: Array[String]): Unit = {
println("Carrier Subsystem")
}
}
1 change: 1 addition & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
version: 3
7 changes: 7 additions & 0 deletions ingestor/src/main/scala/extremeprogramming/ingestor/App.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package extremeprogramming.ingestor

object App {
def main(args: Array[String]): Unit = {
println("Ingestor Subsystem")
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
syntax = "proto3";

package auth.api;
package extremeprogramming.manager.api;

import "google/protobuf/empty.proto";
import "kalix/annotations.proto";
Expand All @@ -26,9 +26,9 @@ message LogoutRequest {}
service AuthService {
option (kalix.codegen) = {
value_entity: {
name: "auth.UserEntity"
name: "extremeprogramming.manager.UserEntity"
entity_type: "users"
state: "auth.domain.UserState"
state: "extremeprogramming.manager.domain.UserState"
}
};
rpc Register(User) returns (google.protobuf.Empty);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
syntax = "proto3";

package auth.domain;
package extremeprogramming.manager.domain;

message UserState {
string userName = 1;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package auth
package extremeprogramming.manager

import kalix.scalasdk.Kalix
import extremeprogramming.manager.KalixFactory
import org.slf4j.LoggerFactory

// This class was initially generated based on the .proto definition by Kalix tooling.
Expand All @@ -10,7 +11,7 @@ import org.slf4j.LoggerFactory

object Main {

private val log = LoggerFactory.getLogger("auth.Main")
private val log = LoggerFactory.getLogger("manager.Main")

def createKalix(): Kalix = {
// The KalixFactory automatically registers any generated Actions, Views or Entities,
Expand All @@ -23,6 +24,6 @@ object Main {

def main(args: Array[String]): Unit = {
log.info("starting the Kalix service")
createKalix().start()
createKalix().start(): Unit
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package auth
package extremeprogramming.manager

import auth.api.User
import auth.domain.UserState
import extremeprogramming.manager.domain.UserState
import com.google.protobuf.empty.Empty
import kalix.scalasdk.valueentity.ValueEntity
import kalix.scalasdk.valueentity.ValueEntityContext
Expand All @@ -17,31 +16,31 @@ class UserEntity(context: ValueEntityContext) extends AbstractUserEntity {
override def emptyState: UserState = UserState()

override def register(
currentState: UserState,
user: auth.api.User
currentState: UserState,
user: extremeprogramming.manager.api.User,
): ValueEntity.Effect[Empty] =
effects.updateState(user.toDomain).thenReply(Empty())

override def login(
currentState: UserState,
loginRequest: auth.api.LoginRequest
currentState: UserState,
loginRequest: extremeprogramming.manager.api.LoginRequest,
): ValueEntity.Effect[Empty] = effects.reply(Empty())

override def logout(
currentState: UserState,
logoutRequest: auth.api.LogoutRequest
currentState: UserState,
logoutRequest: extremeprogramming.manager.api.LogoutRequest,
): ValueEntity.Effect[Empty] = effects.reply(Empty())

}

object UserEntity {
implicit class UserStateExtensions(val user: auth.api.User) extends AnyVal {
implicit class UserStateExtensions(val user: extremeprogramming.manager.api.User) extends AnyVal {
def toDomain: UserState = UserState(
userName = user.userName,
firstName = user.firstName,
lastName = user.lastName,
email = user.email,
enabled = user.enabled
enabled = user.enabled,
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package extremeprogramming.manager

import org.scalatest.matchers.should.Matchers
import org.scalatest.wordspec.AnyWordSpec

class UserEntitySpec
extends AnyWordSpec
with Matchers {

"UserEntity" must {

"have example test that can be removed" in {
val _ = UserEntityTestKit(new UserEntity(_))
pending
// use the testkit to execute a command
// and verify final updated state:
// val result = service.someOperation(SomeRequest)
// verify the reply
// val reply = result.getReply()
// reply shouldBe expectedReply
// verify the final state after the command
// service.currentState() shouldBe expectedState
}

"handle command Register" in {
val _ = UserEntityTestKit(new UserEntity(_))
pending
// val result = service.register(extremeprogramming.manager.api.User(...))
}

"handle command Login" in {
val _ = UserEntityTestKit(new UserEntity(_))
pending
// val result = service.login(extremeprogramming.manager.api.LoginRequest(...))
}

"handle command Logout" in {
val _ = UserEntityTestKit(new UserEntity(_))
pending
// val result = service.logout(extremeprogramming.manager.api.LogoutRequest(...))
}

}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package auth.api
package extremeprogramming.manager.api

import akka.actor.ActorSystem
import auth.Main
import com.google.protobuf.empty.Empty
import extremeprogramming.manager.Main
import kalix.scalasdk.testkit.KalixTestKit
import org.scalatest.BeforeAndAfterAll
import org.scalatest.concurrent.ScalaFutures
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
package auth
package manager

import auth.domain.UserState
import com.google.protobuf.empty.Empty
import kalix.scalasdk.testkit.ValueEntityResult
import kalix.scalasdk.valueentity.ValueEntity
import extremeprogramming.manager.UserEntity._
import extremeprogramming.manager.domain.UserState
import extremeprogramming.manager.{UserEntity, UserEntityTestKit}
import org.scalatest.matchers.should.Matchers
import org.scalatest.wordspec.AnyWordSpec
import UserEntity._

class UserEntitySpec extends AnyWordSpec with Matchers {

val girdharshubham = auth.api.User(
val girdharshubham = extremeprogramming.manager.api.User(
userName = "girdharshubham",
firstName = "Shubham",
lastName = "Girdhar",
email = "girdharshubham@hotmail.com"
email = "girdharshubham@hotmail.com",
)

"UserEntity" must {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package manager.api


import extremeprogramming.manager.Main
import kalix.scalasdk.testkit.KalixTestKit
import org.scalatest.BeforeAndAfterAll
import org.scalatest.concurrent.ScalaFutures
import org.scalatest.matchers.should.Matchers
import org.scalatest.time.Millis
import org.scalatest.time.Seconds
import org.scalatest.time.Span
import org.scalatest.wordspec.AnyWordSpec

// This class was initially generated based on the .proto definition by Kalix tooling.
//
// As long as this file exists it will not be overwritten: you can maintain it yourself,
// or delete it so it is regenerated as needed.

class AuthServiceIntegrationSpec
extends AnyWordSpec
with Matchers
with BeforeAndAfterAll
with ScalaFutures {

implicit private val patience: PatienceConfig =
PatienceConfig(Span(5, Seconds), Span(500, Millis))

private val testKit = KalixTestKit(Main.createKalix()).start()

"AuthService" must {

"have example test that can be removed" in {
pending
// use the gRPC client to send requests to the
// proxy and verify the results
}

}

override def afterAll(): Unit = {
testKit.stop()
super.afterAll()
}
}
Loading

0 comments on commit eb00fe0

Please sign in to comment.