Replicant Detector: A Common Lisp and Datastar Demo
The Replicant Detector is a technical demonstration that integrates Common Lisp, Datastar, and the BKNR datastore to showcase a high-performance, reactive web application architecture. The project serves as a demo for a Datastar SDK for Common Lisp, implementing a Command Query Responsibility Segregation (CQRS) pattern via a single GET stream and multiple POST commands.
Architecture and Technical Stack
The application utilizes a specific set of technologies to achieve real-time updates and persistent storage:
- Common Lisp: The core programming language used for the backend logic.
- Datastar: A hypermedia-driven framework used to manage the frontend reactivity.
- BKNR Datastore: Used as the persistent storage layer for the application's data.
- CQRS Pattern: Following the "Datastar Tao," the application separates read and write operations. It uses a single GET stream for updates and multiple POST commands for state changes.
Real-Time Updates and SSE Implementation
To support the reactive nature of the application, the developer implemented several low-level enhancements to the Common Lisp ecosystem:
- Server-Sent Events (SSE): The application uses SSE to push updates to the client. To prevent blocking the event loop, the developer integrated modifications into the Woo web server (via Clack) to support user channels.
- Event Pool: The use of user channels allows the application to utilize an event pool, which is essential for the CQRS implementation where notifications are sent without stalling the server.
- Brotli Compression: As a side effect of developing this demo, the author created a cl-brotli library to provide Brotli compression support for Common Lisp.
Application Features and Interface
The Replicant Detector is themed as a "Replicant Registration Database" for the Tyrell Corp Blade Runner Division. The interface provides a real-time tracking system with the following capabilities:
- Unit Tracking: A database of replicants categorized by model (Nexus-6, Nexus-7, Nexus-8), role (e.g., Combat, Infiltrator, Loader), and status (At-Large or Retired).
- Orbital Tracking: A visual map using an SVG-based equirectangular projection (utilizing GeoLite2-City data) to show last known positions.
- Field Agent Activity Log: A real-time log that tracks agent sightings and retirement actions (e.g., "Agent S8XLQ08416 (United States): RETIRE N6FAB61216").
Development Context
This project is part of a broader effort to create a Datastar SDK for Common Lisp and an accompanying interactive guide on the "hyper-guide" at lambda-combine.net. The author notes that the implementation is part of a work-in-progress (WIP) and is intended to demonstrate the viability of these tools in a modern, reactive web context.