How mpwsh/smol-kv works
Main Components
• HTTP Server Component: Represent the actix-web server that listens on a configurable port (default port 5050) and provides the REST API interfaces. This is driven by the main.rs and supported by various route handlers (e.g., auth.rs, collection.rs, middleware.rs).
▸ Collection management (collection.rs)
▸ Key-value operations (key.rs, sub.rs)
▸ Middleware (middleware.rs) for handling authentication (the “X-SECRET-KEY” header) and possibly logging or error handling (error.rs)
• Storage Layer: Denote RocksDB as the underlying storage engine. Indicate that this component is connected to the API endpoint for actual persistence. You might also note that an sst.rs module is likely involved in reading/writing SST files for backups.
• Auxiliary/Utility Components: Include supporting modules such as:
▸ Benchmark support (benchmark folder) for performance testing.
▸ Scripts and Dockerfiles for deployment and binary size stripping (e.g., scripts/strip-bins.sh).
▸ CI configuration (GitHub workflows) to show continuous integration and build configuration.
Relationships and Interactions
• Auth/Middleware Layer: Inside the server, requests pass through middleware (e.g., authentication and logging) before hitting the route handlers.
• API Routing: Break out the main route handlers for:
▸ Collection CRUD operations (create collections, add a key, update or delete key, list keys/values).
▸ Batch operations and JSONPath querying.
▸ Backup and restore operations.
• Event/Subscription Mechanism: Show a connection path for real-time event notifications (subscribe endpoint) that feeds back to clients.
Architectural Patterns and Design Principles
• Separation of Concerns: Emphasize that the project separates HTTP request handling, business logic, and data storage.
• Modularity: Represent each module (for example, separate files in the src directory such as auth.rs, collection.rs, etc.) as distinct pieces loosely coupled by well-defined interfaces.
• Containerization and CI/CD: Include elements that denote deployment readiness (Dockerfile, GitHub workflows) and environment configuration via environment variables.
Relevant Technologies and Frameworks
• Rust as the primary programming language.
• actix-web for the HTTP server.
• RocksDB for persistent storage (with additional interfaces available via a RocksDB client).
• Docker for containerizing the application, with environment configuration influencing the server’s behavior.
• CI setup using GitHub Actions (as seen in .github/workflows) for automated testing and dockerization.