# oielay/gtio_votacion architecture

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

- Interactive diagram: https://gitdiagram.com/oielay/gtio_votacion
- Repository: https://github.com/oielay/gtio_votacion

## Overview

This project is a full-stack voting application named GTIO_Votacion, built with a microservices architectural approach. The system is split into distinct services for handling candidate-related functionality and user authentication, managed via an API gateway (Kong) and complemented with a frontend application developed with Astro.

##### Main Components

- Frontend Application:
– Located under the "Frontend" directory.
– Built using Astro, featuring components, pages, and utility functions to interact with backend APIs.
– Acts as the user interface (accessible via http://localhost:1234).

- Backend Services (Microservices):
– Servicio_1: Api.Candidatos – handles candidate-related operations.
– Its codebase is structured into layers: Dependency Injection, Models, Infrastructure (Repositories and DB context), Application (DTOs and Services), and Controllers.
– Manages candidate data and business logic.
– Servicio_2: Api.Autenticacion – handles authentication and authorization.
– Similarly layered (Dependency Injection, Models, Infrastructure, Repository, Services, Controllers).
– Deals with user login, registration, and integration with Kong (via the KongService).

- Database Integration:
– Both backend services contain a "DB" directory with SQL scripts (init.sql, entrypoint.sh) to initialize and configure the underlying databases.
– Each service maintains its own database schema and technology as indicated by the ADRs (e.g., ADR003_TecnologiaBaseDatos.md).

- API Gateway (Kong):
– Located within the "Backend/kong" directory, with its configuration files (Dockerfile, kong-config.sh, prometheus.yml).
– Acts as the central routing and façade for external requests, forwarding them to the appropriate backend service.
– Exposed on port 8002, making it the entry point for managing routes, consumers, and plugins.

- Monitoring & Metrics:
– Prometheus is configured (using a provided prometheus.yml file) to collect metrics from Kong, accessible via http://localhost:9090.

- Container Orchestration:
– The docker-compose.yml file ties all these services together, managing the orchestration and network separation between external and internal services.
– Includes steps to run Kong migrations and initial configurations, as detailed in the README.

##### Relationships & Interactions

- The Frontend interacts with backend APIs indirectly via Kong, ensuring that client requests (such as fetching candidates or submitting a vote) are routed to the Api.Candidatos service, while authentication requests go to the Api.Autenticacion service.

- Kong routes and mediates all external API calls:
– It receives incoming requests from the web client.
– It directs traffic to the appropriate internal service based on pre-defined routes and rules.

- Backend Services:
– Both microservices are built following clean separation between controllers (handling HTTP), application services (business logic), and infrastructure (data access via repositories).
– Databases are initialized separately for each service; the system uses SQL scripts provided in their respective DB folders.

- Monitoring:
– Kong integrates with Prometheus for real-time metrics monitoring, allowing observation of routes, response times, and system health.

##### Architectural Patterns & Design Principles

- Microservices Architecture:
– Each service is independently deployable and encapsulated.
– ADRs (Architecture Decision Records) detail key choices including microservices and internal structuring.

- Layered Architecture in Backend Services:
– Segregation into Dependency Injection, Models, Infrastructure (repositories/DBContext), Application (services and DTOs), and Controllers enables maintainability and testability.

- API Gateway Pattern:
– Kong serves as a centralized API gateway that simplifies client access and provides management benefits such as authentication, routing, and logging.

- Containerization & Orchestration:
– Docker is used to containerize the entire stack with a docker-compose setup for local deployment, ensuring consistency across development and production.

##### Elements

– Clear Labels:
- Name each component (Frontend, Api.Candidatos, Api.Autenticacion, Kong, respective databases, Prometheus).

– Additional Notes:
- Annotations for major configuration steps such as “Docker Compose Build” or “Kong Migration” to emphasize deployment workflows.

##### Final Assembly

- A Frontend block (Astro-based web app) at the top, showing user interactions.
- A separate block representing Prometheus monitoring (connected to Kong).
- Containers for each component as depicted in docker-compose.
- Labels showing accessible ports and network boundaries for external vs. internal services.

## Diagram (Mermaid)

```mermaid
graph TD
  %% Frontend Layer
  subgraph "Frontend Layer"
    FE["Frontend Application (Astro)\n(http://localhost:1234)"]:::frontend
  end

  %% API Gateway
  KONG["API Gateway (Kong)\n(port 8002)"]:::gateway

  %% Backend Services
  subgraph "Backend Services"
    %% Api.Candidatos Service
    subgraph "Api.Candidatos Service"
      C1["Controllers"]:::backend
      C2["Application Services"]:::backend
      C3["Infrastructure & Repositories"]:::backend
      C4["Database"]:::database
      C1 --> C2
      C2 --> C3
      C3 --> C4
    end

    %% Api.Autenticacion Service
    subgraph "Api.Autenticacion Service"
      A1["Controllers"]:::backend
      A2["Application Services"]:::backend
      A3["Infrastructure & Repositories"]:::backend
      A4["Database"]:::database
      A1 --> A2
      A2 --> A3
      A3 --> A4
    end
  end

  %% Monitoring & Container Orchestration
  PROM["Monitoring (Prometheus)\n(http://localhost:9090)"]:::monitoring
  DOCK["Container Orchestration (Docker Compose)"]:::orchestration

  %% Connections
  FE -->|"HTTP"| KONG
  KONG -->|"Routes_to_Candidatos"| C1
  KONG -->|"Routes_to_Autenticacion"| A1
  KONG -->|"Metrics"| PROM

  DOCK --- FE
  DOCK --- KONG
  DOCK --- C1
  DOCK --- A1
  DOCK --- PROM

  %% Click Events
  click FE "https://github.com/oielay/gtio_votacion/tree/main/Frontend/"
  click KONG "https://github.com/oielay/gtio_votacion/tree/main/Backend/kong/"
  click C1 "https://github.com/oielay/gtio_votacion/tree/main/Backend/Servicio_1/Api.Candidatos/"
  click A1 "https://github.com/oielay/gtio_votacion/tree/main/Backend/Servicio_2/Api.Autenticacion/"
  click C4 "https://github.com/oielay/gtio_votacion/tree/main/Backend/Servicio_1/DB/scripts/"
  click A4 "https://github.com/oielay/gtio_votacion/tree/main/Backend/Servicio_2/DB/scripts/"
  click PROM "https://github.com/oielay/gtio_votacion/blob/main/Backend/kong/prometheus.yml"
  click DOCK "https://github.com/oielay/gtio_votacion/blob/main/docker-compose.yml"

  %% Styles
  classDef frontend fill:#f9c74f,stroke:#333,stroke-width:2px;
  classDef backend fill:#90be6d,stroke:#333,stroke-width:2px;
  classDef database fill:#f94144,stroke:#333,stroke-width:2px;
  classDef gateway fill:#577590,stroke:#333,stroke-width:2px,color:#fff;
  classDef monitoring fill:#277da1,stroke:#333,stroke-width:2px,color:#fff;
  classDef orchestration fill:#f3722c,stroke:#333,stroke-width:2px,color:#fff;
```
