# alexdevcoding/sistema-wander architecture

> Architecture diagram of the GitHub repository alexdevcoding/sistema-wander, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-28). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/alexdevcoding/sistema-wander
- Repository: https://github.com/alexdevcoding/sistema-wander

## Overview

##### Project type and purpose
- This is a monolithic, server-rendered PHP web application for library employee management—handling authentication, employee CRUD, payroll calculations, reports, and database backups.
- It leverages TailwindCSS and Flowbite on the frontend, PHP controllers/views on the backend, and a relational database (presumably MySQL) for persistence.

##### File structure
- src/Backend – PHP “controllers” and route handlers (e.g., login.php, añadir-empleado.php, tablas/actions/*).
- src/templates – server-side view templates (Admin vs. Empleado roles, plus shared pages like login.php, 404.php).
- src/assets – static assets (CSS inputs/outputs, compiled Tailwind styles, Flowbite JS, custom JS modules, images, webfonts).
- Top-level scripts – actualizar_db.php for automated DB updates/backups; tailwind.config.js for CSS build; package.json for dependency management.
- Credentials and backup SQL files under src/Backend/respaldo.

##### README
- Installation steps focus solely on setting up Tailwind and Flowbite.

##### Main components
a. Client Tier (Browser)
– HTML/CSS/JS assets: TailwindCSS styles, Flowbite components, custom JS for UI interactions (añadir-empleado.js, graficas.js, buscador.js, etc.).
b. Web/Application Tier
– Web Server (e.g., Apache or Nginx + PHP-FPM) hosting:
- Entry points & route resolvers in src/Backend (login, logout, auth, registrar, añadir-empleado, graficas, reports, tablas/actions, etc.)
- View layer in src/templates (distinguish Admin vs. Empleado layouts and pages).
- Shared PHP modules: conexión.php for DB connection handling, autenticación.php for session/auth logic.
- Scheduled scripts: actualizar_db.php for backups.
c. Data Tier
– Relational Database (MySQL or MariaDB)
– Backup storage (SQL dumps in src/Backend/respaldo)
d. External services (optional/placeholder)
– CDN for serving static assets (if used in production)
– Cron scheduler (Linux cron) triggering actualizar_db.php

##### Relationships & data flows
- The Browser initiates HTTP(S) requests (GET/POST) to the Web Server.
- The Web Server dispatches to PHP controllers in src/Backend. Controllers interact with conexión.php to run SQL queries, call tablas/actions for CRUD or calculo-nomina, then render templates from src/templates populated with dynamic data.
- Response (HTML) plus linked JS/CSS is returned to the browser.
- Database backups are executed on a schedule or manually via actualizar_db.php; resulting SQL files are saved under /respaldo.
- User roles (Admin vs. Empleado) drive which templates/controllers are accessible after authentication.

##### Architectural patterns & design principles
- Layered architecture: Presentation (templates + assets) → Application (controllers + services) → Data (DB + backups).
- Separation of concerns:
– src/assets/js handles purely client-side logic
– src/templates holds view markup
– src/Backend houses request handling & business logic
– conexión.php centralizes DB connectivity
- MVC-inspired flow (though not strict MVC framework): Controllers → Models (raw SQL in acciones) → Views (PHP templates).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client Tier
    subgraph "Client Tier (Browser)"
        direction TB
        Browser["Browser"]:::frontend
        Assets["Static Assets"]:::frontend
        JS["JS Modules"]:::frontend
        CSS["CSS Source/Output"]:::frontend
        Img["Images"]:::frontend
        Fonts["Webfonts & Icons"]:::frontend
        TailwindConfig["Tailwind Config"]:::frontend
        NPMConfig["NPM Config"]:::frontend
    end

    %% Web/Application Tier
    subgraph "Web Server / PHP Application"
        direction TB
        StaticServer["Static Asset Server\n(src/assets)"]:::backend
        Controllers["Controllers & Services"]:::backend
        AuthRoutes["Authentication Routes"]:::backend
        Login["login.php"]:::backend
        Logout["logout.php"]:::backend
        Registrar["registrar.php"]:::backend
        ErrorHandler["404.php"]:::backend
        CRUD["Business Logic Controllers"]:::backend
        AddEmployee["añadir-empleado.php"]:::backend
        Graphs["graficas/index.php"]:::backend
        ReportsController["reports/obtener-reportes.php"]:::backend
        Tables["Table Actions & Data Endpoints"]:::backend
        Actions["tablas/actions/"]:::backend
        BuscaEmpleado["tablas/busca-empleado.php"]:::backend
        CalculoNomina["tablas/calculo-nomina.php"]:::backend
        ObtenerPagos["tablas/obtener-pagos.php"]:::backend
        RegistrarCesta["tablas/registrar-cesta-tickets.php"]:::backend
        TablaEmpleados["tablas/tabla-empleados.php"]:::backend
        TablaUsuarios["tablas/tabla-usuarios.php"]:::backend
        SharedServices["Shared Services"]:::backend
        Connector["conexión.php"]:::backend
        AuthLogic["auth/autenticación.php"]:::backend
        ViewRenderer["View Renderer\n(src/templates)"]:::backend
        AdminTemplates["templates/Admin/"]:::backend
        EmpleadoTemplates["templates/Empleado/"]:::backend
        SharedTemplates["templates/login.php"]:::backend
        BackupScript["actualizar_db.php"]:::backend
        BackupWrapper["respaldo-base-datos.php"]:::backend
    end

    %% Data Tier
    subgraph "Data Tier"
        direction TB
        DB["Relational DB\n(MySQL/MariaDB)"]:::data
    end

    %% Backup & Scheduler
    subgraph "Backup & Scheduler"
        direction TB
        Cron["Cron Scheduler"]:::external
        Backups["Backup Storage\n(SQL dumps)"]:::external
    end

    %% Relationships
    Browser -->|HTTP GET/POST| StaticServer
    Browser -->|HTTP GET/POST| Controllers
    StaticServer --> JS
    StaticServer --> CSS
    StaticServer --> Img
    StaticServer --> Fonts
    Browser -->|build via npm| TailwindConfig
    Browser -->|build via npm| NPMConfig

    Controllers --> AuthRoutes
    AuthRoutes --> Login
    AuthRoutes --> Logout
    AuthRoutes --> Registrar
    AuthRoutes --> ErrorHandler

    Controllers --> CRUD
    CRUD --> AddEmployee
    CRUD --> Graphs
    CRUD --> ReportsController

    Controllers --> Tables
    Tables --> Actions
    Tables --> BuscaEmpleado
    Tables --> CalculoNomina
    Tables --> ObtenerPagos
    Tables --> RegistrarCesta
    Tables --> TablaEmpleados
    Tables --> TablaUsuarios

    Controllers --> SharedServices
    SharedServices --> Connector
    SharedServices --> AuthLogic

    Connector -->|SQL queries| DB
    DB -->|Results| Connector

    Controllers -->|renders| ViewRenderer
    ViewRenderer --> AdminTemplates
    ViewRenderer --> EmpleadoTemplates
    ViewRenderer --> SharedTemplates

    Cron -->|triggers| BackupScript
    BackupScript --> BackupWrapper
    BackupWrapper --> Backups

    %% Click Events
    click JS "https://github.com/alexdevcoding/sistema-wander/tree/main/src/assets/js/"
    click CSS "https://github.com/alexdevcoding/sistema-wander/tree/main/src/css/"
    click Img "https://github.com/alexdevcoding/sistema-wander/tree/main/src/assets/Img/"
    click Fonts "https://github.com/alexdevcoding/sistema-wander/tree/main/src/assets/webfont/"
    click TailwindConfig "https://github.com/alexdevcoding/sistema-wander/blob/main/tailwind.config.js"
    click NPMConfig "https://github.com/alexdevcoding/sistema-wander/blob/main/package.json"
    click Login "https://github.com/alexdevcoding/sistema-wander/blob/main/src/Backend/login.php"
    click Logout "https://github.com/alexdevcoding/sistema-wander/blob/main/src/Backend/logout.php"
    click Registrar "https://github.com/alexdevcoding/sistema-wander/blob/main/src/Backend/registrar.php"
    click ErrorHandler "https://github.com/alexdevcoding/sistema-wander/blob/main/src/Backend/404.php"
    click AddEmployee "https://github.com/alexdevcoding/sistema-wander/blob/main/src/Backend/añadir-empleado.php"
    click Graphs "https://github.com/alexdevcoding/sistema-wander/blob/main/src/Backend/graficas/index.php"
    click ReportsController "https://github.com/alexdevcoding/sistema-wander/blob/main/src/Backend/reports/obtener-reportes.php"
    click Actions "https://github.com/alexdevcoding/sistema-wander/tree/main/src/Backend/tablas/actions/"
    click BuscaEmpleado "https://github.com/alexdevcoding/sistema-wander/blob/main/src/Backend/tablas/busca-empleado.php"
    click CalculoNomina "https://github.com/alexdevcoding/sistema-wander/blob/main/src/Backend/tablas/calculo-nomina.php"
    click ObtenerPagos "https://github.com/alexdevcoding/sistema-wander/blob/main/src/Backend/tablas/obtener-pagos.php"
    click RegistrarCesta "https://github.com/alexdevcoding/sistema-wander/blob/main/src/Backend/tablas/registrar-cesta-tickets.php"
    click TablaEmpleados "https://github.com/alexdevcoding/sistema-wander/blob/main/src/Backend/tablas/tabla-empleados.php"
    click TablaUsuarios "https://github.com/alexdevcoding/sistema-wander/blob/main/src/Backend/tablas/tabla-usuarios.php"
    click Connector "https://github.com/alexdevcoding/sistema-wander/blob/main/src/Backend/conexión.php"
    click AuthLogic "https://github.com/alexdevcoding/sistema-wander/blob/main/src/Backend/auth/autenticación.php"
    click AdminTemplates "https://github.com/alexdevcoding/sistema-wander/tree/main/src/templates/Admin/"
    click EmpleadoTemplates "https://github.com/alexdevcoding/sistema-wander/tree/main/src/templates/Empleado/"
    click SharedTemplates "https://github.com/alexdevcoding/sistema-wander/blob/main/src/templates/login.php"
    click BackupScript "https://github.com/alexdevcoding/sistema-wander/blob/main/actualizar_db.php"
    click BackupWrapper "https://github.com/alexdevcoding/sistema-wander/blob/main/src/Backend/respaldo-base-datos.php"
    click Backups "https://github.com/alexdevcoding/sistema-wander/tree/main/src/Backend/respaldo/"

    %% Styles
    classDef frontend fill:#D0E6FF,stroke:#333,stroke-width:1px
    classDef backend fill:#C8E8C8,stroke:#333,stroke-width:1px
    classDef data fill:#FFE0B2,stroke:#333,stroke-width:1px
    classDef external fill:#E0E0E0,stroke:#333,stroke-width:1px
```
