Saltar a contenido

Capas de Arquitectura

GexCom sigue Clean Architecture con cuatro capas y una regla de dependencia estricta: las capas internas no conocen las externas.

Diagrama de Capas

graph TB
    subgraph Interfaces["interfaces/ — Capa de Presentacion"]
        GUI["GUI Streamlit<br/>10 paginas + sidebar<br/>:8501"]
        API["API FastAPI<br/>11 endpoints + JWT<br/>:8000"]
    end

    subgraph Application["application/ — Casos de Uso"]
        UC["Use Cases (8)<br/>CrearNotificacion, CambiarEstado,<br/>RegistrarProceso, GestionarSujeto,<br/>GestionarAudiencia, VincularSujeto,<br/>ConsultarDirectorio, GenerarReporte"]
        SC["ServiceContainer<br/>Composition Root<br/>(DI lazy-loading + RLock)"]
        PORTS["Ports / Protocols (8)<br/>INotificacionReader/Writer<br/>IProcesoRepository<br/>IAuditLogger, IDispatcher..."]
        EVENTS["EventBus<br/>NotificacionCreada<br/>EstadoCambiado"]
    end

    subgraph Core["core/ — Dominio"]
        ENT["Entidades (7)<br/>Notificacion (aggregate root)<br/>Proceso, Sujeto, Juzgado<br/>Audiencia, Usuario, AuditLog"]
        ENUM["Enums (5)<br/>EstadoNotificacion<br/>CanalNotificacion<br/>RolUsuario..."]
        VO["Value Objects<br/>Frozen dataclasses"]
    end

    subgraph Infrastructure["infrastructure/ — Implementaciones"]
        REPOS["Repositories (6)<br/>SqlNotificacionRepository<br/>SqlProcesoRepository..."]
        NOTIFY["Notifications<br/>EmailDispatcher<br/>WhatsAppDispatcher<br/>DispatchWorker"]
        SEC["Security<br/>SqlAuditLogger<br/>BcryptPasswordHasher<br/>SqlLoginAttemptStore"]
        DB["Database<br/>PostgreSQL 16 (Docker)<br/>SQLite (dev/test)"]
    end

    GUI --> SC
    API --> SC
    SC --> UC
    UC --> PORTS
    PORTS -.->|implementa| REPOS
    PORTS -.->|implementa| NOTIFY
    PORTS -.->|implementa| SEC
    UC --> ENT
    REPOS --> DB
    NOTIFY --> DB
    SEC --> DB
    UC --> EVENTS

Regla de Dependencia

interfaces/ → application/ → core/
             infrastructure/
  • core/ NO importa de ninguna otra capa
  • application/ importa SOLO de core/
  • infrastructure/ implementa los Protocols definidos en application/ports/
  • interfaces/ accede al dominio via ServiceContainer (no importa repos directamente)

Modo Dual

GexCom opera en dos modos simultaneos sobre el mismo ServiceContainer:

Modo Puerto Sesion DB Auth
Streamlit GUI :8501 Thread-local (RLock) session_state JWT
FastAPI API :8000 Per-request (yield+finally) Bearer JWT header

Ambos modos comparten use cases, ports y dominio — solo difieren en el bootstrap y el transporte.