# Synthetic 25-asset enterprise topology (illustrative, hand-built).
# Edge convention: from -> to means "from depends on to".
build_nodes <- function(params) {
nodes <- tribble(
~name, ~tier_num, ~asset_type,
"Cloud_IAM", 0, "identity",
"Root_DNS", 0, "dns",
"IdP_Auth_Okta", 0, "identity",
"Secrets_Vault", 0, "secrets",
"Kafka_Bus", 0, "message_bus",
"Core_Postgres_DB", 1, "database",
"Redis_Session_Cache", 1, "cache",
"S3_Asset_Store", 1, "object_store",
"Ledger_DB", 1, "database",
"Elastic_Search", 1, "search",
"Payment_Execution_API", 2, "service",
"Order_Routing_Svc", 2, "service",
"Fraud_Engine", 2, "service",
"Settlement_API", 2, "service",
"User_Profile_Svc", 2, "service",
"Notification_Gateway", 2, "service",
"Invoicing_API", 2, "service",
"KYC_Verification_API", 2, "service",
"Risk_Scoring_Engine", 2, "service",
"Inventory_Svc", 2, "service",
"Edge_Cloudflare_CDN", 3, "cdn",
"Ingress_WAF_Gateway", 3, "gateway",
"Web_Client_Gateway", 3, "gateway",
"Mobile_API_Gateway", 3, "gateway",
"Partner_B2B_Gateway", 3, "gateway"
)
bw <- params$business_weight
bw$status <- NULL
stopifnot(all(names(bw) %in% nodes$name), abs(sum(unlist(bw)) - 1) < 1e-12)
q <- params$annual_failure_prob
q$status <- NULL
nodes |>
mutate(
id = row_number(),
tier = factor(tier_levels[tier_num + 1], levels = tier_levels),
business_weight = map_dbl(name, \(x) bw[[x]] %||% 0),
annual_failure_prob = map_dbl(asset_type, \(x) q[[x]])
) |>
relocate(id)
}
dep <- function(from, ...) tibble(from_name = from, to_name = c(...))
# Original topology from the first version of the study (56 edges, a DAG)
edges_v1_raw <- function() {
bind_rows(
dep("Edge_Cloudflare_CDN", "Ingress_WAF_Gateway", "Root_DNS"),
dep("Ingress_WAF_Gateway", "Web_Client_Gateway", "Mobile_API_Gateway", "Partner_B2B_Gateway"),
dep("Web_Client_Gateway", "IdP_Auth_Okta", "User_Profile_Svc", "Order_Routing_Svc"),
dep("Mobile_API_Gateway", "IdP_Auth_Okta", "User_Profile_Svc", "Payment_Execution_API"),
dep("Partner_B2B_Gateway", "IdP_Auth_Okta", "Order_Routing_Svc", "Payment_Execution_API"),
dep("User_Profile_Svc", "IdP_Auth_Okta", "Core_Postgres_DB", "Redis_Session_Cache", "Cloud_IAM"),
dep("Order_Routing_Svc", "Inventory_Svc", "Fraud_Engine", "Kafka_Bus", "Core_Postgres_DB"),
dep("Inventory_Svc", "Core_Postgres_DB", "Redis_Session_Cache", "Secrets_Vault"),
dep("Fraud_Engine", "Risk_Scoring_Engine", "Elastic_Search", "Redis_Session_Cache", "Kafka_Bus"),
dep("Risk_Scoring_Engine", "Core_Postgres_DB", "Elastic_Search", "Secrets_Vault"),
dep("KYC_Verification_API", "Secrets_Vault", "S3_Asset_Store", "Core_Postgres_DB"),
dep("Payment_Execution_API", "Secrets_Vault", "Fraud_Engine", "Ledger_DB", "Kafka_Bus"),
dep("Settlement_API", "Ledger_DB", "Secrets_Vault", "Kafka_Bus"),
dep("Invoicing_API", "Ledger_DB", "S3_Asset_Store", "Notification_Gateway"),
dep("Notification_Gateway", "Kafka_Bus", "Redis_Session_Cache"),
dep("Core_Postgres_DB", "Secrets_Vault", "Cloud_IAM"),
dep("Ledger_DB", "Secrets_Vault", "Cloud_IAM"),
dep("Redis_Session_Cache", "Secrets_Vault"),
dep("S3_Asset_Store", "Cloud_IAM"),
dep("Elastic_Search", "Cloud_IAM"),
dep("Kafka_Bus", "Secrets_Vault", "Cloud_IAM")
) |>
mutate(hard = NA, weight = 1)
}
# v2 adds dependencies that almost every real enterprise has.
edges_v2_raw <- function(nodes) {
extra <- bind_rows(
# Every asset resolves names through DNS (the CDN edge already exists in v1)
tibble(
from_name = setdiff(nodes$name, c("Root_DNS", "Edge_Cloudflare_CDN")),
to_name = "Root_DNS"
),
# Vault authenticates clients through cloud IAM and persists to object storage
dep("Secrets_Vault", "Cloud_IAM", "S3_Asset_Store"),
# Cloud IAM federates human access through the corporate IdP; workloads keep
# running if the IdP is down, so this edge is soft (set below)
dep("Cloud_IAM", "IdP_Auth_Okta"),
# Bootstrap secret: IAM's signing keys are held in the vault. With
# Secrets_Vault -> Cloud_IAM this closes a circular recovery dependency.
dep("Cloud_IAM", "Secrets_Vault")
) |>
mutate(hard = NA, weight = 1)
bind_rows(edges_v1_raw(), extra)
}
# Attach integer ids and the hard/soft flag. Soft = the dependent degrades but survives.
index_edges <- function(edges, nodes, soft_targets) {
ids <- select(nodes, id, name)
edges |>
distinct(from_name, to_name, .keep_all = TRUE) |>
mutate(
hard = coalesce(hard, !(to_name %in% soft_targets)),
hard = if_else(from_name == "Cloud_IAM" & to_name == "IdP_Auth_Okta", FALSE, hard)
) |>
left_join(rename(ids, from = id), by = join_by(from_name == name)) |>
left_join(rename(ids, to = id), by = join_by(to_name == name)) |>
relocate(from, to, .after = to_name)
}
to_igraph <- function(nodes, edges) {
graph_from_data_frame(
d = select(edges, from_name, to_name, hard, weight),
vertices = select(nodes, name, tier, asset_type, business_weight),
directed = TRUE
)
}