A graph-native implementation for managing Nostr social relationships in Neo4j, providing Web of Trust (WoT) capabilities for the ORLY relay.
The Social Event Processor automatically processes Nostr events that define social relationships and stores them as a navigable graph in Neo4j. This enables powerful social graph queries, trust metrics computation, and relationship-aware content filtering.
When events are saved to the relay, the processor intercepts social event types and maintains a parallel graph of NostrUser nodes connected by relationship edges (FOLLOWS, MUTES, REPORTS). This graph is separate from the standard NIP-01 event storage, optimized specifically for social graph operations.
Creates or updates NostrUser nodes with profile information extracted from the event content:
Profile updates are applied whenever a newer kind 0 event is received for a pubkey.
Manages FOLLOWS relationships between users using an efficient diff-based approach:
This approach minimizes graph operations for large follow lists where only a few changes occur.
Manages MUTES relationships using the same diff-based approach as contact lists:
Creates REPORTS relationships with additional metadata:
Every relationship in the graph is linked back to the Nostr event that created it via a created_by_event property. This provides:
For replaceable event kinds (0, 3, 10000), the processor:
All graph operations are designed to be safely repeatable:
The social processor is called automatically by SaveEvent() for supported event kinds. No additional code is needed - simply save events normally and the social graph is maintained alongside standard event storage.
Find users within N degrees of separation from a trusted seed set:
Compute trust metrics based on the social graph:
Filter content based on social relationships:
Analyze community structure:
The implementation includes comprehensive tests covering:
To run the tests:
# Start Neo4j
cd pkg/neo4j
docker-compose up -d
# Set environment variables
export ORLY_NEO4J_URI="bolt://localhost:7687"
export ORLY_NEO4J_USER="neo4j"
export ORLY_NEO4J_PASSWORD="testpass123"
# Run tests
go test -v -run TestSocialEventProcessor
See TESTING.md for detailed test documentation.
The social graph consists of:
Nodes:
NostrUser - Represents a Nostr user with their pubkey and profile dataProcessedSocialEvent - Tracks which events have been processed and their statusRelationships:
FOLLOWS - User A follows User BMUTES - User A has muted User BREPORTS - User A has reported User B (with report type)All relationships include properties for event traceability and timestamps.
The social event processor is enabled by default when using the Neo4j database backend. No additional configuration is required.
To use Neo4j as the database backend:
export ORLY_DB_TYPE=neo4j
export ORLY_NEO4J_URI=bolt://localhost:7687
export ORLY_NEO4J_USER=neo4j
export ORLY_NEO4J_PASSWORD=your_password
Planned features include: