Skip to content

Latest commit

Β 

History

11 Commits

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Project 2 - Restaurant API and OLAP Layer

Course: Databases II
Team Members: Daniel AlemΓ‘n, Luis Meza

Node.js Express.js Docker MongoDB PostgreSQL
Elasticsearch Redis Neo4j Apache Airflow Apache Spark Nginx

EN | ES

Explainer Video

Click the image to watch the explainer video. (Note: The video is in Spanish).

πŸ“‘ Table of Contents

  1. Project Description
  2. Architecture
  3. Main Components
  4. Installation
  5. Build and Deployment
  6. Generating Synthetic Data
  7. ETL, Airflow and OLAP Layer
  8. Testing
  9. CI/CD Pipeline
  10. Interface Access
  11. Environment Reset

πŸ“ Project Description

This project implements a complete restaurant management system with a microservices architecture. It allows managing restaurants, menus, products, reservations, and orders through a set of RESTful APIs.

The system is designed with high availability, scalability, and performance as priorities, using modern technologies such as load balancing, database sharding, distributed caching, and optimized searches. It also implements DAGs via Airflow to perform ETL and automatically reindex products in Elastic. Additionally, it includes functionality to visualize significant analytics data.


πŸ—οΈ Architecture


πŸ“„ View Detailed Architecture Document (PDF)

(Note: The document is in Spanish)


Logical Architecture

The project follows a microservices architecture with the following key components:

  1. API Microservices:

    • Main API for CRUD operations of restaurants, menus, products, reservations, and orders.
    • Authentication service for user and JWT token management.
    • Optimized search service with Elasticsearch.
    • Indexing and routing operations service within a graph using Neo4J.
  2. Load Balancing:

    • Nginx as a reverse proxy and load balancer to distribute requests among instances.
  3. Persistence:

    • MongoDB: Main storage with sharding and replication for high availability.
    • PostgreSQL: Configurable alternative storage.
    • Elasticsearch: Search index for optimized queries.
    • HiveDB: Storage as a Data Warehouse.
  4. Cache:

    • Redis as a distributed cache store to improve performance.
  5. CI/CD:

    • Automated pipeline for testing, building, and deployment.
πŸ“‚ View Project Structure
proyecto2-bases2/
β”œβ”€β”€ airflow/                # Airflow service for automated DAGs
β”œβ”€β”€ analytics_service/      # Analytics dashboards service
β”œβ”€β”€ api/                    # Main API
β”œβ”€β”€ auth_service/           # Authentication service
β”œβ”€β”€ drivers/                # Drivers required for Hive metadata
β”œβ”€β”€ etl_service/            # Specific purpose service for full ETL
β”œβ”€β”€ graph_service/          # Indexing and routing service with Neo4j
β”œβ”€β”€ pruebas/                # Testing and data generation scripts
β”œβ”€β”€ search_service/         # Search service
β”œβ”€β”€ spark_analytics/        # Basic query script with Spark and Hive
β”œβ”€β”€ docker-compose.yml      # Container configuration
β”œβ”€β”€ hive_warehouse_init.sql # Warehouse initialization via HiveQL
β”œβ”€β”€ init_cluster.sh         # Script to initialize MongoDB cluster
β”œβ”€β”€ init_hive_warehouse.sh  # Script to initialize Hive
β”œβ”€β”€ init.sql                # Initialization of Postgres tables for services
β”œβ”€β”€ set_config.sh           # Script to configure the environment
β”œβ”€β”€ nginx.conf              # Load balancer configuration
└── README.md               # Documentation

Each service follows an MVC (Model-Controller) structure with a clear separation of responsibilities:

servicio/
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ config/             # Configuration
β”‚   β”œβ”€β”€ controllers/        # Controllers
β”‚   β”œβ”€β”€ dao/                # Data Access Objects
β”‚   β”œβ”€β”€ db/                 # Database connections
β”‚   β”œβ”€β”€ middlewares/        # Middlewares
β”‚   β”œβ”€β”€ models/             # Data models
β”‚   β”œβ”€β”€ routes/             # Route definitions
β”‚   └── app.js              # Main application
β”œβ”€β”€ swagger/                # API Documentation
β”œβ”€β”€ tests/                  # Tests
β”‚   β”œβ”€β”€ integration/        # Integration tests
β”‚   β”œβ”€β”€ unit/               # Unit tests
β”‚   └── utils/              # Test utilities
└── server.js               # Entry point

🧩 Main Components

Main API

Handles all CRUD operations related to restaurants, menus, products, reservations, orders, and delivery drivers.

  • RESTful implementation with Express.js and Swagger documentation.
  • Horizontal scalability with multiple instances (api1, api2).

Authentication Service

Manages users, security, login, registration, roles, and JWT verification.

  • JWT-based authentication and secure password hashing.
  • High availability (auth_service1, auth_service2).

Search Service

Provides independent optimized search functionality.

  • Free-text, category searches, and typo tolerance using Elasticsearch.
  • Real-time updates and automatic indexing.

Graph Service

Resolves complex queries using graph structures (Neo4j).

  • Calculation of optimal delivery routes and automatic delivery driver assignment.
  • Co-purchase analysis and identification of influential users.

ETL and Data Warehouse Service

Extracts, transforms, and loads (ETL) data for OLAP analysis.

  • Automated extraction from MongoDB/PostgreSQL with Python and processing with Apache Spark.
  • Load into Apache Hive optimized for columnar storage.

Apache Airflow Orchestration

Automates programmable workflows.

  • ETL DAG executed every 6 hours to keep the Data Warehouse updated.
  • Automatic reindexing DAG for Elasticsearch when catalog changes are detected.

Load Balancer (Nginx)

Distributes traffic (round-robin) among backend service instances and manages API routes in a unified manner.

Cache System (Redis)

Implements the Cache-Aside pattern to alleviate database load and reduce response times.


πŸš€ Installation

Prerequisites

  • Docker and Docker Compose
  • Git
  • Node.js and npm (for local development)

Clone the Repository

git clone https://github.com/DanielAR27/proyecto2-bases2.git
cd proyecto2-bases2
Module Installation (Local)

For each service that requires module installation (api, auth_service, search_service, graph_service), navigate to its folder and install:

cd <service_name>
npm install

πŸ› οΈ Build and Deployment

  1. Grant execution permissions to the scripts:
chmod +x set_config.sh init_cluster.sh init_hive_warehouse.sh
  1. Execute the main script:
./set_config.sh

This script starts the base services, initializes the MongoDB cluster (with sharding and replication), prepares the Hive warehouse, and starts the backend services.


πŸ“ˆ Generating Synthetic Data

If you want to populate the database with test data:

cd pruebas/
npm install
node generarDatosMasivos.js

πŸ”„ ETL, Airflow and OLAP Layer

  1. Start the ETL service:
docker-compose --profile etl up --build -d
  1. After the first execution, start Airflow (responsible for the periodic ETL):
docker-compose --profile airflow up --build -d
  1. Start the analytics dashboard:
docker-compose --profile analytics up --build -d

You can view the dashboards at http://localhost:8501/ and check the metrics logs:

docker logs -f spark_analytics

πŸ§ͺ Testing

The project includes unit and integration tests using Jest. They evaluate CRUD flows, security, resilience, and cache behavior.

Testing Commands

Authentication:

docker-compose --profile test build auth_test
docker-compose --profile test run --rm auth_test

Search:

docker-compose --profile test build search_test
docker-compose --profile test run --rm search_test

Main API:

docker-compose --profile test build api_test
docker-compose --profile test run --rm api_test

βš™οΈ CI/CD Pipeline

GitHub Actions is used for Continuous Integration and Continuous Deployment (CI/CD):

  • Test: Sets up the test infrastructure, runs microservices tests, and validates coverage.
  • Build-and-Push: If tests are successful on main/master, it builds multi-architecture Docker images and pushes them to the GitHub Container Registry.
  • Deploy: Generates an artifact with the Docker Compose configuration, scripts, and environment, preparing deployment documentation.

πŸ–₯️ Interface Access

API Documentation (Swagger)
  • Main API: http://localhost/api/api-docs/
  • Auth: http://localhost/auth/api-docs/
  • Search: http://localhost/search/api-docs/
  • Graphs: http://localhost/graph/api-docs/
Databases & Monitoring
  • PgAdmin (Postgres): http://localhost:5050 (Host: postgres_container, User: postgres, Pass: postgres)
  • Mongo Express: http://localhost:8081 (Check credentials in .env)
  • Kibana (Elasticsearch): http://localhost:5601

🧹 Environment Reset

To completely remove all containers, networks, and volumes:

docker-compose down -v

Last update: 21/8/2026

About

Distributed microservices platform with polyglot persistence (MongoDB, PostgreSQL, Neo4j, Redis, Elasticsearch) and a Spark/Hive ETL pipeline orchestrated with Airflow for OLAP analytics. Includes CI/CD with GitHub Actions and Nginx load balancing

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages