Demo of how scalable implementation of Reddit-like service could be made in Scala to demonstrate some patterns and principles.
Goals and documentations are in docs directory. You can also start by looking at main and browsing code from there in your IDE.
AGPL - if I cannot make money out of it, nobody else will. (You know where to find me).
Achieved virtually all intended functionality:
- users domain, with simple permission system and GDPR (deleting users from DB, events' fields containing personal data are encrypted)
- discussions domain, with ability to subscribe to channels, having non-linear discussions, sorting posts by newest, most popular, most controversial
- commands are enqueued and then turned into events, events are projected into updates of SQL database (it would be possible to add other projections)
- API is documented using automatically generated Swagger
- all important parameters are configurable, users can decide whether they want to run or not API, users' domain projections or discussions' projections in each instance
Some small TODOs are left, a few things could be improved or refactored. Code could use some more documentation to explain design decisions and how utilities work.
Things that could be implemented:
- OAuth2 support
- full context search using ElasticSearch or Solr or similar
- some notification system
Things that are missing if this was a real project, but are out of scope intended for example app:
- reporting posts, comments and users to moderators
- automatically detecting illegal content to remove it and block offenders
- email validation
Building and testing requires java installed. Then
./sbt
downloads and runs sbt shell.
To run integration tests or local env you need docker and make:
make dev-bg # starts services in background
make dev-up # starts services in terminal (I suggest a separate tab/window)
Then it is possible to run it tests:
sbt> it:test
make dev-down # shuts down services
While in sbt with Docker started run
sbt:branchtalk> application/run --monolith
to start application in a fork. Ctrl+D to send shutdown signal.
OpenAPI will be available at:
http://localhost:8080/docs/index.html?url=/docs/swagger.json
Build docker image:
sbt:branchtalk> application/docker:publishLocal
Once the image is published you can:
make local-bg # or
make local-up
(If it fails I suggest running make dev-down
before running local env).
You can use Ctrl+D to gracefully shutdown service. Server will be available at http://localhost:8080 and Swagger at http://localhost:8080/docs/index.html?url=/docs/swagger.json .
Commons, each domain's published language and API are cross-compiled JVM+JS. This allows publishing the definitions for reuse with e.g. front-end Scala application which interprets Tapir endpoints into e.g. sttp calls to backend.
Definitions are aggregated as scalaJsArtifacts
so you could publish them all
locally with:
sbt:branchtalk> scalaJsArtifacts:publishLocal