# iamjunki/my-etsidi architecture

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

- Interactive diagram: https://gitdiagram.com/iamjunki/my-etsidi
- Repository: https://github.com/iamjunki/my-etsidi

## Overview

##### Project type and purpose
- Full-stack, monolithic web application.
- Static client (HTML/CSS/JS) under `client/`, served by an Express server.
- RESTful API and feature modules in `server/modules/`
- Postgres relational database under `server/database/`
- Redis for session caching (see `server/modules/utils/redisClient.js`)
- External integrations: SMTP mail service, Google OAuth & Calendar APIs

##### File structure
Top-level components:
- client/ – multiple static pages (login, signup, dashboard, etc.)
- server/ – main Express app (`index.js`), feature modules, DB config, migrations, models
- server/modules/ – each feature (auth, calendario, gestorData, mapa, noticias, email, googleCalendar, inicio) follows a handler/router/service pattern
- server/database/ – Knex/Sequelize migrations, models, connection setup
- server/modules/utils/ – cross-cutting utilities (rate-limiter, Redis client, UPM accounts helper)

##### Core architectural patterns
- Layered (handler → router → service → data-access)
- Feature-based modularization (each module owns its routes, services, and helpers)
- REST API endpoints for client communication
- Middleware for auth (Passport), rate limiting, and caching

##### Main components
A. Client (browser)
– Static pages under `client/`
B. Web Server (Express Monolith)
– `index.js` (entry point)
– Middleware layer (auth, limiter, body-parser)
– Router layer → feature routers (auth, calendario, googleCalendar, gestorData, mapa, noticias, email, inicio)
– Service layer (business logic)
– Data-access layer (models & migrations)
C. Database
– PostgreSQL instance
– Knex/Sequelize ORM for migrations and models (`usuarios`, `horarios`, `noticias`, etc.)
D. Cache/Session Store
– Redis (session storage)
E. External Services
– SMTP email transporter (`server/modules/email/transporter.js`)
– Google OAuth & Calendar APIs (`server/modules/auth/passportStrategies.js`, `server/modules/googleCalendar/services.js`)

##### Relationships and interactions
1. Client → Express API (REST calls)
2. Express → Middleware
3. Middleware → Routers → Handlers → Services
4. Services →
- Database (read/write)
- Redis (session reads/writes)
- External APIs (email, Google Calendar)
5. Database and Redis respond back to Services → Handlers → Routers → Client

##### Important architectural/design principles
- Single codebase “monolith” but modular by feature
- Clear separation of concerns: static assets vs. dynamic API logic
- Reusable utilities in `modules/utils/`
- Migrations and models isolate schema definition from business logic
- Environment variables for configuration (.env)

## Diagram (Mermaid)

```mermaid
graph TD
    C["Client (Static Pages)"]:::component
    C -->|HTTPS/REST| E["Express Server"]:::component

    E --> S_index["index.js"]:::entry

    subgraph "Express Monolith"
        S_index

        subgraph "Middleware Layer"
            RateLimiter["Rate Limiter"]:::middleware
            RedisClient["Redis Session Client"]:::middleware
            Utils["Body Parsing & Other Utils"]:::middleware
            Passport["Passport Strategies"]:::middleware
        end

        subgraph "Router Layer"
            AuthRouter["Auth Router"]:::router
            CalRouter["Calendario Router"]:::router
            GC_Router["GoogleCalendar Router"]:::router
            NewsRouter["Noticias Router"]:::router
            MapRouter["Mapa Router"]:::router
            DataRouter["GestorData Router"]:::router
            InicioRouter["Inicio Router"]:::router
        end

        subgraph "Handler Layer"
            AuthHandler["Auth Handler"]:::handler
            CalHandler["Calendario Handler"]:::handler
            GC_Handler["GoogleCalendar Handler"]:::handler
            NewsHandler["Noticias Handler"]:::handler
            MapHandler["Mapa Handler"]:::handler
            DataHandler["GestorData Handler"]:::handler
            InicioHandler["Inicio Handler"]:::handler
        end

        subgraph "Service Layer"
            AuthService["Auth Service"]:::service
            CalService["Calendario Service"]:::service
            GC_Service["GoogleCalendar Service"]:::service
            NewsService["Noticias Service"]:::service
            MapService["Mapa Service"]:::service
            DataService["GestorData Service"]:::service
            InicioService["Inicio Service"]:::service
            EmailTemplates["Mail Templates"]:::service
            EmailDefs["Mail Definitions"]:::service
            EmailTransporter["SMTP Transporter"]:::service
        end

        subgraph "Data-Access Layer"
            DBConfig["DB Config"]:::data
            DBConn["DB Connection"]:::data
            KnexInit["Knex Init"]:::data
            Migrations["Migrations"]:::data
            Models["Models"]:::data
            Aliases["Aliases & Path Config"]:::data
        end
    end

    %% Layer flows
    S_index --> RateLimiter
    RateLimiter --> RedisClient
    RateLimiter --> Utils
    Utils --> Passport

    S_index --> AuthRouter
    S_index --> CalRouter
    S_index --> GC_Router
    S_index --> NewsRouter
    S_index --> MapRouter
    S_index --> DataRouter
    S_index --> InicioRouter

    AuthRouter --> AuthHandler
    CalRouter --> CalHandler
    GC_Router --> GC_Handler
    NewsRouter --> NewsHandler
    MapRouter --> MapHandler
    DataRouter --> DataHandler
    InicioRouter --> InicioHandler

    AuthHandler --> AuthService
    CalHandler --> CalService
    GC_Handler --> GC_Service
    NewsHandler --> NewsService
    MapHandler --> MapService
    DataHandler --> DataService
    InicioHandler --> InicioService

    AuthService -->|SQL queries| Models
    CalService --> Models
    GC_Service --> Models
    NewsService --> Models
    MapService --> Models
    DataService --> Models
    InicioService --> Models

    AuthService --> RedisClient
    Passport --> RedisClient

    EmailTransporter --> EmailTemplates
    EmailTransporter --> EmailDefs
    AuthService --> EmailTransporter

    GC_Service -->|Calendar API| GoogleAPI
    EmailTransporter -->|SMTP| SMTP

    Models -->|SQL| Postgres
    DBConn -->|connect| Postgres
    KnexInit --> Postgres
    Migrations --> Postgres

    RedisClient -->|SESSION READ/WRITE| RedisStore

    %% External resources
    SMTP["SMTP Email Service"]:::external
    GoogleAPI["Google OAuth & Calendar API"]:::external
    Postgres["PostgreSQL DB"]:::database
    RedisStore["Redis Store"]:::cache

    %% Click Events
    click C "https://github.com/iamjunki/my-etsidi/tree/main/client/"
    click S_index "https://github.com/iamjunki/my-etsidi/blob/main/server/index.js"
    click RateLimiter "https://github.com/iamjunki/my-etsidi/blob/main/server/modules/utils/limiter.js"
    click RedisClient "https://github.com/iamjunki/my-etsidi/blob/main/server/modules/utils/redisClient.js"
    click Utils "https://github.com/iamjunki/my-etsidi/blob/main/server/modules/utils/utils.js"
    click Passport "https://github.com/iamjunki/my-etsidi/blob/main/server/modules/auth/helpers/passportStrategies.js"
    click AuthHandler "https://github.com/iamjunki/my-etsidi/blob/main/server/modules/auth/handlers.js"
    click AuthRouter "https://github.com/iamjunki/my-etsidi/blob/main/server/modules/auth/router.js"
    click AuthService "https://github.com/iamjunki/my-etsidi/blob/main/server/modules/auth/services.js"
    click CalHandler "https://github.com/iamjunki/my-etsidi/blob/main/server/modules/calendario/handlers.js"
    click CalRouter "https://github.com/iamjunki/my-etsidi/blob/main/server/modules/calendario/router.js"
    click CalService "https://github.com/iamjunki/my-etsidi/blob/main/server/modules/calendario/services.js"
    click GC_Service "https://github.com/iamjunki/my-etsidi/blob/main/server/modules/googleCalendar/services.js"
    click GC_Handler "https://github.com/iamjunki/my-etsidi/blob/main/server/modules/googleCalendar/handlers.js"
    click GC_Router "https://github.com/iamjunki/my-etsidi/blob/main/server/modules/googleCalendar/router.js"
    click NewsHandler "https://github.com/iamjunki/my-etsidi/blob/main/server/modules/noticias/handlers.js"
    click NewsRouter "https://github.com/iamjunki/my-etsidi/blob/main/server/modules/noticias/router.js"
    click NewsService "https://github.com/iamjunki/my-etsidi/blob/main/server/modules/noticias/services.js"
    click MapHandler "https://github.com/iamjunki/my-etsidi/blob/main/server/modules/mapa/handlers.js"
    click MapRouter "https://github.com/iamjunki/my-etsidi/blob/main/server/modules/mapa/router.js"
    click MapService "https://github.com/iamjunki/my-etsidi/blob/main/server/modules/mapa/services/services.js"
    click DataHandler "https://github.com/iamjunki/my-etsidi/blob/main/server/modules/gestorData/handlers.js"
    click DataRouter "https://github.com/iamjunki/my-etsidi/blob/main/server/modules/gestorData/router.js"
    click DataService "https://github.com/iamjunki/my-etsidi/blob/main/server/modules/gestorData/services/services.js"
    click InicioHandler "https://github.com/iamjunki/my-etsidi/blob/main/server/modules/inicio/handlers.js"
    click InicioRouter "https://github.com/iamjunki/my-etsidi/blob/main/server/modules/inicio/router.js"
    click InicioService "https://github.com/iamjunki/my-etsidi/blob/main/server/modules/inicio/services.js"
    click EmailTemplates "https://github.com/iamjunki/my-etsidi/blob/main/server/modules/email/templatesCorreoCodigo.js"
    click EmailDefs "https://github.com/iamjunki/my-etsidi/blob/main/server/modules/email/mails.js"
    click EmailTransporter "https://github.com/iamjunki/my-etsidi/blob/main/server/modules/email/transporter.js"
    click DBConfig "https://github.com/iamjunki/my-etsidi/blob/main/server/database/config/config.js"
    click DBConn "https://github.com/iamjunki/my-etsidi/blob/main/server/database/connection.js"
    click KnexInit "https://github.com/iamjunki/my-etsidi/blob/main/server/database/knex.js"
    click Migrations "https://github.com/iamjunki/my-etsidi/tree/main/server/database/migrations/"
    click Models "https://github.com/iamjunki/my-etsidi/tree/main/server/database/models/"
    click Aliases "https://github.com/iamjunki/my-etsidi/blob/main/server/aliases.js"

    %% Styles
    classDef component fill:#ffb7ce,stroke:#333,stroke-width:1px
    classDef entry fill:#f9c2a1,stroke:#333,stroke-width:1px
    classDef middleware fill:#fdfd96,stroke:#333,stroke-width:1px
    classDef router fill:#aec6cf,stroke:#333,stroke-width:1px
    classDef handler fill:#cdb3d4,stroke:#333,stroke-width:1px
    classDef service fill:#77dd77,stroke:#333,stroke-width:1px
    classDef data fill:#d3b683,stroke:#333,stroke-width:1px
    classDef database fill:#a2cffe,stroke:#333,stroke-width:1px
    classDef cache fill:#ffd8b1,stroke:#333,stroke-width:1px
    classDef external fill:#ff6961,stroke:#333,stroke-width:1px
```
