| 9496 | } |
| 9497 | |
| 9498 | static void classify_layer(const char *pkg, int in, int out_deg, bool has_routes, |
| 9499 | bool has_entry_points, const char **layer, const char **reason) { |
| 9500 | static CBM_TLS char reason_buf[CBM_SZ_128]; |
| 9501 | if (has_entry_points && out_deg > 0 && in == 0) { |
| 9502 | *layer = "entry"; |
| 9503 | *reason = "has entry points, only outbound calls"; |
| 9504 | return; |
| 9505 | } |
| 9506 | if (has_routes) { |
| 9507 | *layer = "api"; |
| 9508 | *reason = "has HTTP route definitions"; |
| 9509 | return; |
| 9510 | } |
| 9511 | if (in > out_deg && in > ST_MIN_INDEGREE) { |
| 9512 | snprintf(reason_buf, sizeof(reason_buf), "high fan-in (%d in, %d out)", in, out_deg); |
| 9513 | *layer = "core"; |
| 9514 | *reason = reason_buf; |
| 9515 | return; |
| 9516 | } |
| 9517 | if (out_deg == 0 && in > 0) { |
| 9518 | *layer = "leaf"; |
| 9519 | *reason = "only inbound calls, no outbound"; |
| 9520 | return; |
| 9521 | } |
| 9522 | if (in == 0 && out_deg > 0) { |
| 9523 | *layer = "entry"; |
| 9524 | *reason = "only outbound calls"; |
| 9525 | return; |
| 9526 | } |
| 9527 | snprintf(reason_buf, sizeof(reason_buf), "fan-in=%d, fan-out=%d", in, out_deg); |
| 9528 | *layer = "internal"; |
| 9529 | *reason = reason_buf; |
| 9530 | (void)pkg; |
| 9531 | } |
| 9532 | |
| 9533 | /* Find or insert a package name, returning its index. Returns -1 if full. */ |
| 9534 | static int find_or_add_pkg(char **all_pkgs, int *npkgs, int max_pkgs, const char *pkg) { |