跳到主要内容

Infrastructure Overview

This document provides an overview of the iHospita infrastructure architecture, including API gateway, observability stack, and deployment configuration.


Architecture Diagram

┌─────────────────────────────────────────────────────────────────────────────────┐
│ INFRASTRUCTURE OVERVIEW │
├─────────────────────────────────────────────────────────────────────────────────┤
│ │
│ CLIENTS │
│ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ │
│ │ Portal │ │ Console │ │ Queue │ │ Landing │ │
│ │ (React) │ │ (Next.js) │ │ (Next.js) │ │ (Next.js) │ │
│ └──────┬──────┘ └──────┬──────┘ └──────┬──────┘ └──────┬──────┘ │
│ │ │ │ │ │
│ └────────────────┴────────────────┴────────────────┘ │
│ │ │
│ ▼ │
│ ┌─────────────────────────────────────────────────────────────────────────┐ │
│ │ CLOUDFLARE (CDN + WAF) │ │
│ │ - DDoS Protection - SSL/TLS Termination - Edge Caching │ │
│ └─────────────────────────────────────────────────────────────────────────┘ │
│ │ │
│ ▼ │
│ ┌─────────────────────────────────────────────────────────────────────────┐ │
│ │ KONG API GATEWAY │ │
│ │ - Rate Limiting - Authentication - Load Balancing │ │
│ │ - Request Transform - Circuit Breaker - Health Checks │ │
│ │ │ │
│ │ Routes: │ │
│ │ /api/auth/* → Keycloak │ │
│ │ /api/hms/* → HMS Service │ │
│ │ /api/crm/* → CRM Service │ │
│ │ /api/payment/* → Payment Service │ │
│ │ /api/queue/* → Queue Service │ │
│ │ /api/report/* → Report Service │ │
│ └─────────────────────────────────────────────────────────────────────────┘ │
│ │ │
│ ┌──────────────────────────┼──────────────────────────┐ │
│ │ │ │ │
│ ▼ ▼ ▼ │
│ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ │
│ │ Keycloak │ │ NestJS │ │ NestJS │ │
│ │ (Identity) │ │ Services │ │ Report │ │
│ │ │ │ │ │ Service │ │
│ └──────┬──────┘ └──────┬──────┘ └──────┬──────┘ │
│ │ │ │ │
│ └──────────────────────────┼──────────────────────────┘ │
│ │ │
│ ▼ │
│ ┌─────────────────────────────────────────────────────────────────────────┐ │
│ │ DATA LAYER │ │
│ │ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ │ │
│ │ │ PostgreSQL │ │ PostgreSQL │ │ Redis │ │ S3/Spaces │ │ │
│ │ │ (App DB) │ │ (Keycloak) │ │ (Cache) │ │ (Storage) │ │ │
│ │ └─────────────┘ └─────────────┘ └─────────────┘ └─────────────┘ │ │
│ └─────────────────────────────────────────────────────────────────────────┘ │
│ │ │
│ ▼ │
│ ┌─────────────────────────────────────────────────────────────────────────┐ │
│ │ OBSERVABILITY STACK │ │
│ │ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ │ │
│ │ │ Prometheus │ │ Loki │ │ Grafana │ │ Tempo │ │ │
│ │ │ (Metrics) │ │ (Logs) │ │ (Dashboard) │ │ (Traces) │ │ │
│ │ └─────────────┘ └─────────────┘ └─────────────┘ └─────────────┘ │ │
│ └─────────────────────────────────────────────────────────────────────────┘ │
│ │
└─────────────────────────────────────────────────────────────────────────────────┘

Technology Stack

LayerTechnologyPurpose
CDN/WAFCloudflareDDoS protection, SSL termination, caching
API GatewayKong 3.5Rate limiting, auth, routing, load balancing
IdentityKeycloak 23OAuth2/OIDC, 2FA, user management
BackendNestJSMicroservices (hms, crm, payment, queue, report)
DatabasePostgreSQL 15Primary relational database
CacheRedis 7Session, caching, pub/sub, queues
StorageDigitalOcean SpacesS3-compatible object storage
MetricsPrometheusTime-series metrics collection
LogsLokiLog aggregation and querying
TracesTempoDistributed tracing
DashboardsGrafanaVisualization and alerting
ContainerDockerContainerization
OrchestrationDocker ComposeContainer orchestration

Service Endpoints

ServiceInternal URLKong Route
Keycloakhttp://keycloak:8080/auth/*
HMS Servicehttp://hms-service:3000/api/hms/*
CRM Servicehttp://crm-service:3001/api/crm/*
Payment Servicehttp://payment-service:3002/api/payment/*
Queue Servicehttp://queue-service:3003/api/queue/*
Report Servicehttp://report-service:3004/api/report/*

Port Allocation

ServicePortPurpose
Kong Proxy8000HTTP API requests
Kong Proxy SSL8443HTTPS API requests
Kong Admin8001Kong admin API
Keycloak8080Identity provider
PostgreSQL5432Database
Redis6379Cache
Prometheus9090Metrics server
Grafana3000Dashboard UI
Loki3100Log aggregation
Tempo3200Trace collection

Network Architecture

┌─────────────────────────────────────────────────────────────┐
│ EXTERNAL NETWORK │
│ ┌─────────────────────────────────────────────────────┐ │
│ │ Internet → Cloudflare → Kong (8000/8443) │ │
│ └─────────────────────────────────────────────────────┘ │
└─────────────────────────────────────────────────────────────┘


┌─────────────────────────────────────────────────────────────┐
│ INTERNAL NETWORK │
│ ┌─────────────────────────────────────────────────────┐ │
│ │ Docker Network: ihospita-network (172.20.0.0/16) │ │
│ │ │ │
│ │ ┌──────────────────────────────────────────────┐ │ │
│ │ │ Services communicate via Docker DNS │ │ │
│ │ │ - kong → hms-service:3000 │ │ │
│ │ │ - hms-service → postgres:5432 │ │ │
│ │ │ - hms-service → redis:6379 │ │ │
│ │ └──────────────────────────────────────────────┘ │ │
│ └─────────────────────────────────────────────────────┘ │
└─────────────────────────────────────────────────────────────┘

Deployment Environments

EnvironmentPurposeURL Pattern
DevelopmentLocal developmentlocalhost:*
StagingPre-production testingstaging.ihospita.com
ProductionLive system*.ihospita.com