SOCIAL_EVENT_PROCESSOR.md raw

Neo4j Social Event Processor

A graph-native implementation for managing Nostr social relationships in Neo4j, providing Web of Trust (WoT) capabilities for the ORLY relay.

Overview

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.

Supported Event Kinds

Kind 0 - Profile Metadata

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.

Kind 3 - Contact Lists (Follows)

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.

Kind 10000 - Mute Lists

Manages MUTES relationships using the same diff-based approach as contact lists:

Kind 1984 - Reports

Creates REPORTS relationships with additional metadata:

Key Features

Event Traceability

Every relationship in the graph is linked back to the Nostr event that created it via a created_by_event property. This provides:

Replaceable Event Handling

For replaceable event kinds (0, 3, 10000), the processor:

Idempotent Operations

All graph operations are designed to be safely repeatable:

Integration with Event Storage

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.

Use Cases

Web of Trust Queries

Find users within N degrees of separation from a trusted seed set:

Reputation Scoring

Compute trust metrics based on the social graph:

Content Filtering

Filter content based on social relationships:

Social Graph Analysis

Analyze community structure:

Testing

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.

Graph Model

The social graph consists of:

Nodes:

Relationships:

All relationships include properties for event traceability and timestamps.

Configuration

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

Related Documentation

Future Enhancements

Planned features include: