Skip to main content

API Gateway

Overview

An Express-based API Gateway for routing requests to microservices, handling authentication, logging, and error management. It serves as the entry point for client requests and coordinates communication between the gateway and underlying services.

Request Life-Cycle Summary

1.Client requestIncludes API key in header
2.MiddlewareHashes and verifies key (Cache --> Supabase)
3.MetricsLogged for Prometheus
4.Rate limiterEnforces request quotas
5.RequestProceeds to endpoint handler if verified
6.Supabase RPCUpdates usage counters asynchronously
7.Grafana dashboardVisualises metrics and logs

Service-Routing

The Servie Routing Map defines how incoming routes on the API Gateway are fowarded to corresponding microservices.

Each API Gateway route prefix (e.g. /synthesis) is mapped to the actual URL of its corresponding microservice.

const SERVICE_MAP = {
"/users": `http://users_service:${process.env.USERS_PORT}`,
"/products": `http://products_service:${process.env.PRODUCTS_PORT}`,
"/synthesis": `${process.env.SYNTHESIS}`,
};