mikcar
Sidecar infrastructure services for mik.
Overview
mikcar provides HTTP-based infrastructure services for WASM handlers running in mik:
- Storage - Object storage (S3, GCS, MinIO, local filesystem)
- KV - Embedded key-value store (redb - pure Rust, no external dependencies)
- SQL - Database proxy (Postgres, SQLite)
- Queue - Message queues (Redis Streams, RabbitMQ)
- Secrets - Secret managers (Vault, AWS Secrets Manager, GCP Secret Manager)
- Email - SMTP email (works with any provider)
Same API works locally and in production. Your WASM handlers don't know or care if they're talking to MinIO or AWS S3.
Docker
Two optimized images available:
| Image | Size | Queue Support | Base |
|---|---|---|---|
mikcar |
~21MB | No | scratch (musl static) |
mikcar-all |
~65MB | Redis, RabbitMQ | distroless |
Pull from GitHub Container Registry
# Minimal image (no queue) - recommended for most use cases
# Full image with queue support
# Pull specific version
Run
Build locally
# Minimal image (no queue)
# Full image with queue support
Installation
# Install with default services (storage, kv, sql, secrets, email)
# Install with queue support
# Install specific services only
Usage
# Run storage service
STORAGE_URL=file:///data
# Run KV service (embedded redb, no external dependencies)
KV_URL=file:///data/kv.redb
# Run SQL service
DATABASE_URL=postgres://user:pass@localhost/db
# Run secrets service
SECRETS_URL=vault://localhost:8200
# Run email service
EMAIL_URL=smtp://localhost:1025
# Supercar mode (multiple services on one port)
API
Storage (/storage/*)
GET /object/{path} Get object
PUT /object/{path} Put object (body = content)
DELETE /object/{path} Delete object
HEAD /object/{path} Check exists + metadata
GET /list/{prefix} List objects
Key-Value (/kv/*)
GET /get/{key} Get value
POST /get/batch Get multiple (body = {keys: [...]})
POST /set/{key}?ttl= Set value (body = value)
POST /set/batch Set multiple (body = {key: value, ...})
DELETE /del/{key} Delete key
GET /keys/{pattern} List keys matching pattern
POST /increment/{key} Increment (atomic)
GET /exists/{key} Check if key exists
GET /ttl/{key} Get TTL (-1 = no TTL, -2 = not found)
POST /expire/{key} Set expiration (body = {seconds: N})
SQL (/sql/*)
POST /query Execute SELECT (body = {sql, params})
POST /execute Execute INSERT/UPDATE/DELETE
POST /batch Execute multiple statements in transaction
POST /script Execute JavaScript with SQL in transaction
SQL Script Endpoint
The /sql/script endpoint executes JavaScript code with SQL operations within a single database transaction. This enables complex conditional logic, validation, and multi-step operations with automatic rollback on failure.
Request:
Response:
Script API:
sql.query(sql, params)- Execute SELECT, returns array of row objectssql.execute(sql, params)- Execute INSERT/UPDATE/DELETE, returns rows affectedinput- The input object from the requestreturn- Specify the response value
Supported script formats:
// 1. Export default function (recommended)
export default
// 2. Raw code with return (simple scripts)
var users = sql.;
return ;
// 3. Raw expression (simplest)
sql.
Transaction semantics:
- All SQL operations run in a single transaction
- If the script throws an error, the transaction is rolled back
- If any SQL operation fails, the transaction is rolled back
- Only on successful completion is the transaction committed
Example: Fund transfer with balance check
export default
Queue (/queue/*)
POST /publish/{topic} Publish message
GET /subscribe/{topic} Long-poll for messages
POST /ack/{topic}/{id} Acknowledge message
POST /push/{queue} Push to work queue
GET /pop/{queue} Pop from work queue
Email (/email/*)
POST /send Send single email
POST /send/batch Send multiple emails
Request body (POST /send):
Response:
Batch request (POST /send/batch):
Authentication
Set SIDECAR_TOKEN or AUTH_TOKEN environment variable. Requests must include:
Authorization: Bearer <token>
The /health endpoint is always accessible without authentication.
Configuration
| Variable | Service | Example |
|---|---|---|
STORAGE_URL |
storage | file:///data, s3://bucket, memory:// |
KV_URL |
kv | file:///data/kv.redb, memory:// |
DATABASE_URL |
sql | postgres://user:pass@host/db |
QUEUE_URL |
queue | redis://host:port, amqp://user:pass@host:port |
SECRETS_URL |
secrets | vault://host:port, awssm://region, gcpsm://project |
EMAIL_URL |
smtp://host:port, smtps://user:pass@host:465 |
|
SIDECAR_TOKEN |
auth | Bearer token for API authentication |
Queue Backends
mikcar acts as an HTTP proxy to queue infrastructure. Supported backends:
| Backend | URL Format | Platform |
|---|---|---|
| In-memory | memory:// |
All |
| Redis Streams | redis://host:port |
Linux/macOS |
| RabbitMQ | amqp://user:pass@host:port |
Linux/macOS |
Auto-creation: Queues are automatically created on first push:
- Redis: Creates stream + consumer group (
XGROUP CREATE ... MKSTREAM) - RabbitMQ: Declares durable queue
No manual setup required - just push and pop.
Note: Queue requires the all feature or Dockerfile.all. Windows builds only support memory://.
# Redis
QUEUE_URL=redis://localhost:6379
# RabbitMQ
QUEUE_URL=amqp://guest:guest@localhost:5672
# In-memory (dev only)
QUEUE_URL=memory://
Email Backends
SMTP is the universal email protocol - works with any provider.
| Provider | URL Format |
|---|---|
| Local dev (Mailpit) | smtp://localhost:1025 |
| Gmail | smtps://user:app-password@smtp.gmail.com:465 |
| SendGrid | smtps://apikey:SG.xxx@smtp.sendgrid.net:465 |
| AWS SES | smtps://AKIA...:secret@email-smtp.us-east-1.amazonaws.com:465 |
| Resend | smtps://resend:re_xxx@smtp.resend.com:465 |
Port behavior:
- Ports 25, 1025, 2525: Plain SMTP (no TLS) - for local testing
- Port 465: Implicit TLS (
smtps://) - Port 587: STARTTLS (
smtp://)
# Local development with Mailpit
EMAIL_URL=smtp://localhost:1025
# Production with SendGrid
EMAIL_URL=smtps://apikey:SG.xxx@smtp.sendgrid.net:465
Library Usage
mikcar can be used as a Rust library to embed sidecars in your own applications (e.g., Tauri, Axum, or custom servers).
Add Dependencies
[]
= { = "https://github.com/dufeut/mikcar", = ["all"] }
= { = "1", = ["full"] }
Example: Single Service
use ;
async
Example: Multiple Services
use ;
async
Example: Tauri Integration
use ;
use Arc;
use Mutex;
async
Example: Combined with mik Runtime
use HostBuilder;
use ;
async
Exported Types
| Type | Description |
|---|---|
SidecarBuilder |
Builder for configuring and starting sidecars |
StorageService |
S3/GCS/Azure/local filesystem storage |
KvService |
Embedded key-value store (redb) |
SqlService |
PostgreSQL/SQLite proxy |
QueueService |
Redis Streams/RabbitMQ queues |
SecretsService |
Vault/AWS/GCP secret managers |
EmailService |
SMTP email sending |
Sidecar trait |
Implement custom sidecars |
Re-exported Crates
mikcar re-exports commonly used crates for convenience:
use axum; // Web framework
use tower; // Service abstractions
use tower_http; // HTTP middleware
License
MIT