Analysis of foundation
to mabeam
Dependencies
This document analyzes the dependencies from the foundation
library to the mabeam
library. The goal is to identify and recommend solutions for dependencies that are undesirable, maintaining a clean separation of concerns where foundation
is the core framework and mabeam
is a feature built on top of it.
Summary of Findings
The analysis of grep -ir mabeam lib/foundation/*
reveals several files with references to mabeam
.
lib/foundation/application.ex
: Contains the most significant and problematic dependencies. It has leftover logic for a:mabeam
application startup phase, even though the service definitions have been moved to a separatemabeam
application. This is a code smell from an incomplete refactoring.lib/foundation/coordination/primitives.ex
: The module documentation mentionsMABEAM
as a consumer of these primitives. This is an acceptable conceptual dependency.lib/foundation/process_registry.ex
: The type definition for service names includes a{:mabeam, atom()}
variant, and an example mentions a:mabeam_agent
. This is acceptable loose coupling for a generic service registry.lib/foundation/services/service_behaviour.ex
: The module documentation mentions preparing forMABEAM
coordination. This is an acceptable conceptual dependency.lib/foundation/types/error.ex
: A comment mentions enhanced error fields forMABEAM
. The fields are generic for distributed systems, so this is not a hard dependency.
The primary issue is the leftover application logic in Foundation.Application
. Other references are acceptable for a core framework designed to be extended.
Detailed Analysis and Recommendations
1. lib/foundation/application.ex
- Finding: This file has multiple references to a
:mabeam
startup phase.- The
@type startup_phase
includes:mabeam
. @service_definitions
formabeam
are commented out with a note that they have been moved.build_supervision_tree
still callsbuild_phase_children(:mabeam)
.perform_graceful_shutdown
andgroup_services_by_phase
still include:mabeam
in their phase lists.
- The
- Impact: While this may not cause a runtime error (as no services are defined in the
:mabeam
phase), it makesFoundation.Application
aware of a specific feature module (mabeam
), which is a violation of dependency direction. It’s an incomplete refactoring. - Recommendation: Remove all logic related to the
:mabeam
phase fromFoundation.Application
.- Remove
:mabeam
from the@type startup_phase
definition. - In
build_supervision_tree
, remove themabeam_children
variable and its inclusion in the final children list. - In
perform_graceful_shutdown
, remove:mabeam
from theshutdown_phases
list. - In
group_services_by_phase
, remove:mabeam
from thephases
list. - The
MABEAM
application should be managed by a higher-level supervisor that composesFoundation
andMABEAM
.
- Remove
2. lib/foundation/coordination/primitives.ex
- Finding: The module documentation states that it provides primitives for
MABEAM
. - Impact: This is a documentation-level reference. It explains the motivation and intended use of the module. It does not create a code-level dependency.
- Recommendation: No action required. This is an acceptable way to document the relationship between a core framework and its extensions.
3. lib/foundation/process_registry.ex
- Finding:
- The
@type service_name
includes{:mabeam, atom()}
. - A documentation example uses a
:mabeam_agent
.
- The
- Impact: These are forms of very loose coupling.
- Allowing a
{:mabeam, atom()}
service name makes the registry more flexible and allowsmabeam
to namespace its services withoutfoundation
needing to know about themabeam
modules themselves. - The example is for documentation purposes.
- Allowing a
- Recommendation: No action required. The process registry is behaving as a generic service.
4. lib/foundation/services/service_behaviour.ex
- Finding: The module documentation states it prepares for
MABEAM
multi-agent coordination. - Impact: Similar to
primitives.ex
, this is a documentation-level reference. - Recommendation: No action required.
5. lib/foundation/types/error.ex
- Finding: A comment mentions that some fields are for
MABEAM
. - Impact: This is only a comment. The fields themselves are generic and useful for any distributed system.
- Recommendation: No action required.
Conclusion
The foundation
library is mostly well-decoupled from mabeam
. The only necessary change is to complete the refactoring in lib/foundation/application.ex
to remove the vestigial :mabeam
startup phase logic. The other references are acceptable and reflect foundation
’s role as a framework for modules like mabeam
.