A modular design with clear separation of concerns
ShibuDB is a lightweight database system designed for high-performance storage and retrieval with vector search capabilities. The architecture follows a modular design pattern with clear separation of concerns.
┌─────────────────────────────────────────────────────────────┐
│ Client Applications │
└─────────────────────┬───────────────────────────────────────┘
│ TCP/JSON
┌─────────────────────▼───────────────────────────────────────┐
│ Network Layer │
│ ┌─────────────────┐ ┌─────────────────┐ ┌─────────────┐ │
│ │ TCP Server │ │ Connection │ │ Protocol │ │
│ │ │ │ Manager │ │ Handler │ │
│ └─────────────────┘ └─────────────────┘ └─────────────┘ │
└─────────────────────┬───────────────────────────────────────┘
│
┌─────────────────────▼───────────────────────────────────────┐
│ Query Engine │
│ ┌─────────────────┐ ┌─────────────────┐ ┌─────────────┐ │
│ │ Query Parser │ │ Query Router │ │ Response │ │
│ │ │ │ │ │ Builder │ │
│ └─────────────────┘ └─────────────────┘ └─────────────┘ │
└─────────────────────┬───────────────────────────────────────┘
│
┌─────────────────────▼───────────────────────────────────────┐
│ Authentication │
│ ┌─────────────────┐ ┌─────────────────┐ ┌─────────────┐ │
│ │ Auth Manager │ │ Role Manager │ │ Permission │ │
│ │ │ │ │ │ Checker │ │
│ └─────────────────┘ └─────────────────┘ └─────────────┘ │
└─────────────────────┬───────────────────────────────────────┘
│
┌─────────────────────▼───────────────────────────────────────┐
│ Storage Layer │
│ ┌─────────────────┐ ┌─────────────────┐ ┌─────────────┐ │
│ │ Space Manager │ │ Key-Value │ │ Vector │ │
│ │ │ │ Storage │ │ Storage │ │
│ └─────────────────┘ └─────────────────┘ └─────────────┘ │
└─────────────────────┬───────────────────────────────────────┘
│
┌─────────────────────▼───────────────────────────────────────┐
│ Index Layer │
│ ┌─────────────────┐ ┌─────────────────┐ ┌─────────────┐ │
│ │ B-Tree Index │ │ Vector Index │ │ Metadata │ │
│ │ │ │ (FAISS) │ │ Index │ │
│ └─────────────────┘ └─────────────────┘ └─────────────┘ │
└─────────────────────┬───────────────────────────────────────┘
│
┌─────────────────────▼───────────────────────────────────────┐
│ Persistence Layer │
│ ┌─────────────────┐ ┌─────────────────┐ ┌─────────────┐ │
│ │ WAL (Write- │ │ Data Files │ │ Checkpoint │ │
│ │ Ahead Log) │ │ │ │ Manager │ │
│ └─────────────────┘ └─────────────────┘ └─────────────┘ │
└─────────────────────┬───────────────────────────────────────┘
│
┌─────────────────────▼───────────────────────────────────────┐
│ File System │
└─────────────────────────────────────────────────────────────┘
The network layer handles all client communication via TCP connections.
The query engine is the central coordinator for all database operations.
The authentication system provides role-based access control.
The storage layer manages data persistence and retrieval.
The index layer provides fast data access patterns.
The persistence layer ensures data durability and recovery.
Client Request → Network Layer → Query Engine → Auth Check → Storage Layer → Index Update → WAL Write → Response
Client Request → Network Layer → Query Engine → Auth Check → Index Lookup → Storage Layer → Response
Client Request → Network Layer → Query Engine → Auth Check → Vector Index → Similarity Search → Response
ShibuDB organizes data into logical spaces (similar to databases in traditional systems).
Space: "users"
├── Key: "user:123:profile" → Value: {"name": "John", "email": "john@example.com"}
├── Key: "user:123:settings" → Value: {"theme": "dark", "notifications": true}
└── Key: "user:456:profile" → Value: {"name": "Jane", "email": "jane@example.com"}
Space: "products"
├── Key: "product:789:info" → Value: {"name": "Laptop", "price": 999.99}
└── Vector: "product:789:embedding" → Vector: [0.1, 0.2, 0.3, ...]
B-Tree Index: provides fast key-value lookups.
Key: "user:123:profile" → File Offset: 1024
Key: "user:123:settings" → File Offset: 2048
Key: "user:456:profile" → File Offset: 3072
Vector Index (FAISS): enables similarity search.
Space: "products"
├── Index Type: IVF (Inverted File)
├── Vector Dimension: 128
├── Number of Clusters: 100
└── Distance Metric: L2
shibudb_data.db
├── Header (Magic Number, Version, Metadata)
├── Data Blocks
│ ├── Block 1: Key-Value Pairs
│ ├── Block 2: Key-Value Pairs
│ └── ...
└── Footer (Checksum, Size)
shibudb_wal.db
├── Log Entry 1: {"op": "PUT", "space": "users", "key": "user:123", "value": "..."}
├── Log Entry 2: {"op": "DELETE", "space": "users", "key": "user:456"}
└── ...