this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

at main 391 lines 9.3 kB view raw view rendered
1# GigaBrain Graph Database 2 3GigaBrain is a high-performance, in-memory graph database written in Rust, designed for efficient graph operations, complex queries, and real-time analytics. 4 5## Features 6 7- **High Performance**: In-memory storage with optimized data structures 8- **Cypher Query Language**: Full support for Neo4j-compatible Cypher queries 9- **Interactive CLI**: Comprehensive command-line interface with REPL and batch processing 10- **Graph Algorithms**: Built-in shortest path, centrality, community detection, and more 11- **Dual API**: Both REST and gRPC interfaces for maximum flexibility 12- **ACID Transactions**: Full transaction support with configurable isolation levels 13- **Persistence**: Optional RocksDB backend for data durability 14- **Authentication**: JWT-based authentication with role-based access control 15- **Monitoring**: Built-in metrics and observability features 16- **Data Import/Export**: JSON and CSV import/export capabilities 17 18## Quick Start 19 20### Installation 21 22```bash 23git clone https://github.com/your-org/gigabrain.git 24cd gigabrain 25cargo build --release 26``` 27 28### Running the Server 29 30```bash 31# Start both REST (port 3000) and gRPC (port 50051) servers 32cargo run --bin gigabrain 33``` 34 35### Using the CLI 36 37```bash 38# Build and start the interactive CLI 39cargo build --release --bin gigabrain-cli 40./target/release/gigabrain-cli 41 42# Execute a single command 43./target/release/gigabrain-cli --execute "CREATE (alice:Person {name: 'Alice', age: 30})" 44 45# Run commands from file 46./target/release/gigabrain-cli --file my_queries.cypher 47 48# Show graph statistics 49./target/release/gigabrain-cli stats 50``` 51 52### Basic Usage 53 54#### Using the CLI (Recommended) 55 56```cypher 57# Start interactive CLI 58gigabrain> CREATE (alice:Person {name: 'Alice', age: 30}) 59gigabrain> CREATE (bob:Person {name: 'Bob', age: 25}) 60gigabrain> MATCH (a:Person), (b:Person) WHERE a.name = 'Alice' AND b.name = 'Bob' 61 -> CREATE (a)-[:KNOWS]->(b) 62gigabrain> MATCH (p:Person)-[:KNOWS]->(friend) RETURN p.name, friend.name 63``` 64 65#### Using the REST API 66 67```bash 68# Check server health 69curl http://localhost:3000/api/v1/health 70 71# Create a node 72curl -X POST http://localhost:3000/api/v1/nodes \ 73 -H "Content-Type: application/json" \ 74 -d '{ 75 "labels": ["Person"], 76 "properties": [ 77 {"key": "name", "value": {"string_value": "Alice"}}, 78 {"key": "age", "value": {"int_value": 30}} 79 ] 80 }' 81 82# Execute a Cypher query 83curl -X POST http://localhost:3000/api/v1/cypher \ 84 -H "Content-Type: application/json" \ 85 -d '{ 86 "query": "MATCH (n:Person) RETURN n.name, n.age" 87 }' 88``` 89 90## Architecture 91 92### Core Components 93 94- **Graph Engine**: High-performance graph storage and traversal 95- **Query Engine**: Cypher parser and execution engine 96- **CLI Interface**: Interactive REPL and command-line tools 97- **Algorithm Library**: Graph algorithms for analytics 98- **API Layer**: REST and gRPC interfaces 99- **Storage Layer**: Memory and persistent storage backends 100- **Transaction Manager**: ACID transaction support 101- **Observability**: Metrics, tracing, and health monitoring 102 103### Performance 104 105- **Node Operations**: 1M+ operations/second 106- **Relationship Traversal**: Sub-millisecond response times 107- **Cypher Queries**: Optimized execution plans 108- **Memory Usage**: Efficient memory layout with minimal overhead 109- **Concurrent Access**: Lock-free data structures where possible 110 111## Use Cases 112 113### Social Networks 114- Friend recommendations 115- Community detection 116- Influence analysis 117- Content propagation modeling 118 119### Fraud Detection 120- Pattern recognition 121- Anomaly detection 122- Risk scoring 123- Network analysis 124 125### Knowledge Graphs 126- Semantic search 127- Recommendation engines 128- Data lineage tracking 129- Relationship discovery 130 131### Supply Chain 132- Route optimization 133- Dependency analysis 134- Impact assessment 135- Bottleneck identification 136 137## Configuration 138 139### CLI Configuration 140 141```toml 142# ~/.gigabrain/config.toml 143[cli] 144prompt = "gigabrain> " 145history_file = "~/.gigabrain/history" 146max_history = 2000 147output_format = "table" 148show_timing = true 149enable_completion = true 150 151[connection] 152rest_endpoint = "http://localhost:3000" 153grpc_endpoint = "http://localhost:50051" 154timeout = 30 155``` 156 157### Server Configuration 158 159```rust 160ServerConfig { 161 rest_port: 3000, 162 grpc_port: 50051, 163 max_connections: 1000, 164 request_timeout: Duration::from_secs(30), 165 enable_cors: true, 166 jwt_secret: "your-secret-key", 167} 168``` 169 170### Storage Configuration 171 172```rust 173// In-memory storage (default) 174let storage = MemoryStore::new(); 175 176// Persistent storage with RocksDB 177let storage = RocksDBStore::new("./data")?; 178``` 179 180### Authentication 181 182```rust 183// Generate JWT token 184let auth_service = AuthService::new("secret-key"); 185let token = auth_service.generate_token("user123", "ReadWrite", 24)?; 186 187// Validate token 188let claims = auth_service.validate_token(&token)?; 189``` 190 191## Documentation 192 193- [CLI and REPL Guide](./CLI.md) - Complete command-line interface documentation 194- [API Reference](./API.md) - REST and gRPC API documentation 195- [Architecture Guide](./ARCHITECTURE.md) - Technical architecture overview 196- [gRPC Protocol Buffers](../proto/gigabrain.proto) - Protocol buffer definitions 197- [Examples](./examples/) - Usage examples and tutorials 198 199## Benchmarks 200 201Performance benchmarks on a 16-core machine with 32GB RAM: 202 203| Operation | Throughput | Latency (p99) | 204|-----------|------------|---------------| 205| Node Creation | 1.2M ops/sec | 2ms | 206| Relationship Creation | 800K ops/sec | 3ms | 207| Single-hop Traversal | 2M ops/sec | 0.5ms | 208| Multi-hop Queries | 100K ops/sec | 15ms | 209| Shortest Path (6 hops) | 50K ops/sec | 25ms | 210| PageRank (1K nodes) | 1K ops/sec | 100ms | 211 212## Development 213 214### Building 215 216```bash 217# Debug build 218cargo build 219 220# Release build 221cargo build --release 222 223# With RocksDB support 224cargo build --features rocksdb-storage 225``` 226 227### Testing 228 229```bash 230# Run all tests 231cargo test 232 233# Run with RocksDB features 234cargo test --features rocksdb-storage 235 236# Property-based testing 237cargo test --test property_tests 238 239# Benchmarks 240cargo bench 241``` 242 243### Contributing 244 2451. Fork the repository 2462. Create a feature branch 2473. Add tests for new functionality 2484. Ensure all tests pass 2495. Submit a pull request 250 251### Code Style 252 253- Follow Rust standard formatting (`cargo fmt`) 254- Use `cargo clippy` for linting 255- Write comprehensive tests 256- Document public APIs 257 258## Deployment 259 260### Docker 261 262```dockerfile 263FROM rust:1.70 as builder 264WORKDIR /app 265COPY . . 266RUN cargo build --release 267 268FROM debian:bookworm-slim 269COPY --from=builder /app/target/release/gigabrain /usr/local/bin/ 270EXPOSE 3000 50051 271CMD ["gigabrain"] 272``` 273 274### Kubernetes 275 276```yaml 277apiVersion: apps/v1 278kind: Deployment 279metadata: 280 name: gigabrain 281spec: 282 replicas: 3 283 selector: 284 matchLabels: 285 app: gigabrain 286 template: 287 metadata: 288 labels: 289 app: gigabrain 290 spec: 291 containers: 292 - name: gigabrain 293 image: gigabrain:latest 294 ports: 295 - containerPort: 3000 296 - containerPort: 50051 297 env: 298 - name: JWT_SECRET 299 valueFrom: 300 secretKeyRef: 301 name: gigabrain-secrets 302 key: jwt-secret 303``` 304 305### Production Considerations 306 307- **High Availability**: Deploy multiple instances with load balancing 308- **Backup Strategy**: Regular snapshots for persistent storage 309- **Monitoring**: Use Prometheus metrics and distributed tracing 310- **Security**: Enable TLS, rotate JWT secrets regularly 311- **Resource Limits**: Configure memory and CPU limits appropriately 312 313## Monitoring and Observability 314 315### Metrics 316 317GigaBrain exposes Prometheus-compatible metrics: 318 319``` 320# Node and relationship counts 321gigabrain_nodes_total 322gigabrain_relationships_total 323 324# Query performance 325gigabrain_query_duration_seconds 326gigabrain_query_errors_total 327 328# API performance 329gigabrain_http_requests_total 330gigabrain_grpc_requests_total 331 332# System resources 333gigabrain_memory_usage_bytes 334gigabrain_cpu_usage_percent 335``` 336 337### Logging 338 339Structured logging with multiple levels: 340 341```rust 342use tracing::{info, warn, error}; 343 344info!(node_id = %node.id, "Node created successfully"); 345warn!(query = %cypher, duration_ms = %elapsed, "Slow query detected"); 346error!(error = %e, "Failed to process request"); 347``` 348 349### Tracing 350 351Distributed tracing support with OpenTelemetry: 352 353```rust 354use tracing_opentelemetry::OpenTelemetryLayer; 355 356// Configure tracing 357let tracer = opentelemetry_jaeger::new_pipeline() 358 .with_service_name("gigabrain") 359 .install_simple()?; 360``` 361 362## License 363 364This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details. 365 366## Support 367 368- **Documentation**: [docs/](./docs/) 369- **Issues**: [GitHub Issues](https://github.com/your-org/gigabrain/issues) 370- **Discussions**: [GitHub Discussions](https://github.com/your-org/gigabrain/discussions) 371- **Discord**: [Community Server](https://discord.gg/gigabrain) 372 373## Roadmap 374 375### Version 0.2.0 376- [ ] Distributed deployment support 377- [ ] Advanced query optimization 378- [ ] Real-time streaming APIs 379- [ ] Graph visualization tools 380 381### Version 0.3.0 382- [ ] Machine learning integration 383- [ ] Time-series graph support 384- [ ] Advanced security features 385- [ ] Cloud provider integrations 386 387### Version 1.0.0 388- [ ] Production-ready stability 389- [ ] Comprehensive documentation 390- [ ] Enterprise features 391- [ ] Professional support options