GigaBrain Examples#
This directory contains example applications demonstrating how to use GigaBrain's graph database capabilities.
Available Examples#
🧠 Basic Example - ✅ Working#
A simple, working example that demonstrates core GigaBrain functionality:
cd examples/basic-example
cargo run
Features demonstrated:
- Schema setup (labels, properties, relationships)
- Node creation with typed properties
- Relationship creation and traversal
- Graph querying and statistics
- Basic graph operations
Output:
🧠 GigaBrain Basic Example
=========================
📝 Creating nodes...
✅ Created Alice (Person)
✅ Created Bob (Person)
✅ Created TechCorp (Company)
🔗 Creating relationships...
✅ Alice works for TechCorp
✅ Bob works for TechCorp
✅ Alice knows Bob
🔍 Querying the graph...
📊 Total nodes: 3
👥 People in the graph:
- Bob (age: 25)
- Alice (age: 30)
🕸️ Alice's relationships:
- WORKS_FOR -> TechCorp
- KNOWS -> Bob
📈 Graph Statistics:
Nodes: 3
Relationships: 3
✨ Example completed successfully!
🌐 Social Network Example - ⚠️ In Development#
A comprehensive social network application (currently has compilation issues):
Planned Features:
- User registration and authentication
- Posts, likes, comments, shares
- Friend/follow relationships
- Recommendation engine
- Timeline and feed generation
- REST API with 20+ endpoints
- Graph visualization integration
Note: This example is currently being debugged and may not compile.
Getting Started#
- Prerequisites: Ensure you have Rust installed
- Choose an Example: Start with the basic example to understand core concepts
- Run the Example: Navigate to the example directory and run
cargo run - Explore the Code: Read the source code to understand the implementation
Key Concepts Demonstrated#
Schema Management#
// Setup labels, properties, and relationship types
let mut schema = graph.schema().write();
schema.get_or_create_label("Person");
schema.get_or_create_property_key("name");
schema.get_or_create_relationship_type("KNOWS");
Node Operations#
// Create and update nodes
let node_id = graph.create_node();
graph.update_node(node_id, |node| {
node.add_label(person_label);
node.properties.insert(name_prop, PropertyValue::String("Alice".to_string()));
})?;
Relationship Creation#
// Create relationships between nodes
graph.create_relationship(alice_id, bob_id, knows_rel)?;
Graph Traversal#
// Find relationships for a node
let relationships = graph.get_node_relationships(
node_id,
Direction::Outgoing,
Some(relationship_type)
);
Best Practices#
- Schema First: Always set up your schema before creating nodes
- Type Safety: Use strongly typed PropertyValue enums
- Error Handling: Properly handle GigaBrain errors
- Resource Management: Use appropriate lock scopes for schema operations
- Query Optimization: Leverage relationship direction and type filtering
Next Steps#
- Explore the working basic example
- Read the API documentation
- Try the CLI interface
- Build your own graph application!
For more examples and tutorials, see the GigaBrain documentation.