# etzel92/eventcontrolsystem architecture

> Architecture diagram of the GitHub repository etzel92/eventcontrolsystem, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-03-09). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/etzel92/eventcontrolsystem
- Repository: https://github.com/etzel92/eventcontrolsystem

## Overview

##### Tipo y propósito del proyecto (qué debes reflejar en el diagrama)
**EventControlSystem** es una **solución distribuida** con **control remoto y monitoreo en tiempo real**. Concretamente:
- **Admin Web (React)** envía comandos (abrir/cerrar formularios) y consulta bitácora.
- **Backend (ASP.NET Core)** expone **REST** (bitácora/edición) y un **Hub SignalR** (comandos/tiempo real).
- **Clientes WinForms (.NET 8)** se conectan por SignalR, ejecutan comandos (mostrar/cerrar forms) y **registran eventos**.
- **SQL Server** persiste los eventos (README menciona SPs; el código muestra EF Core DbContext).

Tu diagrama debe capturar dos flujos principales:

##### Frontend: `EventControl.UI/`
Indicadores claros:
- `src/services/signalRService.js` → conexión al Hub SignalR del backend.
- `src/services/eventLogService.js` → llamadas REST para bitácora.
- `src/components/RemoteControl.jsx` → UI para mandar comandos.
- `src/components/EventLogTable.jsx` → UI para visualizar/editar bitácora.
**En el diagrama**: un bloque “EventControl.UI (React + Vite)” con dos flechas salientes: REST y SignalR.

##### Backend: `EventControl/EventControl.API/`
Piezas:
- `Controllers/EventLogController.cs` → capa REST para bitácora (consulta/edición).
- `Hubs/WinFormsHub.cs` → Hub SignalR para mensajes en tiempo real hacia clientes.
- `Data/EventLogDbContext.cs` + `Models/EventLog.cs` → persistencia con EF Core.
- `Program.cs` → composición (DI), mapeo de endpoints, configuración de SignalR, CORS, etc.
**En el diagrama**: un bloque “EventControl.API (ASP.NET Core)” subdividido (opcional) en:
- “REST Controllers”
- “SignalR Hub”
- “EF Core / DbContext”
y una dependencia a “SQL Server”.

##### Cliente escritorio: `EventClient/EventClient.App/`
Piezas:
- `SignalR/SignalRClient.cs` → conexión al Hub; recibe comandos.
- `Service/EventService.cs` → lógica para ejecutar acciones/registrar (probable).
- `Data/EventLogger.cs` → registro local/llamadas de logging (probable).
- `MainForm.cs`, `SecondaryForm.cs` → superficies UI que se abren/cierran remotamente.
**En el diagrama**: un bloque “EventClient.App (WinForms .NET 8)” con:
- sub-bloque “SignalR Client”
- sub-bloque “Forms (Main/Secondary)”
- sub-bloque “Event Logging”

##### (A) Diagrama C4–Nivel 2 (Container) — el “sistema real”
Incluye:
- **EventControl.UI (React/Vite)** — navegador del admin
- **EventControl.API (ASP.NET Core)** — REST + SignalR
- **EventClient.App (WinForms .NET 8)** — múltiples instancias (N clientes)
- **SQL Server** — base de datos de eventos
Conecta:
- UI → API: **HTTPS REST** (`EventLogController`)
- UI ⇄ API: **SignalR (WebSockets/LongPolling)** (`WinFormsHub`)
- WinForms ⇄ API: **SignalR** (`SignalRClient.cs` ↔ `WinFormsHub.cs`)
- API → SQL Server: **EF Core** (`EventLogDbContext`)
- (si aplica en tu implementación) WinForms → API REST (o directo a DB) para registrar eventos. *La README dice “registra eventos en base de datos”; por seguridad/arquitectura típica, modela WinForms registrando vía API, y anota como “según implementación”.*

##### Admin abre formulario remoto
- Admin (UI) → SignalR Hub: `OpenSecondaryForm(clientId|machine)`
- Hub → WinForms clients: broadcast/target
- Cliente objetivo → abre `SecondaryForm`
- Cliente/Backend → registra EventLog (y retorna ack opcional)
##### Admin consulta/edita bitácora
- UI → REST `/eventlog` (GET)
- UI → REST `/eventlog/{id}` (PUT/PATCH comentario)
- API → DB

##### (C) Diagrama interno del Backend (componentes)
- REST Controller → Service/Repository (si existe; si no, Controller → DbContext)
- Hub → (opcional) servicio de routing/targeting de clientes
- DbContext → SQL Server
Esto aterriza el código a runtime.

##### EventControl.UI
- RemoteControl (UI)
- EventLogTable (UI)
- signalRService.js
- eventLogService.js
##### EventControl.API
- EventLogController (REST)
- WinFormsHub (SignalR)
- EventLogDbContext (EF Core)
##### SQL Server
- Tabla EventLog (y nota: “Stored procedures (según README)”)
##### EventClient.App (xN)
- SignalRClient
- MainForm / SecondaryForm
- EventLogger / EventService

##### Flechas (dirección y protocolo)
- EventControl.UI → EventControl.API: **HTTPS REST** (bitácora)
- EventControl.UI ⇄ EventControl.API: **SignalR** (comandos/estado)
- EventClient.App ⇄ EventControl.API: **SignalR** (recepción de comandos + notificaciones)
- EventControl.API → SQL Server: **EF Core / TCP** (persistencia)
- (Opcional/si aplica) EventClient.App → EventControl.API: **REST** (registrar evento/heartbeat)

##### Patrones/decisiones arquitectónicas a resaltar
- **Arquitectura “3 capas / 3 componentes”** (UI Web, API, Cliente).
- **Event-driven en tiempo real** con SignalR (pub/sub-like).
- **Separación de canales**:
- SignalR para “control/telemetría”
- REST para “consulta/edición” de bitácora
- **Escalabilidad de clientes**: WinForms como **N instancias** conectadas a un Hub.
- **Persistencia centralizada** en SQL Server (auditabilidad).

##### Cómo “hacerlo muy detallado” sin complicarte
Descompón cada bloque en sub-bloques directamente rastreables en el árbol:

- Para UI: referencia explícita a `services/*` y `components/*`.
- Para API: separa **Controllers**, **Hubs**, **Data/Models**.
- Para WinForms: separa **SignalR**, **Forms**, **Service/Data**.

Si algo no está en el árbol (por ejemplo “Repository”), **no lo inventes**: o lo omites, o lo dibujas como “(implícito / en Controller)”.

##### Convenciones visuales (para que el diagrama sea legible y “engineering-grade”)
- Rectángulos: procesos/servicios (UI, API, WinForms)
- Cilindro: SQL Server
- Paquetes/containers: subcomponentes dentro de cada proceso
- Frontend (React): azul
- Backend (.NET): verde
- Client desktop: naranja
- Data store: gris
- **Etiquetas en flechas**:
- “HTTPS/REST”
- “SignalR (WebSockets)”
- “EF Core”
- **Cardinalidad**:
- Marca WinForms como **1..N clients**
- **Notas**:
- URLs/puertos (README menciona `localhost:7290` por defecto): añade como anotación en API/UI si te ayuda a depurar.

##### Checklist final (lo que no debe faltar)
- [ ] UI Web con **dos integraciones** (REST + SignalR)
- [ ] API con **Controller + Hub + DbContext**
- [ ] WinForms con **SignalRClient** y **Forms**
- [ ] SQL Server como **persistencia de bitácora**
- [ ] Dos flujos: **comandos en tiempo real** y **consulta/edición de bitácora**
- [ ] Indicar **N clientes** conectados al Hub

Con esto tu diagrama quedará lo más fiel posible al repo: cada caja corresponde a carpetas/archivos reales, y cada flecha a un mecanismo explícito (REST/SignalR/EF Core).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% =========================
    %% (A) C4-L2 / Container View
    %% =========================
    subgraph C4["(A) Container View — EventControlSystem"]
        direction TB

        AdminBrowser["Admin Browser"]:::external

        subgraph UI["EventControl.UI (React + Vite)"]
            direction TB
            UI_RemoteControl["RemoteControl (send open/close)"]:::frontend
            UI_EventLogTable["EventLogTable (view/edit audit log)"]:::frontend
            UI_SignalRService["signalRService.js (SignalR client)"]:::frontend
            UI_EventLogService["eventLogService.js (REST client)"]:::frontend
        end

        subgraph API["EventControl.API (ASP.NET Core)"]
            direction TB
            API_REST["REST API (Controllers)"]:::backend
            API_Hub["SignalR Hub"]:::backend
            API_EF["EF Core (DbContext/Models)"]:::backend
            API_Compose["Composition (Program/Settings)"]:::backend
        end

        subgraph WF["EventClient.App (WinForms .NET 8) — 1..N Clients"]
            direction TB
            WF_SignalRClient["SignalRClient (connect/receive commands)"]:::client
            WF_Forms["Forms (Main/Secondary)"]:::client
            WF_Logic["EventService + EventLogger (execute actions/log events)"]:::client
            WF_Startup["Client Startup (Program.cs)"]:::client
        end

        SQL["SQL Server\n(EventLog table)\nNote: SPs mentioned in README (optional)"]:::datastore

        AdminBrowser -->|"Hosts UI"| UI

        %% UI -> API integrations
        UI_EventLogService -->|"HTTPS/REST (audit log CRUD)"| API_REST
        UI_SignalRService <-->|"SignalR (WebSockets/LongPolling)\ncommands/state"| API_Hub

        %% WinForms <-> API
        WF_SignalRClient <-->|"SignalR (commands + notifications)"| API_Hub
        WF_Logic -->|"Optional: HTTPS/REST (log event/heartbeat)\n(implementation-dependent)"| API_REST

        %% API -> DB
        API_REST -->|"uses"| API_EF
        API_Hub -->|"writes audit events (optional/when needed)"| API_EF
        API_EF -->|"EF Core (DB access)"| SQL
    end

    %% ==================================
    %% (C) Backend Internal Component View
    %% ==================================
    subgraph BACKEND["(C) Backend Internal — EventControl.API"]
        direction TB

        subgraph API_Controllers["Controllers"]
            direction TB
            EventLogController["EventLogController.cs\n(GET/PUT/PATCH event log)"]:::backend
        end

        subgraph API_Hubs["SignalR"]
            direction TB
            WinFormsHub["WinFormsHub.cs\n(route/broadcast commands)"]:::backend
        end

        subgraph API_Data["Data / Models"]
            direction TB
            DbContext["EventLogDbContext.cs\n(EF Core DbContext)"]:::backend
            Model["EventLog.cs\n(Entity model)"]:::backend
        end

        subgraph API_Boot["Bootstrap / Config"]
            direction TB
            ApiProgram["Program.cs\n(DI, endpoints, SignalR, CORS)"]:::backend
            Appsettings["appsettings.json\n(connection strings/settings)"]:::config
            AppsettingsDev["appsettings.Development.json\n(dev settings)"]:::config
            LaunchSettings["launchSettings.json\n(ports/urls; e.g., :7290)"]:::config
        end

        EventLogController -->|"uses"| DbContext
        DbContext -->|"maps"| Model

        WinFormsHub -->|"may log events via"| DbContext

        ApiProgram -->|"registers/mapping"| EventLogController
        ApiProgram -->|"maps Hub endpoint"| WinFormsHub
        ApiProgram -->|"configures EF Core"| DbContext
        ApiProgram -->|"reads"| Appsettings
        ApiProgram -->|"reads"| AppsettingsDev
        ApiProgram -->|"dev profile"| LaunchSettings
    end

    %% ==================================
    %% (B) Critical Use-Cases (Flow Steps)
    %% ==================================
    subgraph SEQ["(B) Critical Use-Cases — Step Flows"]
        direction TB

        subgraph UC1["UC1: Admin opens/closes remote form (real-time)"]
            direction TB
            UC1_1["1) Admin clicks Open/Close in RemoteControl"]:::step
            UC1_2["2) UI signalRService invokes Hub method\n(e.g., OpenSecondaryForm(target))"]:::step
            UC1_3["3) WinFormsHub routes command to target client(s)"]:::step
            UC1_4["4) SignalRClient receives command"]:::step
            UC1_5["5) Client opens/closes SecondaryForm"]:::step
            UC1_6["6) Client and/or Hub records audit event (optional)"]:::step

            UC1_1 --> UC1_2 --> UC1_3 --> UC1_4 --> UC1_5 --> UC1_6
        end

        subgraph UC2["UC2: Admin queries/edits audit log (REST)"]
            direction TB
            UC2_1["1) UI EventLogTable requests audit log list (GET /eventlog)"]:::step
            UC2_2["2) EventLogController queries DbContext"]:::step
            UC2_3["3) DbContext reads from SQL Server"]:::step
            UC2_4["4) UI edits entry (PUT/PATCH /eventlog/{id})"]:::step
            UC2_5["5) EventLogController writes via DbContext to SQL Server"]:::step

            UC2_1 --> UC2_2 --> UC2_3 --> UC2_4 --> UC2_5
        end
    end

    %% =========================
    %% Cross-links (traceability)
    %% =========================
    UI_RemoteControl -.->|"drives"| UC1_1
    UI_SignalRService -.->|"implements"| UC1_2
    WinFormsHub -.->|"implements"| UC1_3
    WF_SignalRClient -.->|"implements"| UC1_4
    WF_Forms -.->|"implements"| UC1_5
    EventLogController -.->|"implements"| UC2_2
    DbContext -.->|"implements"| UC2_2
    SQL -.->|"stores"| UC2_3

    %% =========================
    %% Click Events (from mapping)
    %% =========================
    click UI "https://github.com/etzel92/eventcontrolsystem/tree/main/EventControl.UI/"
    click UI_RemoteControl "https://github.com/etzel92/eventcontrolsystem/blob/main/EventControl.UI/src/components/RemoteControl.jsx"
    click UI_EventLogTable "https://github.com/etzel92/eventcontrolsystem/blob/main/EventControl.UI/src/components/EventLogTable.jsx"
    click UI_SignalRService "https://github.com/etzel92/eventcontrolsystem/blob/main/EventControl.UI/src/services/signalRService.js"
    click UI_EventLogService "https://github.com/etzel92/eventcontrolsystem/blob/main/EventControl.UI/src/services/eventLogService.js"

    click API "https://github.com/etzel92/eventcontrolsystem/tree/main/EventControl/EventControl.API/"
    click EventLogController "https://github.com/etzel92/eventcontrolsystem/blob/main/EventControl/EventControl.API/Controllers/EventLogController.cs"
    click WinFormsHub "https://github.com/etzel92/eventcontrolsystem/blob/main/EventControl/EventControl.API/Hubs/WinFormsHub.cs"
    click DbContext "https://github.com/etzel92/eventcontrolsystem/blob/main/EventControl/EventControl.API/Data/EventLogDbContext.cs"
    click Model "https://github.com/etzel92/eventcontrolsystem/blob/main/EventControl/EventControl.API/Models/EventLog.cs"
    click ApiProgram "https://github.com/etzel92/eventcontrolsystem/blob/main/EventControl/EventControl.API/Program.cs"
    click Appsettings "https://github.com/etzel92/eventcontrolsystem/blob/main/EventControl/EventControl.API/appsettings.json"
    click AppsettingsDev "https://github.com/etzel92/eventcontrolsystem/blob/main/EventControl/EventControl.API/appsettings.Development.json"
    click LaunchSettings "https://github.com/etzel92/eventcontrolsystem/blob/main/EventControl/EventControl.API/Properties/launchSettings.json"

    click WF "https://github.com/etzel92/eventcontrolsystem/tree/main/EventClient/EventClient.App/"
    click WF_SignalRClient "https://github.com/etzel92/eventcontrolsystem/blob/main/EventClient/EventClient.App/SignalR/SignalRClient.cs"
    click WF_Forms "https://github.com/etzel92/eventcontrolsystem/blob/main/EventClient/EventClient.App/MainForm.cs"
    click UC1_5 "https://github.com/etzel92/eventcontrolsystem/blob/main/EventClient/EventClient.App/SecondaryForm.cs"
    click WF_Logic "https://github.com/etzel92/eventcontrolsystem/blob/main/EventClient/EventClient.App/Service/EventService.cs"
    click UC1_6 "https://github.com/etzel92/eventcontrolsystem/blob/main/EventClient/EventClient.App/Data/EventLogger.cs"
    click WF_Startup "https://github.com/etzel92/eventcontrolsystem/blob/main/EventClient/EventClient.App/Program.cs"

    %% =========================
    %% Styles
    %% =========================
    classDef external fill:#f3f4f6,stroke:#6b7280,color:#111827,stroke-width:1px
    classDef frontend fill:#dbeafe,stroke:#1d4ed8,color:#0b1b3a,stroke-width:1px
    classDef backend fill:#dcfce7,stroke:#16a34a,color:#052e12,stroke-width:1px
    classDef client fill:#ffedd5,stroke:#f97316,color:#3b1a05,stroke-width:1px
    classDef datastore fill:#e5e7eb,stroke:#374151,color:#111827,stroke-width:1px
    classDef config fill:#ede9fe,stroke:#7c3aed,color:#1f1147,stroke-width:1px
    classDef step fill:#fff7ed,stroke:#9a3412,color:#3b1a05,stroke-width:1px,stroke-dasharray: 4 2
```
