How psmon/kopring-reactive-labs works
Project Type and Purpose
• This is a full-stack reactive application:
• A .NET Blazor front-end (BlazorWebApp) serving the UI and invoking APIs via HTTP, SSE, and WebSockets.
• A Kotlin + Spring WebFlux + Akka Actor back-end (KotlinBootReactiveLabs) exposing REST/SSE/WS endpoints, running an actor system for concurrency, and persisting state via R2DBC.
• A Kotlin-based shared model library (CommonModel) used to define message DTOs and domain objects consistently on both sides.
File Structure
• Top-level modules:
• BlazorWebApp – UI layer in C#/.razor files; JS utilities for SSE & WebSocket; CSS assets.
• CommonModel – Kotlin Gradle project packaging shared data models (SendTextMessage, ChatModels).
• KotlinBootReactiveLabs – Spring Boot WebFlux application with Akka actor packages (core, cluster, persistence, router, sse, stream, timer, etc.), controllers (actor, cluster, auth, pubsub, sse), service layer, repository layer, configs, and resources.
README for Insights
• The system leverages:
• Reactive Streams (Reactor) for non-blocking data flows.
• Spring WebFlux as the HTTP/SSE/WS server.
• R2DBC for reactive database access.
• Akka Actor model for concurrency, distribution, and CQRS (Event Sourcing, Snapshots, Durable State, Akka Projections).
• Docker-based test environments for MySQL, Postgres, Mongo, Kafka, RabbitMQ, Redis.
a. Client Tier
• Browser/mobile client running Blazor WebApp (HTML/CSS/JS/razor components).
• JS libraries for SSE and WebSocket (in wwwroot/js).
b. API Gateway / HTTP Layer
• Spring WebFlux server hosting controllers:
• REST endpoints (ActorController, ClusterController, AuthController, Admin controllers).
• SSE endpoint (SseController).
• WebSocket endpoints (ReactiveWebSocketConfig + WS handlers under ws/actor).
• Pub/Sub API (PubSubController).
c. Business Layer
• Service classes (SendService, SimpleAuthService) orchestrating use cases.
• Akka Actor System (multiple actor packages: core, cluster, discovery, persistent, router, sse, state, stream, supervisor, timer).
• CQRS components: Event Journal, Snapshot store, Durable State Store, Projections.
d. Data Layer
• R2DBC drivers connecting to relational DBs (Postgres/MySQL) for event journals and durable state.
• DAO/DTO layers under repositories/durable.
e. Shared Model Library
• CommonModel JAR distributed as Gradle dependency to backend, and shared via Protobuf/JSON contracts to Blazor front-end (via JsonUtil.cs).
f. External Systems (optional)
• Kafka, RabbitMQ, Redis (used in tests or in production for Pub/Sub, if configured).
Relationships and Data Flows
• Controller → Service → Actor System (tell/ask patterns).
• Actors → Event Journal / Durable Store (R2DBC) → Database.
• Actors → Projections → Read model (R2DBC) → Query API.
• Controller → SSE / WS push → Client.
Architectural Patterns
• Non-blocking Reactive Streams end-to-end.
• Actor Model for concurrency, distribution, resilience (supervisors, clustering).
• CQRS: segregation of write model (Akka Persistence) and read model (Akka Projections + R2DBC).
• Layered architecture: Presentation (Blazor/Controllers), Business (Services/Actors), Persistence (Repositories/DB).