# ezzeldinabdulhafiz/kubernetes-banking-platform architecture

> Architecture diagram of the GitHub repository ezzeldinabdulhafiz/kubernetes-banking-platform, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-04-13). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/ezzeldinabdulhafiz/kubernetes-banking-platform
- Repository: https://github.com/ezzeldinabdulhafiz/kubernetes-banking-platform

## Overview

1. **Repository purpose**
   - This repo implements a Kubernetes-deployed banking platform with three runtime components: a PostgreSQL data tier, a Node.js API, and a static web dashboard.
   - The core architecture is cloud-native and centered on Kubernetes resources rather than an in-process monolith.

2. **Runtime subsystems**
   - `app/banking-api` is the application backend. It is a Node.js/Express service that exposes banking endpoints and talks to PostgreSQL through connection pooling.
   - `app/banking-dashboard` is a static front end served by Nginx; it is the user-facing UI and consumes the API over HTTP.
   - PostgreSQL runs as a StatefulSet with replication, so the database tier is stateful and pod-identity-aware.

3. **Request/data flow**
   - User traffic enters through Kubernetes Ingress.
   - Requests to `/` are routed to the dashboard service, which serves the browser UI.
   - Requests to `/api/...` are routed to the API service, which performs reads/writes against PostgreSQL.
   - The database layer is split into primary and replica pods; the API is configured to use primary for writes and replica for reads.

4. **Application boundary**
   - The API is the main business-logic boundary: it owns account creation, transfers, transaction history, stats, and health/readiness endpoints.
   - The dashboard is intentionally thin and presentation-only; it does not own data persistence.
   - PostgreSQL is the system of record, with schema tables for `accounts` and `transactions`.

5. **Kubernetes deployment model**
   - Everything is deployed into a dedicated `banking` namespace.
   - The database is implemented as a StatefulSet because it needs stable identities and persistent storage.
   - The API and dashboard are Deployments because they are stateless and horizontally replaceable.
   - Services sit between pods and consumers: headless service for PostgreSQL discovery, ClusterIP services for API and dashboard.

6. **Infrastructure and scheduling**
   - The cluster is expected to have labeled and tainted nodes, especially `high-memory` worker nodes and `database-only` taints for database placement.
   - PostgreSQL pods tolerate database-only nodes and are spread with pod anti-affinity for availability.
   - API pods also use anti-affinity, while the dashboard has its own scheduling constraints to keep placement predictable.

7. **Configuration and secrets**
   - Runtime configuration is split between ConfigMaps and Secrets.
   - The API receives database hostnames, port, DB name, and logging/transaction settings from config, while credentials come from a Secret.
   - The database init script is injected via a ConfigMap-backed script in `k8s/scripts/postgres-init.sh`, which is used to bootstrap replication/setup behavior.

8. **Security boundaries**
   - Pods run as non-root users and use hardened security contexts.
   - The API container uses a read-only root filesystem and drops unnecessary privileges.
   - NetworkPolicy, RBAC, and separate service accounts are present to constrain inter-pod and cluster access.
   - Sensitive values are not baked into images; they are externalized in Kubernetes secrets.

9. **Availability and scaling**
   - The API has multiple replicas, health checks, and is managed by HPA and VPA manifests for elasticity and resource tuning.
   - PostgreSQL replication provides database-level resilience; anti-affinity and PVCs help protect against node loss.
   - Probes (`/health`, `/ready`) are part of the API lifecycle, ensuring traffic only reaches healthy pods.

10. **Observability and ops**
   - A Fluentd DaemonSet collects logs cluster-wide.
   - The manifests include health, readiness, and resource constraints, indicating an emphasis on operational visibility and stability.
   - The setup script is the operational entry point: it can create the cluster, configure nodes, build images, deploy manifests, show status, and clean up.

11. **Packaging and delivery**
   - Each app component has its own Dockerfile, so images are built independently and deployed separately.
   - `setup.sh` orchestrates the full lifecycle; it is the main automation boundary between local workstation and cluster deployment.
   - The repo is therefore organized around infrastructure-as-code plus two containerized app artifacts, not around a single server application.

12. **What an architecture diagram should show**
   - Three main tiers: browser/dashboard, API service, PostgreSQL cluster.
   - Kubernetes control plane objects around them: namespace, services, ingress, StatefulSet/Deployments, ConfigMap/Secret, policies, autoscaling, logging.
   - Clear directional flow from user → ingress → dashboard/API → database, with replication between PostgreSQL primary and replica.

Main entry points: [`app/banking-api/app.js`](https://github.com/ezzeldinabdulhafiz/kubernetes-banking-platform/blob/main/app/banking-api/app.js) (Banking API), [`k8s/03-postgres-statefulset.yaml`](https://github.com/ezzeldinabdulhafiz/kubernetes-banking-platform/blob/main/k8s/03-postgres-statefulset.yaml) (PostgreSQL), [`setup.sh`](https://github.com/ezzeldinabdulhafiz/kubernetes-banking-platform/blob/main/setup.sh) (Setup Script), [`k8s/07-ingress.yaml`](https://github.com/ezzeldinabdulhafiz/kubernetes-banking-platform/blob/main/k8s/07-ingress.yaml) (Ingress)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_workloads["Workloads"]
  node_user(("User<br/>client"))
  node_dashboard["Dashboard<br/>nginx static app<br/>[index.html]"]
  node_api["Banking API<br/>node express service<br/>[app.js]"]
end

subgraph group_platform["Platform"]
  node_ingress{{"Ingress<br/>routing<br/>[07-ingress.yaml]"}}
  node_dashboard_service["Dashboard Svc<br/>clusterip service<br/>[06-services.yaml]"]
  node_api_service["API Svc<br/>clusterip service<br/>[06-services.yaml]"]
  node_postgres_statefulset[("PostgreSQL<br/>statefulset")]
  node_postgres_service["DB Svc<br/>headless service<br/>[06-services.yaml]"]
  node_postgres_primary[("Primary Pod<br/>db primary")]
  node_postgres_replica[("Replica Pod<br/>db replica")]
  node_config["ConfigMap<br/>runtime config<br/>[01-configmap.yaml]"]
  node_secret["Secret<br/>credentials<br/>[02-secret.yaml]"]
  node_autoscaling{{"Autoscaling<br/>hpa/vpa<br/>[08-hpa.yaml]"}}
  node_policy{{"Policy<br/>[10-rbac.yaml]"}}
end

subgraph group_ops["Ops"]
  node_fluentd["Fluentd<br/>daemonset"]
  node_setup["Setup Script<br/>automation<br/>[setup.sh]"]
end

node_user -->|"HTTP traffic"| node_ingress
node_ingress -->|"/"| node_dashboard_service
node_ingress -->|"/api"| node_api_service
node_dashboard_service -->|"serves"| node_dashboard
node_api_service -->|"serves"| node_api
node_api -->|"connects"| node_postgres_service
node_postgres_service -->|"discover"| node_postgres_primary
node_postgres_service -->|"discover"| node_postgres_replica
node_api -->|"writes"| node_postgres_primary
node_api -->|"reads"| node_postgres_replica
node_postgres_primary -->|"replicates"| node_postgres_replica
node_postgres_statefulset -->|"manages"| node_postgres_primary
node_postgres_statefulset -->|"manages"| node_postgres_replica
node_config -->|"configures"| node_api
node_secret -->|"credentials"| node_api
node_config -->|"bootstraps"| node_postgres_statefulset
node_autoscaling -->|"scales"| node_api
node_policy -->|"restricts"| node_api
node_policy -->|"restricts"| node_postgres_statefulset
node_fluentd -->|"collects logs"| node_api
node_fluentd -->|"collects logs"| node_dashboard
node_fluentd -->|"collects logs"| node_postgres_statefulset
node_setup -->|"deploys"| node_ingress
node_setup -->|"builds/deploys"| node_api
node_setup -->|"builds/deploys"| node_dashboard
node_setup -->|"deploys"| node_postgres_statefulset

click node_ingress "https://github.com/ezzeldinabdulhafiz/kubernetes-banking-platform/blob/main/k8s/07-ingress.yaml"
click node_dashboard_service "https://github.com/ezzeldinabdulhafiz/kubernetes-banking-platform/blob/main/k8s/06-services.yaml"
click node_dashboard "https://github.com/ezzeldinabdulhafiz/kubernetes-banking-platform/blob/main/app/banking-dashboard/index.html"
click node_api_service "https://github.com/ezzeldinabdulhafiz/kubernetes-banking-platform/blob/main/k8s/06-services.yaml"
click node_api "https://github.com/ezzeldinabdulhafiz/kubernetes-banking-platform/blob/main/app/banking-api/app.js"
click node_postgres_statefulset "https://github.com/ezzeldinabdulhafiz/kubernetes-banking-platform/blob/main/k8s/03-postgres-statefulset.yaml"
click node_postgres_service "https://github.com/ezzeldinabdulhafiz/kubernetes-banking-platform/blob/main/k8s/06-services.yaml"
click node_postgres_primary "https://github.com/ezzeldinabdulhafiz/kubernetes-banking-platform/blob/main/k8s/03-postgres-statefulset.yaml"
click node_postgres_replica "https://github.com/ezzeldinabdulhafiz/kubernetes-banking-platform/blob/main/k8s/03-postgres-statefulset.yaml"
click node_config "https://github.com/ezzeldinabdulhafiz/kubernetes-banking-platform/blob/main/k8s/01-configmap.yaml"
click node_secret "https://github.com/ezzeldinabdulhafiz/kubernetes-banking-platform/blob/main/k8s/02-secret.yaml"
click node_autoscaling "https://github.com/ezzeldinabdulhafiz/kubernetes-banking-platform/blob/main/k8s/08-hpa.yaml"
click node_policy "https://github.com/ezzeldinabdulhafiz/kubernetes-banking-platform/blob/main/k8s/10-rbac.yaml"
click node_fluentd "https://github.com/ezzeldinabdulhafiz/kubernetes-banking-platform/blob/main/k8s/12-daemonset-fluentd.yaml"
click node_setup "https://github.com/ezzeldinabdulhafiz/kubernetes-banking-platform/blob/main/setup.sh"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_user,node_dashboard,node_api toneBlue
class node_ingress,node_dashboard_service,node_api_service,node_postgres_statefulset,node_postgres_service,node_postgres_primary,node_postgres_replica,node_config,node_secret,node_autoscaling,node_policy toneAmber
class node_fluentd,node_setup toneMint
```

## Components

### Workloads

Application runtimes and user-facing traffic

- **User**: client · Browser user accessing the platform
- [Dashboard](https://github.com/ezzeldinabdulhafiz/kubernetes-banking-platform/blob/main/app/banking-dashboard/index.html): nginx static app · Presentation-only web UI served by Nginx · `app/banking-dashboard/index.html`
- [Banking API](https://github.com/ezzeldinabdulhafiz/kubernetes-banking-platform/blob/main/app/banking-api/app.js): node express service · Business logic for accounts, transfers, history, and health · `app/banking-api/app.js`

### Platform

Kubernetes objects and data tier

- [Ingress](https://github.com/ezzeldinabdulhafiz/kubernetes-banking-platform/blob/main/k8s/07-ingress.yaml): routing · Entry point routing web and API traffic · `k8s/07-ingress.yaml`
- [Dashboard Svc](https://github.com/ezzeldinabdulhafiz/kubernetes-banking-platform/blob/main/k8s/06-services.yaml): clusterip service · Routes browser requests to the dashboard pods · `k8s/06-services.yaml`
- [API Svc](https://github.com/ezzeldinabdulhafiz/kubernetes-banking-platform/blob/main/k8s/06-services.yaml): clusterip service · Stable endpoint for banking API traffic · `k8s/06-services.yaml`
- [PostgreSQL](https://github.com/ezzeldinabdulhafiz/kubernetes-banking-platform/blob/main/k8s/03-postgres-statefulset.yaml): statefulset · Stateful database tier with stable identities and storage · `k8s/03-postgres-statefulset.yaml`
- [DB Svc](https://github.com/ezzeldinabdulhafiz/kubernetes-banking-platform/blob/main/k8s/06-services.yaml): headless service · Discovery for PostgreSQL pods · `k8s/06-services.yaml`
- [Primary Pod](https://github.com/ezzeldinabdulhafiz/kubernetes-banking-platform/blob/main/k8s/03-postgres-statefulset.yaml): db primary · Write target for the API · `k8s/03-postgres-statefulset.yaml`
- [Replica Pod](https://github.com/ezzeldinabdulhafiz/kubernetes-banking-platform/blob/main/k8s/03-postgres-statefulset.yaml): db replica · Read replica used for read traffic · `k8s/03-postgres-statefulset.yaml`
- [ConfigMap](https://github.com/ezzeldinabdulhafiz/kubernetes-banking-platform/blob/main/k8s/01-configmap.yaml): runtime config · Non-secret settings and init script source · `k8s/01-configmap.yaml`
- [Secret](https://github.com/ezzeldinabdulhafiz/kubernetes-banking-platform/blob/main/k8s/02-secret.yaml): credentials · Database credentials and sensitive runtime values · `k8s/02-secret.yaml`
- [Autoscaling](https://github.com/ezzeldinabdulhafiz/kubernetes-banking-platform/blob/main/k8s/08-hpa.yaml): hpa/vpa · Horizontal and vertical scaling policies for the API · `k8s/08-hpa.yaml`
- [Policy](https://github.com/ezzeldinabdulhafiz/kubernetes-banking-platform/blob/main/k8s/10-rbac.yaml): rbac/networkpolicy · Access control boundaries for pods and cluster traffic · `k8s/10-rbac.yaml`

### Ops

Automation, security, and observability

- [Fluentd](https://github.com/ezzeldinabdulhafiz/kubernetes-banking-platform/blob/main/k8s/12-daemonset-fluentd.yaml): daemonset · Cluster-wide log collection · `k8s/12-daemonset-fluentd.yaml`
- [Setup Script](https://github.com/ezzeldinabdulhafiz/kubernetes-banking-platform/blob/main/setup.sh): automation · Lifecycle automation for cluster creation, deploy, status, and cleanup · `setup.sh`

## Connections

- User → Ingress: HTTP traffic · Browser traffic enters the cluster through ingress
- Ingress → Dashboard Svc: / · Routes root requests to the dashboard
- Ingress → API Svc: /api · Routes API requests to the banking backend
- Dashboard Svc → Dashboard: serves · Cluster service targets dashboard pods
- API Svc → Banking API: serves · Cluster service targets API pods
- Banking API → DB Svc: connects · API reaches the database through discovery service
- DB Svc → Primary Pod: discover · Primary identity used for writes
- DB Svc → Replica Pod: discover · Replica identity used for reads
- Banking API → Primary Pod: writes · Account and transaction updates go to the primary
- Banking API → Replica Pod: reads · Read-heavy queries can use the replica
- Primary Pod → Replica Pod: replicates · Database-level replication keeps data in sync
- PostgreSQL → Primary Pod: manages · StatefulSet owns the primary pod identity
- PostgreSQL → Replica Pod: manages · StatefulSet owns replica pod identity
- ConfigMap → Banking API: configures · API receives database and logging settings from config
- Secret → Banking API: credentials · API consumes database credentials from secret
- ConfigMap → PostgreSQL: bootstraps · Init script helps bootstrap PostgreSQL replication/setup
- Autoscaling → Banking API: scales · HPA and VPA tune API replicas and resources
- Policy → Banking API: restricts · RBAC and network policy constrain API access
- Policy → PostgreSQL: restricts · Policy limits database access and pod interactions
- Fluentd → Banking API: collects logs · DaemonSet gathers workload logs cluster-wide
- Fluentd → Dashboard: collects logs · DaemonSet gathers frontend logs cluster-wide
- Fluentd → PostgreSQL: collects logs · DaemonSet gathers database logs cluster-wide
- Setup Script → Ingress: deploys · Automation applies cluster manifests and resources
- Setup Script → Banking API: builds/deploys · Automation builds images and deploys the API
- Setup Script → Dashboard: builds/deploys · Automation builds images and deploys the dashboard
- Setup Script → PostgreSQL: deploys · Automation creates the stateful database tier
