Table of Contents
Do not index
Do not index
This is my journey of building a Nostr relays service in the cloud
So, first of all, there are a lot of relays on the market. Why do I want to create a new one?
- I aim to create a new Java relay and a platform to create private/paid relays stored in the cloud (AWS).
- I intend to create my own to experiment with the Nostr protocol end to end. I have already started implementing a Nostr client, nostrsky.com, and a relay is what I need to understand the Nostr protocol end to end.
- Another reason is the fact that there are not so many Java implementations. People think that Java is old and not good for Nostr? But I believe that Java is keeping pace with the other languages.
- And there is another personal reason. I want to keep pace with modern Java. All these are fresh in 2023: Spring 6, SpringBoot 3, and Java JDK 20, Jakarta EE 10.
My inspiration for the technologies I want to use is in this presentation:
The Nostr relays on the market.
Here are some statistics about the existing Nostr relays:
Here is a good description of the relay's relevance on the market:
What is a Nostr relay?
By definition, a relay stores Nostr events sent by clients and accept subscriptions from clients. Events are like this (in this case, we have an event of type 0 → meta-data):
It can filter and offer search for events: profiles, notes, etc. Also can offer anti-spam support.
The relays can be paid at https://relay.exchange or not. A list of worldwide relays is here: https://nostr.watch/relays/find
Relays browsers:
Starting the project
I decided to use SpringBoot 3 (Spring Framework 6) and Java JDK 20 to build the relays service. See this URL: https://spring.io
Some reasons:
- support for Graal VM (native - improve startup time and lower usage of memory)
- ready for virtual threads (Loom project - improvements of runtime speed)
There is a very convenient way to start a project with Sprin Boot, but I can’t use it now:
- JHipster - https://www.jhipster.tech
- It has scaffolding for the UI
- but is not migrated to the new SpringBoot 3 / Spring 6
The lite version of JHipster is a good candidate because it already has the new Spring 6 / SpringBoot 3
- JHipster Lite - https://www.jhipster.tech/jhipster-lite
- clean architecture, incremental development
Playing with existing Java libraries for Nostr
So, I search the entire github.com, and I get just one Java library for working with Nostr protocol, and I don’t like it very much. Github: I https://github.com/tcheeric/nostr-java
- it uses lombock which has no future after Java introduced records (I used lombok in the past, but now it is obsolete)
- too much inheritance in the domain model (this is a sin of the academic world - in real projects, the composition is preferred)
- the way the project is structured, the maven sub-project is also not the best (it is better to be structured on NIPs)
- in-house JSON encoder/decoder is needed?
I started to browse fiatjaf repositories on github.com. Maybe I can find something better:
If not, I will use this library and try to create a better one afterward.
Bootstrapping the project
I initiated the project using Spring Initializr with some libraries: web sockets, persistence, and others.
I initialized a similar project but with JHipster Lite.
I have to decide which of them to use to bootstrap my project!
A few days later….
I decided to use JHipster Lite because:
- it has already Spring Boot inside 🦾
- it has already UI (Angular) support
- extra utilities
But, I will use Clean Architecture and not Hexagonal Architecture. They are similar as the final goal, but I like Uncle Bob's approach more.
And see here the trends:
I’m inspired by the following:
spring-shoestore
Github
spring-shoestore
Owner
spemberUpdated
Aug 30, 2023NEXT STEPS
- implement a first version of a relay server
- create a new feature in JHipster around the Nostr events (JHipster is generating just a dummy feature as a simple business example)
- save the events in different data sources: Postgres, Firebase, etc
- expose a relay on a web socket: https://docs.spring.io/spring-framework/reference/web/websocket/server.html
- play with Nostr Java: https://github.com/tcheeric/nostr-java
- test the relay with integration tests
- integrate the relay with an existing client
- publish the relay service in AWS
- create support for external users to create relays (public and private)