scalaconsultants / zio-scala2-quickstart.g8 Goto Github PK
View Code? Open in Web Editor NEWA Giter8 template for a fully functional, ready to deploy ZIO-based microservice.
License: Creative Commons Zero v1.0 Universal
A Giter8 template for a fully functional, ready to deploy ZIO-based microservice.
License: Creative Commons Zero v1.0 Universal
We've got two ActorSystem delivered by actorSystemLayer
and actorSystem
layers.
Invalid path: src/main/g8/src/main/scala/$package$/domain/$if(add_caliban_endpoint.truthy || add_server_sent_events_endpoint.truthy || add_websocket_endpoint.truthy)$Subscriber.scala$endif$
Developers not familiar with it could have a hard time understanding why services are defined in such way. Some documentation and references to original Zio pattern description won't hurt
Although all tests pass locally in all combinations of yes/no
, some random CI checks are failing each time (e.g. (yes, yes, yes)
passes but (yes, yes, no)
fails).
in main api Graphql directory is done without using of gitter8
add plugin zio-shield + fix issues found
Switch the template to PostgreSQL and Testcontainers for the integration tests.
We could follow instructions from https://hmemcpy.com/2020/08/running-postgres-integration-tests-easily-with-testcontainers-and-zio-test/ .
Use zio-logging
Need more detailed specification.
Use zio-test.
Research might be needed to integrate zio-test and akka testkit.
Change integration tests to cover only the repository layer (not the API).
That means removing ItApiSpec
and introducing ItemRepositorySpec
.
Having out of the box authentication would be useful. The question is what should we support and how much effort will the maintenance take? Are there any abstraction we could use?
Figure out a better way to model Item's states without Option[ItemId].
Optional endpoints were added without any test coverage
Remove dependency on Console from GraphQLApi. If needed replace with proper logging.
This line
zio.Runtime.default.unsafeRun(routeWithDependencies)
in src/main/scala/com/kzs/lab/ws/package.scala (line 15) blocks the theard until the result is ready and can seriously affect performance
Server should be able to start without the database running and make scheduled retries until the database is available.
Also if the database is unavailable at some point when the application is running, it shouldn't stop the server, but retry connection.
Using Delete in SlickRepository there are hidden runs of Event publishing which shouldn't be there. SlickRepository need to be agnostic of Events.
For this template to be useful we need a clear Readme.
Let's gather here what type of information should we put there.
Tests for Events are ignored because they were failing by timeout. Need investigation and fix. Probably problem with zio-akka-wrapper
It's highly probable that the DatabaseProvider in conjuntion with ZIOSupport is creating new connection on every HTTP request. This needs to be confirmed.
If yes, then a solution would be to introduce a connection pool (probably HikariCP as suggested in Slick documentation).
Unless other ideas come up.
We want users of the template to have a choice of database integration library. Right now it's only Slick. This ticket is about introducing Quill.
Repro:
(The following on a Mac.)
a fresh instantiation of this template
(which btw looks great, in general, thanks for putting it together.)
No code/config changes whatsoever
Run postgres in whatever way desired. Here, just using docker: docker run --name devdb -p 5432:5432 -e POSTGRES_DB=items -e POSTGRES_PASSWORD=12345 -d postgres:13
All good with the service via sbt
. In particular, output quickly shows:
[info] running zio_akka_quickstart.Boot
2021-10-23 16:50:01 INFO com.zaxxer.hikari.HikariDataSource - Starting...
2021-10-23 16:50:01 INFO com.zaxxer.hikari.HikariDataSource - Start completed.
2021-10-23 16:50:01 INFO akka.event.slf4j.Slf4jLogger Slf4jLogger started
Server online.
2021-10-23 16:50:02 INFO o.f.c.i.license.VersionPrinter Flyway Community Edition 7.14.0 by Redgate
2021-10-23 16:50:02 INFO o.f.c.i.d.base.BaseDatabaseType Database: jdbc:postgresql://localhost:5432/items (PostgreSQL 13.4)
2021-10-23 16:50:02 INFO o.f.core.internal.command.DbValidate Successfully validated 1 migration (execution time 00:00.020s)
2021-10-23 16:50:02 INFO o.f.core.internal.command.DbMigrate Current version of schema "public": 1
2021-10-23 16:50:02 INFO o.f.core.internal.command.DbMigrate Schema "public" is up to date. No migration necessary.
Flyway migration completed with: MigrateResult(7.14.0,items,List(),migrate,Some(1),None,None,List(),0)
and all requests are handled normally.
sbt docker:publishLocal
-generated image, things don't go as smoothly:$ docker run --name devzio -p 8080:8080 zio-akka-quickstart:0.1.0-SNAPSHOT
2021-10-23 23:57:17 INFO akka.event.slf4j.Slf4jLogger Slf4jLogger started
2021-10-23 23:57:17 INFO com.zaxxer.hikari.HikariDataSource - Starting...
2021-10-23 23:57:17 INFO com.zaxxer.hikari.HikariDataSource - Start completed.
Server online.
the immediate output doesn't show the Flyby and DB related lines as with sbt run
(probably OK).
Now, upon a request like curlie get http://localhost:8080/items
, one can see, after several seconds, the following service output:
2021-10-23 23:58:28 INFO akka.actor.ActorSystemImpl akka.actor.ActorSystemImpl(zio-akka-quickstart-system) Request timeout encountered for request [GET /items Empty]
2021-10-23 23:58:39 INFO akka.actor.ActorSystemImpl akka.actor.ActorSystemImpl(zio-akka-quickstart-system) items: Response for
Request : HttpRequest(HttpMethod(GET),http://localhost:8080/items,List(Timeout-Access: <function1>, Host, User-Agent: curl/7.71.1, Accept: application/json, */*),HttpEntity.Strict(none/none,0 bytes total),HttpProtocol(HTTP/1.1))
Response: Complete(HttpResponse(500 Internal Server Error,List(),HttpEntity.Strict(none/none,0 bytes total),HttpProtocol(HTTP/1.1)))
When generating the project we have a choice of library versions to go with. It doesn't really make sense as the chosen library might be totally incompatible with the template.
Better way is to stay always consistent and remove the choice.
Also add https://github.com/fthomas/scala-steward to this project (as long as it's able to keep track not only the project's dependencies but also of the template's dependencies).
It would be very useful if the generated app was docker ready.
Currently, as part of this quickstart, I could find REST(Akka), Graphql(Caliban).
Any thoughts on integrating Akka-GRPC or ZIO-GRPC?
Add Async API documentation to the optional WebSocket and SSE endpoints.
Also add an endpoint serving generated UI (from Async API Generator)
https://www.asyncapi.com/
Check if it's possible for scala-steward to monitor project-inside-project as is the case with giter8 templates.
https://github.com/fthomas/scala-steward
Split the application into three sub-projects:
Domain should not depend on other projects.
Infrastructure should depend on domain.
Api should depend on domain and infrastructure.
GET and HEAD healthchecks should be separated. HEAD healthcheck should not access the database. Its purpose is to just answer as fast as it can with the least resource utilization with the main use case being AWS ECS healtcheck access.
Use Caliban
Since now the project is opened and should be considered opensource - we can setup circle ci or something similar for free
It would be nice to have ready postgres by docker compose
Use zio-config
Refactor to use ZLayer.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.