How oielay/gtio_votacion works
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.