DEV Community

Chris Warner
Chris Warner

Posted on

Building a Neo4j NIF for Elixir: When the Ecosystem Doesn't Have What You Need

I'm building Grimoire, a tool that helps story writers create AI-powered content for games. Writers define quests, locations, and narrative guardrails—then the system generates infinite personalized content for players.

The Graph Database Problem

Story data is inherently relational. The connections between characters, locations, and plot points matter more than the nodes themselves. A traditional relational database doesn't capture this well.
Neo4j made sense. I needed to store story graphs and traverse them efficiently. For production, that meant Neo4j Aura with SSL connections.

The Driver Problem

I'm building Grimoire in Elixir. When I tried the existing Neo4j drivers:
The official driver: Unmaintained, doesn't support modern Neo4j versions
bolt_sips: Couldn't handle Aura's SSL connection requirements (bolt+s:// protocol)
I was stuck.

The Wrong Solution

My first instinct: build a gRPC service as a proxy. Elixir talks to the service, service talks to Neo4j.
I started implementing it, but something felt wrong. I was building a relationship database repository pattern when what I actually needed was graph traversal. I wanted to write Cypher queries and get graph results back—not abstract it away behind an API.

The Right Solution: Rust NIFs

After some research, I discovered Rustler makes it straightforward to build Native Implemented Functions (NIFs) for Elixir. And because it's Rust, I get type safety and memory safety.
I found neo4rs, a well-maintained Rust driver for Neo4j that supports everything I need—including Aura's SSL connections.
The NIF setup was easier than expected. Now I'm working through the neo4rs Row API implementation to properly return query results to Elixir.
Current Status
Working:

✅ Connections to Neo4j (including Aura)
✅ Query execution framework
✅ Comprehensive type conversion for Neo4j types

In progress:

🚧 Row API implementation for returning actual results

Repo: https://github.com/chwarner-solo/neo4j_nif
I'm building this in public. If you've worked with neo4rs or have experience building Elixir NIFs for database drivers, I'd love your input.
This library will be published to Hex once the Row API is complete—the Elixir ecosystem needs a maintained Neo4j driver.

Tags: #elixir #rust #neo4j #buildinginpublic #nif

Top comments (0)