How cristiancastineiras/dotchat works
Purpose and entry points
dotChat is a self-hosted, terminal-first real-time chat platform. It supports public/private rooms, direct conversations, encrypted messages and attachments, presence, and separate administration.
Primary executables:
• ASP.NET Core server/API and SignalR host: src/Chat.Servidor/Program.cs
• Interactive user CLI: src/Chat.ClienteCli/Program.cs
• Interactive administration CLI: src/Chat.AdminCli/Program.cs
• Containerized deployment and reverse proxy: docker-compose.yml, Dockerfile, despliegue/nginx.conf
Layered core and domain boundary
The solution follows Domain → Application → Infrastructure → Server layering. The domain owns chat concepts and repository/unit-of-work contracts, without persistence or transport dependencies.
• Entities: src/Chat.Dominio/Entidades/Usuario.cs, src/Chat.Dominio/Entidades/Sala.cs, src/Chat.Dominio/Entidades/Mensaje.cs
• Persistence contracts: src/Chat.Dominio/Abstracciones/IRepositorioMensajes.cs, src/Chat.Dominio/Abstracciones/IUnidadDeTrabajo.cs
• Domain failures provide the application/server error boundary: src/Chat.Dominio/Excepciones/
Application command/query pipeline
The application layer implements lightweight hand-rolled CQRS: endpoints and internal callers dispatch commands/queries to handlers through a central dispatcher. Commands mutate state; queries project DTOs for clients.
• Dispatcher contracts: src/Chat.Aplicacion/Cqrs/Contratos.cs, src/Chat.Aplicacion/Cqrs/Despachador.cs
• Core mutations: src/Chat.Aplicacion/Comandos/Mensajes/ComandoEnviarMensaje.cs, src/Chat.Aplicacion/Comandos/Salas/ComandoCrearSala.cs
• Reads and DTO boundary: src/Chat.Aplicacion/Consultas/Mensajes/ConsultaObtenerMensajes.cs, src/Chat.Aplicacion/Dtos/DtosMensaje.cs
HTTP API, authentication, and realtime delivery
The server exposes grouped endpoint modules for authentication, users, rooms, messages, attachments, diagnostics, and administration. Global exception handling turns domain/application failures into transport responses. SignalR is the realtime boundary for messages, typing, and connection activity.
• API composition and middleware: src/Chat.Servidor/Program.cs, src/Chat.Servidor/Configuracion/ManejadorExcepcionesGlobal.cs
• Transport modules: src/Chat.Servidor/Endpoints/EndpointsMensajes.cs, src/Chat.Servidor/Endpoints/EndpointsSalas.cs
• Hub and application notification adapter: src/Chat.Servidor/Hubs/ChatHub.cs, src/Chat.Servidor/Servicios/NotificadorSignalR.cs
• JWT/session abstractions and implementation: src/Chat.Aplicacion/Servicios/EmisorSesiones.cs, src/Chat.Infraestructura/Seguridad/GeneradorTokensJwt.cs
Persistence, encrypted content, and object storage
PostgreSQL is the system of record through EF Core. Repositories implement domain contracts and commit through a unit of work. Message encryption occurs before stored content reaches persistence; attachments are processed then encrypted and stored separately in S3-compatible MinIO.
• EF context/repositories: src/Chat.Infraestructura/Persistencia/ContextoChat.cs, src/Chat.Infraestructura/Persistencia/Repositorios/RepositorioMensajes.cs
• Encryption: src/Chat.Infraestructura/Seguridad/ServicioCifradorMensajes.cs, src/Chat.Infraestructura/Seguridad/FlujoCifrador.cs
• Attachment pipeline: src/Chat.Aplicacion/Comandos/Mensajes/ComandoSubirAdjunto.cs, src/Chat.Infraestructura/Almacenamiento/AlmacenObjetosS3.cs
Distributed runtime services
Docker Compose runs server replicas behind nginx, plus PostgreSQL, Valkey, MinIO, Jaeger, and Seq. Valkey supports cache, distributed presence/connection registration, rate limits, and replica coordination; in-memory alternatives exist for local/single-instance behavior.
• Cache and Valkey setup: src/Chat.Infraestructura/Cache/ServicioCacheFusion.cs, src/Chat.Infraestructura/ExtensionesValkey.cs
• Presence and replica coordination: src/Chat.Infraestructura/Presencia/RegistroConexionesValkey.cs, src/Chat.Servidor/Servicios/ServicioLatidoReplica.cs
• Telemetry and health wiring: src/Chat.Servidor/Configuracion/ExtensionesTelemetria.cs, src/Chat.Servidor/Configuracion/ExtensionesSalud.cs
Terminal clients and operational control
The user CLI owns local session state, calls the REST API, and subscribes to SignalR to render interactive conversations and inline images. The admin CLI calls administration endpoints for user, room, cache, message, and diagnostics operations.
• User client orchestration: src/Chat.ClienteCli/Servicios/AplicacionChat.cs, src/Chat.ClienteCli/Servicios/ClienteTiempoReal.cs
• Session/API boundary: src/Chat.ClienteCli/Servicios/AlmacenSesion.cs, src/Chat.ClienteCli/Servicios/ClienteApi.cs
• Admin API client and command shell: src/Chat.AdminCli/Servicios/ClienteAdminApi.cs, src/Chat.AdminCli/Infraestructura/ConsolaAdminInteractiva.cs
Main entry points: ComandoEnviarMensaje.cs Message workflows · Program.cs Server host · EndpointsMensajes.cs Endpoint modules · docker-compose.yml Compose & nginx
Components 20
Terminal clients
- User CLI · Interactive chat and conversation renderer.
src/Chat.ClienteCli/Servicios/AplicacionChat.cs - API client & session · Persists sessions and calls REST endpoints.
src/Chat.ClienteCli/Servicios/ClienteApi.cs - Realtime client
src/Chat.ClienteCli/Servicios/ClienteTiempoReal.cs - Admin CLI · Administrative command shell.
src/Chat.AdminCli/Infraestructura/ConsolaAdminInteractiva.cs - Admin API client
src/Chat.AdminCli/Servicios/ClienteAdminApi.cs
Server transport
- Server host · Composes API, middleware, DI, and runtime services.
src/Chat.Servidor/Program.cs - Endpoint modules · Auth, user, room, message, attachment, and admin endpoints.
src/Chat.Servidor/Endpoints/EndpointsMensajes.cs - Exception boundary · Maps domain and application failures to transport responses.
src/Chat.Servidor/Configuracion/ManejadorExcepcionesGlobal.cs - Chat hub · Realtime messages, typing, and connection activity.
src/Chat.Servidor/Hubs/ChatHub.cs - SignalR notifier · Publishes application notifications to hub clients.
src/Chat.Servidor/Servicios/NotificadorSignalR.cs
Core layers
- CQRS dispatcher · Dispatches commands and queries to handlers.
src/Chat.Aplicacion/Cqrs/Despachador.cs - Message workflows · Send, retrieve, and upload attachment workflows.
src/Chat.Aplicacion/Comandos/Mensajes/ComandoEnviarMensaje.cs - Chat domain · Users, rooms, messages, repositories, unit of work, and failures.
src/Chat.Dominio/Entidades/Mensaje.cs - JWT sessions · Issues and validates session tokens.
src/Chat.Infraestructura/Seguridad/GeneradorTokensJwt.cs - EF repositories · Implements domain repositories and unit-of-work commits.
src/Chat.Infraestructura/Persistencia/Repositorios/RepositorioMensajes.cs - Content encryption · Encrypts message and attachment content before storage.
src/Chat.Infraestructura/Seguridad/ServicioCifradorMensajes.cs
Distributed runtime
- PostgreSQL
docker-compose.yml - MinIO · Stores encrypted attachments.
src/Chat.Infraestructura/Almacenamiento/AlmacenObjetosS3.cs - Valkey · Cache, presence, rate limits, and replica coordination.
src/Chat.Infraestructura/ExtensionesValkey.cs - Compose & nginx · Routes traffic to replicated server containers and backing services.
docker-compose.yml
Connections 26
- User CLI → API client & session: uses
- User CLI → Realtime client: subscribes
- Admin CLI → Admin API client: uses
- API client & session → Endpoint modules: REST
- Admin API client → Endpoint modules: admin REST
- Realtime client → Chat hub: SignalR
- Compose & nginx → Server host: routes to replicas
- Compose & nginx → PostgreSQL: runs
- Compose & nginx → Valkey: runs
- Compose & nginx → MinIO: runs
- Server host → Endpoint modules: maps
- Server host → Exception boundary: uses
- Server host → Chat hub: hosts
- Endpoint modules → CQRS dispatcher: dispatches
- Chat hub → CQRS dispatcher: dispatches
- Endpoint modules → JWT sessions: authenticates
- CQRS dispatcher → Message workflows: invokes
- Message workflows → Chat domain: applies rules
- Message workflows → EF repositories: reads and writes
- Message workflows → Content encryption: encrypts
- Message workflows → MinIO: stores attachments
- Message workflows → SignalR notifier: notifies
- EF repositories → Chat domain: implements contracts
- EF repositories → PostgreSQL: EF Core
- SignalR notifier → Chat hub: publishes
- Server host → Valkey: presence and coordination