MCPcopy Create free account
hub / github.com/DeusData/codebase-memory-mcp / arch_layers

Function arch_layers

src/store/store.c:9591–9679  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

9589}
9590
9591static int arch_layers(cbm_store_t *s, const char *project, const char *path,
9592 cbm_architecture_info_t *out) {
9593 /* Get boundaries for fan analysis */
9594 cbm_cross_pkg_boundary_t *boundaries = NULL;
9595 int bcount = 0;
9596 int rc = arch_boundaries(s, project, path, &boundaries, &bcount);
9597 if (rc != CBM_STORE_OK) {
9598 return rc;
9599 }
9600
9601 /* Collect route and entry point packages */
9602 char *route_pkgs[CBM_SZ_32];
9603 int nrpkgs =
9604 collect_pkg_names(s, "SELECT qualified_name FROM nodes WHERE project=?1 AND label='Route'",
9605 project, path, route_pkgs, CBM_SZ_32);
9606
9607 char *entry_pkgs[CBM_SZ_32];
9608 int nepkgs = collect_pkg_names(s,
9609 "SELECT qualified_name FROM nodes WHERE project=?1 AND "
9610 "json_extract(properties, '$.is_entry_point') = 1",
9611 project, path, entry_pkgs, CBM_SZ_32);
9612
9613 /* Compute fan-in/out per package */
9614 char *all_pkgs[CBM_SZ_64];
9615 int fan_in[CBM_SZ_64];
9616 int fan_out[CBM_SZ_64];
9617 int npkgs = 0;
9618 memset(fan_in, 0, sizeof(fan_in));
9619 memset(fan_out, 0, sizeof(fan_out));
9620
9621 for (int i = 0; i < bcount; i++) {
9622 int fi = find_or_add_pkg(all_pkgs, &npkgs, ST_MAX_PKGS, boundaries[i].from);
9623 if (fi >= 0) {
9624 fan_out[fi] += boundaries[i].call_count;
9625 }
9626 int ti = find_or_add_pkg(all_pkgs, &npkgs, ST_MAX_PKGS, boundaries[i].to);
9627 if (ti >= 0) {
9628 fan_in[ti] += boundaries[i].call_count;
9629 }
9630 }
9631
9632 /* Also include route/entry packages */
9633 for (int i = 0; i < nrpkgs; i++) {
9634 find_or_add_pkg(all_pkgs, &npkgs, ST_MAX_PKGS, route_pkgs[i]);
9635 }
9636 for (int i = 0; i < nepkgs; i++) {
9637 find_or_add_pkg(all_pkgs, &npkgs, ST_MAX_PKGS, entry_pkgs[i]);
9638 }
9639
9640 /* Classify each package */
9641 out->layers = (npkgs > 0) ? calloc(npkgs, sizeof(cbm_package_layer_t)) : NULL;
9642 out->layer_count = npkgs;
9643 for (int i = 0; i < npkgs; i++) {
9644 bool has_route = pkg_in_list(all_pkgs[i], route_pkgs, nrpkgs);
9645 bool has_entry = pkg_in_list(all_pkgs[i], entry_pkgs, nepkgs);
9646 const char *layer;
9647 const char *reason;
9648 classify_layer(all_pkgs[i], fan_in[i], fan_out[i], has_route, has_entry, &layer, &reason);

Callers 1

Calls 7

arch_boundariesFunction · 0.85
collect_pkg_namesFunction · 0.85
find_or_add_pkgFunction · 0.85
pkg_in_listFunction · 0.85
classify_layerFunction · 0.85
safe_str_freeFunction · 0.85
heap_strdupFunction · 0.70

Tested by

no test coverage detected