How aditya-ds-1806/dicedb-driver works
Project type and purpose
• This is a Node.js client library (driver) for DiceDB, an external in-memory database.
• Its goal is to expose a promise-based, high-performance API to send commands to DiceDB, manage connections, parse replies, and surface results or errors to the user.
File structure
• src/commands: individual Command classes (Set, Get, ZAdd, etc.) implementing each DiceDB protocol command.
• src/dicedb.ts + src/registry.ts: the main client class (DiceDBClient) and a registry mapping command Names to Command classes.
• lib/: compiled output (.js/.d.ts) mirroring core modules (Command, ConnectionPool, DiceDBSocket, Parsers, Validators).
• proto/ & dicedb-protos/: protocol buffer definitions and generated TypeScript types, used by Parsers to decode/encode wire messages.
• utils/: auxiliary Logger and helpers.
• scripts/codegen.ts: builds or updates the proto files.
• tests/ & examples/: validation and usage patterns.
• configuration and CI: .github/workflows, eslint.config.js, tsconfig.json, package.json.
Key README insights
• Emphasizes promise-based API, built-in connection pooling, clean modern interface.
Main components & interactions
a. User Application Layer
b. API / Client Layer
• DiceDBClient class (src/dicedb.ts): exposes connect(), disconnect(), and command methods.
• Registry: mapping of method names (ping, get, set…) to Command implementations.
c. Connection Pool
• ConnectionPool module: manages multiple logical connections for concurrency.
• Pool hands out Connection objects on each request.
d. Connection / Transport Layer
• DiceDBSocket: wraps a single TCP socket to the DiceDB server.
• Parsers: transforms incoming byte streams (using proto definitions) into JS objects or errors.
• Command instances: serialize user arguments into protocol buffers/messages.
e. Wire Protocol
• proto files (.proto, *.ts): message definitions, used by both codegen and parsers.
• scripts/codegen: generates TypeScript definitions, kept in proto/ and dicedb-protos/.
f. External Service
• DiceDB Server: remote host:port 7379.
g. Utilities & Support
• Validators: ensure arguments conform to protocol expectations before sending.
• Errors: custom error types returned on protocol or validation failures.
• Logger: optional instrumentation for debug/tracing.
h. Build & CI
• GitHub workflows: build, test, npm-publish.
• ESLint, TypeScript config, code coverage.
Architectural patterns & design principles
• Separation of concerns: API vs. pooling vs. transport vs. command serialization vs. parsing.
• Command pattern: each DiceDB command is a class implementing a uniform interface.
• Promise-based asynchronous flows: client methods return Promises resolved when parser completes.
• Code generation: proto→TypeScript ensures type-safe protocol handling.
• Layered design: user-facing → orchestration (pool) → transport → protocol.