Skip to content

refactor: simplify nostr-java from 9 modules to 4 (v2.0.0)#515

Merged
tcheeric merged 2 commits intodevelopfrom
refactoring/design-simplification
Feb 24, 2026
Merged

refactor: simplify nostr-java from 9 modules to 4 (v2.0.0)#515
tcheeric merged 2 commits intodevelopfrom
refactoring/design-simplification

Conversation

@tcheeric
Copy link
Owner

Summary

  • Module consolidation: merged 9 modules (~180 classes) into 4 modules (~40 classes): nostr-java-core, nostr-java-event, nostr-java-identity, nostr-java-client
  • Unified event/tag model: GenericEvent is the sole event class (39 subclasses removed), GenericTag with List<String> params is the sole tag class (17 subclasses removed), Kinds utility replaces Kind enum, EventFilter builder replaces 14 filter wrappers
  • Hardened WebSocket client: NostrRelayClient with Virtual Thread dispatch, async APIs (connectAsync, sendAsync, subscribeAsync), Spring Retry, RelayTimeoutException, ConnectionState tracking, ReentrantLock (no VT pinning)
  • Dead code cleanup: deleted 21 additional unused classes (IContent, GenericEventConverter, HttpClientProvider, BaseAuthMessage, IKey, etc.), merged IKey into BaseKey, inlined HttpClientProvider into Nip05Validator
  • Documentation overhaul: all docs rewritten for 2.0 architecture — README, architecture guide, API reference, how-to guides, migration guide, troubleshooting

Test plan

  • mvn clean test passes (BUILD SUCCESS, all unit tests green)
  • mvn clean verify with Docker for integration tests
  • Verify GenericEvent build → sign → send workflow end-to-end
  • Verify EventFilter subscription workflow
  • Verify relay timeout throws RelayTimeoutException
  • Review documentation links are not broken

🤖 Generated with Claude Code

Implements the full design simplification (2.0.0):
- Merge 9 modules into 4: core, event, identity, client
- Remove 39 concrete event subclasses, 17 tag subclasses, 27 entities
- GenericEvent as sole event class, GenericTag with List<String> params
- Kinds utility replaces Kind enum, EventFilter builder replaces 14 filters
- NostrRelayClient with Virtual Threads, async APIs, Spring Retry
- RelayTimeoutException replaces silent empty-list returns
- java.util.HexFormat replaces hand-rolled hex encoding
- Delete 21 additional dead classes (IContent, GenericEventConverter, etc.)
- Merge IKey into BaseKey, BaseAuthMessage into BaseMessage hierarchy
- Overhaul all documentation for 2.0 architecture

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@tcheeric tcheeric requested a review from Copilot February 24, 2026 03:12
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR implements a major refactoring (v2.0.0) that simplifies nostr-java from 9 modules (~180 classes) to 4 modules (~40 classes). The changes consolidate event/tag models into a single GenericEvent and GenericTag approach, remove NIP helper classes, enhance the WebSocket client with async APIs and Virtual Thread dispatch, and overhaul documentation to reflect the new architecture.

Changes:

  • Consolidated modules: merged 9 modules into 4 (nostr-java-core, nostr-java-event, nostr-java-identity, nostr-java-client)
  • Unified event/tag model: removed 39 event subclasses and 17 tag subclasses in favor of GenericEvent and GenericTag
  • Enhanced WebSocket client: NostrRelayClient with Virtual Thread dispatch, async APIs, Spring Retry, and RelayTimeoutException
  • Dead code cleanup: deleted 21 unused classes and inlined dependencies
  • Documentation: rewrote all docs for 2.0 architecture

Reviewed changes

Copilot reviewed 135 out of 466 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
nostr-java-api/src/test/java/nostr/api/unit/*.java (18 files) Removed test files for deleted NIP helper classes
nostr-java-api/src/test/java/nostr/api/integration/*.java (5 files) Removed integration tests for deleted client/handler infrastructure
nostr-java-api/src/test/java/nostr/api/client/*.java (11 files) Removed unit tests for deleted WebSocket handler/dispatcher components
nostr-java-api/src/test/java/nostr/api/*.java (2 files) Removed test support classes for deleted API layer
nostr-java-api/src/main/resources/*.properties (2 files) Removed relay configuration files
nostr-java-api/src/main/java/nostr/config/*.java (3 files) Removed Spring configuration classes
nostr-java-api/src/main/java/nostr/api/service/*.java (2 files) Removed service layer abstractions
nostr-java-api/src/main/java/nostr/api/nip57/*.java (5 files) Removed NIP-57 (zap) helper classes
nostr-java-api/src/main/java/nostr/api/nip01/*.java (3 files) Removed NIP-01 helper builders
nostr-java-api/src/main/java/nostr/api/factory/*.java (6 files) Removed factory abstractions
nostr-java-api/src/main/java/nostr/api/client/*.java (5 files) Removed client management infrastructure
nostr-java-api/src/main/java/nostr/api/*.java (12 files) Removed NIP helper classes (NIP02-NIP99, EventNostr, NostrIF)
nostr-java-api/pom.xml Removed module POM (entire module deleted)
docs/*.md (9 files) Updated documentation for 2.0 architecture
MIGRATION.md Added 2.0 migration guide
CHANGELOG.md Added 2.0 release notes

Comment on lines 30 to 33
* **Sanitize Logs:** Ensure user input written to logs does not contain newline characters (`
`, ``) to prevent log forging.
* **Structured Logging:** Prefer structured logging (JSON) to mitigate format string attacks.

Copy link

Copilot AI Feb 24, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The markdown escaping appears incorrect here, making the newline character examples unreadable. The escaped sequences should be properly formatted as backtick-enclosed code: \n, \r.

Suggested change
* **Sanitize Logs:** Ensure user input written to logs does not contain newline characters (`
`, ``) to prevent log forging.
* **Structured Logging:** Prefer structured logging (JSON) to mitigate format string attacks.
* **Sanitize Logs:** Ensure user input written to logs does not contain newline characters (`\n`, `\r`) to prevent log forging.
* **Structured Logging:** Prefer structured logging (JSON) to mitigate format string attacks.

Copilot uses AI. Check for mistakes.
Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 6aff8c693f

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines 91 to 93
if (events.size() < maxEvents) {
events.add(event);
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Do not silently truncate relay responses at 10k events

This drops events once maxEventsPerRequest is reached without signaling an error, so callers can receive incomplete result sets while the request still appears successful. For large historical queries (or broad filters) this causes silent data loss and incorrect downstream state because the client cannot distinguish a complete response from a truncated one.

Useful? React with 👍 / 👎.

- Fix SECURE_CODING.md: replace "imani-bridge" with "nostr-java" and
  fix broken markdown escaping for \n, \r characters
- Fix GenericTagDecoder: preserve duplicate tag parameters (Nostr tags
  are positional arrays where repeated values are valid data)
- Fix EventFilter: deep-copy tagFilters map in constructor to prevent
  mutable state leaking from reused builders
- Fix NostrRelayClient: log warning when max-events-per-request limit
  is reached instead of silently dropping events

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@tcheeric tcheeric merged commit f662bdf into develop Feb 24, 2026
5 checks passed
@tcheeric tcheeric deleted the refactoring/design-simplification branch February 24, 2026 03:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants