[importlinter]
root_packages =
    core
    configs
    controllers
    extensions
    models
    tasks
    services
include_external_packages = True

[importlinter:contract:workflow]
name = Workflow
type=layers
layers =
    graph_engine
    graph_events
    graph
    nodes
    node_events
    runtime
    entities
containers =
    core.workflow
ignore_imports =
    core.workflow.nodes.base.node -> core.workflow.graph_events
    core.workflow.nodes.iteration.iteration_node -> core.workflow.graph_events
    core.workflow.nodes.loop.loop_node -> core.workflow.graph_events

    core.workflow.nodes.iteration.iteration_node -> core.app.workflow.node_factory
    core.workflow.nodes.loop.loop_node -> core.app.workflow.node_factory

    core.workflow.nodes.iteration.iteration_node -> core.workflow.graph_engine
    core.workflow.nodes.iteration.iteration_node -> core.workflow.graph
    core.workflow.nodes.iteration.iteration_node -> core.workflow.graph_engine.command_channels
    core.workflow.nodes.loop.loop_node -> core.workflow.graph_engine
    core.workflow.nodes.loop.loop_node -> core.workflow.graph
    core.workflow.nodes.loop.loop_node -> core.workflow.graph_engine.command_channels
    # TODO(QuantumGhost): fix the import violation later
    core.workflow.entities.pause_reason -> core.workflow.nodes.human_input.entities

[importlinter:contract:workflow-infrastructure-dependencies]
name = Workflow Infrastructure Dependencies
type = forbidden
source_modules =
    core.workflow
forbidden_modules =
    extensions.ext_database
    extensions.ext_redis
allow_indirect_imports = True
ignore_imports =
    core.workflow.nodes.agent.agent_node -> extensions.ext_database
    core.workflow.nodes.datasource.datasource_node -> extensions.ext_database
    core.workflow.nodes.knowledge_index.knowledge_index_node -> extensions.ext_database
    core.workflow.nodes.llm.file_saver -> extensions.ext_database
    core.workflow.nodes.llm.llm_utils -> extensions.ext_database
    core.workflow.nodes.llm.node -> extensions.ext_database
    core.workflow.nodes.tool.tool_node -> extensions.ext_database
    core.workflow.graph_engine.command_channels.redis_channel -> extensions.ext_redis
    core.workflow.graph_engine.manager -> extensions.ext_redis
    # TODO(QuantumGhost): use DI to avoid depending on global DB.
    core.workflow.nodes.human_input.human_input_node -> extensions.ext_database

[importlinter:contract:workflow-external-imports]
name = Workflow External Imports
type = forbidden
source_modules =
    core.workflow
forbidden_modules =
    configs
    controllers
    extensions
    models
    services
    tasks
    core.agent
    core.app
    core.base
    core.callback_handler
    core.datasource
    core.db
    core.entities
    core.errors
    core.extension
    core.external_data_tool
    core.file
    core.helper
    core.hosting_configuration
    core.indexing_runner
    core.llm_generator
    core.logging
    core.mcp
    core.memory
    core.model_manager
    core.moderation
    core.ops
    core.plugin
    core.prompt
    core.provider_manager
    core.rag
    core.repositories
    core.schemas
    core.tools
    core.trigger
    core.variables
ignore_imports =
    core.workflow.nodes.loop.loop_node -> core.app.workflow.node_factory
    core.workflow.graph_engine.command_channels.redis_channel -> extensions.ext_redis
    core.workflow.workflow_entry -> core.app.workflow.layers.observability
    core.workflow.nodes.agent.agent_node -> core.model_manager
    core.workflow.nodes.agent.agent_node -> core.provider_manager
    core.workflow.nodes.agent.agent_node -> core.tools.tool_manager
    core.workflow.nodes.code.code_node -> core.helper.code_executor.code_executor
    core.workflow.nodes.datasource.datasource_node -> models.model
    core.workflow.nodes.datasource.datasource_node -> models.tools
    core.workflow.nodes.datasource.datasource_node -> services.datasource_provider_service
    core.workflow.nodes.document_extractor.node -> configs
    core.workflow.nodes.document_extractor.node -> core.file.file_manager
    core.workflow.nodes.document_extractor.node -> core.helper.ssrf_proxy
    core.workflow.nodes.http_request.entities -> configs
    core.workflow.nodes.http_request.executor -> configs
    core.workflow.nodes.http_request.executor -> core.file.file_manager
    core.workflow.nodes.http_request.node -> configs
    core.workflow.nodes.http_request.node -> core.tools.tool_file_manager
    core.workflow.nodes.iteration.iteration_node -> core.app.workflow.node_factory
    core.workflow.nodes.knowledge_index.knowledge_index_node -> core.rag.index_processor.index_processor_factory
    core.workflow.nodes.llm.llm_utils -> configs
    core.workflow.nodes.llm.llm_utils -> core.app.entities.app_invoke_entities
    core.workflow.nodes.llm.llm_utils -> core.file.models
    core.workflow.nodes.llm.llm_utils -> core.model_manager
    core.workflow.nodes.llm.llm_utils -> core.model_runtime.model_providers.__base.large_language_model
    core.workflow.nodes.llm.llm_utils -> models.model
    core.workflow.nodes.llm.llm_utils -> models.provider
    core.workflow.nodes.llm.llm_utils -> services.credit_pool_service
    core.workflow.nodes.llm.node -> core.tools.signature
    core.workflow.nodes.tool.tool_node -> core.callback_handler.workflow_tool_callback_handler
    core.workflow.nodes.tool.tool_node -> core.tools.tool_engine
    core.workflow.nodes.tool.tool_node -> core.tools.tool_manager
    core.workflow.workflow_entry -> configs
    core.workflow.workflow_entry -> models.workflow
    core.workflow.nodes.agent.agent_node -> core.agent.entities
    core.workflow.nodes.agent.agent_node -> core.agent.plugin_entities
    core.workflow.nodes.base.node -> core.app.entities.app_invoke_entities
    core.workflow.nodes.human_input.human_input_node -> core.app.entities.app_invoke_entities
    core.workflow.nodes.knowledge_index.knowledge_index_node -> core.app.entities.app_invoke_entities
    core.workflow.nodes.knowledge_retrieval.knowledge_retrieval_node -> core.app.app_config.entities
    core.workflow.nodes.llm.node -> core.app.entities.app_invoke_entities
    core.workflow.nodes.parameter_extractor.parameter_extractor_node -> core.app.entities.app_invoke_entities
    core.workflow.nodes.parameter_extractor.parameter_extractor_node -> core.prompt.advanced_prompt_transform
    core.workflow.nodes.parameter_extractor.parameter_extractor_node -> core.prompt.simple_prompt_transform
    core.workflow.nodes.parameter_extractor.parameter_extractor_node -> core.model_runtime.model_providers.__base.large_language_model
    core.workflow.nodes.question_classifier.question_classifier_node -> core.app.entities.app_invoke_entities
    core.workflow.nodes.question_classifier.question_classifier_node -> core.prompt.advanced_prompt_transform
    core.workflow.nodes.question_classifier.question_classifier_node -> core.prompt.simple_prompt_transform
    core.workflow.nodes.start.entities -> core.app.app_config.entities
    core.workflow.nodes.start.start_node -> core.app.app_config.entities
    core.workflow.workflow_entry -> core.app.apps.exc
    core.workflow.workflow_entry -> core.app.entities.app_invoke_entities
    core.workflow.workflow_entry -> core.app.workflow.node_factory
    core.workflow.nodes.datasource.datasource_node -> core.datasource.datasource_manager
    core.workflow.nodes.datasource.datasource_node -> core.datasource.utils.message_transformer
    core.workflow.nodes.llm.llm_utils -> core.entities.provider_entities
    core.workflow.nodes.parameter_extractor.parameter_extractor_node -> core.model_manager
    core.workflow.nodes.question_classifier.question_classifier_node -> core.model_manager
    core.workflow.node_events.node -> core.file
    core.workflow.nodes.agent.agent_node -> core.file
    core.workflow.nodes.datasource.datasource_node -> core.file
    core.workflow.nodes.datasource.datasource_node -> core.file.enums
    core.workflow.nodes.document_extractor.node -> core.file
    core.workflow.nodes.http_request.executor -> core.file.enums
    core.workflow.nodes.http_request.node -> core.file
    core.workflow.nodes.http_request.node -> core.file.file_manager
    core.workflow.nodes.knowledge_retrieval.knowledge_retrieval_node -> core.file.models
    core.workflow.nodes.list_operator.node -> core.file
    core.workflow.nodes.llm.file_saver -> core.file
    core.workflow.nodes.llm.llm_utils -> core.variables.segments
    core.workflow.nodes.llm.node -> core.file
    core.workflow.nodes.llm.node -> core.file.file_manager
    core.workflow.nodes.llm.node -> core.file.models
    core.workflow.nodes.loop.entities -> core.variables.types
    core.workflow.nodes.parameter_extractor.parameter_extractor_node -> core.file
    core.workflow.nodes.protocols -> core.file
    core.workflow.nodes.question_classifier.question_classifier_node -> core.file.models
    core.workflow.nodes.tool.tool_node -> core.file
    core.workflow.nodes.tool.tool_node -> core.tools.utils.message_transformer
    core.workflow.nodes.tool.tool_node -> models
    core.workflow.nodes.trigger_webhook.node -> core.file
    core.workflow.runtime.variable_pool -> core.file
    core.workflow.runtime.variable_pool -> core.file.file_manager
    core.workflow.system_variable -> core.file.models
    core.workflow.utils.condition.processor -> core.file
    core.workflow.utils.condition.processor -> core.file.file_manager
    core.workflow.workflow_entry -> core.file.models
    core.workflow.workflow_type_encoder -> core.file.models
    core.workflow.nodes.agent.agent_node -> models.model
    core.workflow.nodes.code.code_node -> core.helper.code_executor.code_node_provider
    core.workflow.nodes.code.code_node -> core.helper.code_executor.javascript.javascript_code_provider
    core.workflow.nodes.code.code_node -> core.helper.code_executor.python3.python3_code_provider
    core.workflow.nodes.code.entities -> core.helper.code_executor.code_executor
    core.workflow.nodes.datasource.datasource_node -> core.variables.variables
    core.workflow.nodes.http_request.executor -> core.helper.ssrf_proxy
    core.workflow.nodes.http_request.node -> core.helper.ssrf_proxy
    core.workflow.nodes.llm.file_saver -> core.helper.ssrf_proxy
    core.workflow.nodes.llm.node -> core.helper.code_executor
    core.workflow.nodes.template_transform.template_renderer -> core.helper.code_executor.code_executor
    core.workflow.nodes.llm.node -> core.llm_generator.output_parser.errors
    core.workflow.nodes.llm.node -> core.llm_generator.output_parser.structured_output
    core.workflow.nodes.llm.node -> core.model_manager
    core.workflow.nodes.agent.entities -> core.prompt.entities.advanced_prompt_entities
    core.workflow.nodes.llm.entities -> core.prompt.entities.advanced_prompt_entities
    core.workflow.nodes.llm.llm_utils -> core.prompt.entities.advanced_prompt_entities
    core.workflow.nodes.llm.node -> core.prompt.entities.advanced_prompt_entities
    core.workflow.nodes.llm.node -> core.prompt.utils.prompt_message_util
    core.workflow.nodes.parameter_extractor.entities -> core.prompt.entities.advanced_prompt_entities
    core.workflow.nodes.parameter_extractor.parameter_extractor_node -> core.prompt.entities.advanced_prompt_entities
    core.workflow.nodes.parameter_extractor.parameter_extractor_node -> core.prompt.utils.prompt_message_util
    core.workflow.nodes.question_classifier.entities -> core.prompt.entities.advanced_prompt_entities
    core.workflow.nodes.question_classifier.question_classifier_node -> core.prompt.utils.prompt_message_util
    core.workflow.nodes.knowledge_index.entities -> core.rag.retrieval.retrieval_methods
    core.workflow.nodes.knowledge_index.knowledge_index_node -> core.rag.retrieval.retrieval_methods
    core.workflow.nodes.knowledge_index.knowledge_index_node -> models.dataset
    core.workflow.nodes.knowledge_index.knowledge_index_node -> services.summary_index_service
    core.workflow.nodes.knowledge_index.knowledge_index_node -> tasks.generate_summary_index_task
    core.workflow.nodes.knowledge_index.knowledge_index_node -> core.rag.index_processor.processor.paragraph_index_processor
    core.workflow.nodes.llm.node -> models.dataset
    core.workflow.nodes.agent.agent_node -> core.tools.utils.message_transformer
    core.workflow.nodes.llm.file_saver -> core.tools.signature
    core.workflow.nodes.llm.file_saver -> core.tools.tool_file_manager
    core.workflow.nodes.tool.tool_node -> core.tools.errors
    core.workflow.conversation_variable_updater -> core.variables
    core.workflow.graph_engine.entities.commands -> core.variables.variables
    core.workflow.nodes.agent.agent_node -> core.variables.segments
    core.workflow.nodes.answer.answer_node -> core.variables
    core.workflow.nodes.code.code_node -> core.variables.segments
    core.workflow.nodes.code.code_node -> core.variables.types
    core.workflow.nodes.code.entities -> core.variables.types
    core.workflow.nodes.datasource.datasource_node -> core.variables.segments
    core.workflow.nodes.document_extractor.node -> core.variables
    core.workflow.nodes.document_extractor.node -> core.variables.segments
    core.workflow.nodes.http_request.executor -> core.variables.segments
    core.workflow.nodes.http_request.node -> core.variables.segments
    core.workflow.nodes.human_input.entities -> core.variables.consts
    core.workflow.nodes.iteration.iteration_node -> core.variables
    core.workflow.nodes.iteration.iteration_node -> core.variables.segments
    core.workflow.nodes.iteration.iteration_node -> core.variables.variables
    core.workflow.nodes.knowledge_retrieval.knowledge_retrieval_node -> core.variables
    core.workflow.nodes.knowledge_retrieval.knowledge_retrieval_node -> core.variables.segments
    core.workflow.nodes.list_operator.node -> core.variables
    core.workflow.nodes.list_operator.node -> core.variables.segments
    core.workflow.nodes.llm.node -> core.variables
    core.workflow.nodes.loop.loop_node -> core.variables
    core.workflow.nodes.parameter_extractor.entities -> core.variables.types
    core.workflow.nodes.parameter_extractor.exc -> core.variables.types
    core.workflow.nodes.parameter_extractor.parameter_extractor_node -> core.variables.types
    core.workflow.nodes.tool.tool_node -> core.variables.segments
    core.workflow.nodes.tool.tool_node -> core.variables.variables
    core.workflow.nodes.trigger_webhook.node -> core.variables.types
    core.workflow.nodes.trigger_webhook.node -> core.variables.variables
    core.workflow.nodes.variable_aggregator.entities -> core.variables.types
    core.workflow.nodes.variable_aggregator.variable_aggregator_node -> core.variables.segments
    core.workflow.nodes.variable_assigner.common.helpers -> core.variables
    core.workflow.nodes.variable_assigner.common.helpers -> core.variables.consts
    core.workflow.nodes.variable_assigner.common.helpers -> core.variables.types
    core.workflow.nodes.variable_assigner.v1.node -> core.variables
    core.workflow.nodes.variable_assigner.v2.helpers -> core.variables
    core.workflow.nodes.variable_assigner.v2.node -> core.variables
    core.workflow.nodes.variable_assigner.v2.node -> core.variables.consts
    core.workflow.runtime.graph_runtime_state_protocol -> core.variables.segments
    core.workflow.runtime.read_only_wrappers -> core.variables.segments
    core.workflow.runtime.variable_pool -> core.variables
    core.workflow.runtime.variable_pool -> core.variables.consts
    core.workflow.runtime.variable_pool -> core.variables.segments
    core.workflow.runtime.variable_pool -> core.variables.variables
    core.workflow.utils.condition.processor -> core.variables
    core.workflow.utils.condition.processor -> core.variables.segments
    core.workflow.variable_loader -> core.variables
    core.workflow.variable_loader -> core.variables.consts
    core.workflow.workflow_type_encoder -> core.variables
    core.workflow.graph_engine.manager -> extensions.ext_redis
    core.workflow.nodes.agent.agent_node -> extensions.ext_database
    core.workflow.nodes.datasource.datasource_node -> extensions.ext_database
    core.workflow.nodes.knowledge_index.knowledge_index_node -> extensions.ext_database
    core.workflow.nodes.llm.file_saver -> extensions.ext_database
    core.workflow.nodes.llm.llm_utils -> extensions.ext_database
    core.workflow.nodes.llm.node -> extensions.ext_database
    core.workflow.nodes.tool.tool_node -> extensions.ext_database
    core.workflow.nodes.human_input.human_input_node -> extensions.ext_database
    core.workflow.nodes.human_input.human_input_node -> core.repositories.human_input_repository
    core.workflow.workflow_entry -> extensions.otel.runtime
    core.workflow.nodes.agent.agent_node -> models
    core.workflow.nodes.base.node -> models.enums
    core.workflow.nodes.llm.llm_utils -> models.provider_ids
    core.workflow.nodes.llm.node -> models.model
    core.workflow.workflow_entry -> models.enums
    core.workflow.nodes.agent.agent_node -> services
    core.workflow.nodes.tool.tool_node -> services

[importlinter:contract:model-runtime-no-internal-imports]
name = Model Runtime Internal Imports
type = forbidden
source_modules =
    core.model_runtime
forbidden_modules =
    configs
    controllers
    extensions
    models
    services
    tasks
    core.agent
    core.app
    core.base
    core.callback_handler
    core.datasource
    core.db
    core.entities
    core.errors
    core.extension
    core.external_data_tool
    core.file
    core.helper
    core.hosting_configuration
    core.indexing_runner
    core.llm_generator
    core.logging
    core.mcp
    core.memory
    core.model_manager
    core.moderation
    core.ops
    core.plugin
    core.prompt
    core.provider_manager
    core.rag
    core.repositories
    core.schemas
    core.tools
    core.trigger
    core.variables
    core.workflow
ignore_imports =
    core.model_runtime.model_providers.__base.ai_model -> configs
    core.model_runtime.model_providers.__base.ai_model -> extensions.ext_redis
    core.model_runtime.model_providers.__base.large_language_model -> configs
    core.model_runtime.model_providers.__base.text_embedding_model -> core.entities.embedding_type
    core.model_runtime.model_providers.model_provider_factory -> configs
    core.model_runtime.model_providers.model_provider_factory -> extensions.ext_redis
    core.model_runtime.model_providers.model_provider_factory -> models.provider_ids

[importlinter:contract:rsc]
name = RSC
type = layers
layers =
    graph_engine
    response_coordinator
containers =
    core.workflow.graph_engine

[importlinter:contract:worker]
name = Worker
type = layers
layers =
    graph_engine
    worker
containers =
    core.workflow.graph_engine

[importlinter:contract:graph-engine-architecture]
name = Graph Engine Architecture
type = layers
layers =
    graph_engine
    orchestration
    command_processing
    event_management
    error_handler
    graph_traversal
    graph_state_manager
    worker_management
    domain
containers =
    core.workflow.graph_engine

[importlinter:contract:domain-isolation]
name = Domain Model Isolation
type = forbidden
source_modules =
    core.workflow.graph_engine.domain
forbidden_modules =
    core.workflow.graph_engine.worker_management
    core.workflow.graph_engine.command_channels
    core.workflow.graph_engine.layers
    core.workflow.graph_engine.protocols

[importlinter:contract:worker-management]
name = Worker Management
type = forbidden
source_modules =
    core.workflow.graph_engine.worker_management
forbidden_modules =
    core.workflow.graph_engine.orchestration
    core.workflow.graph_engine.command_processing
    core.workflow.graph_engine.event_management


[importlinter:contract:graph-traversal-components]
name = Graph Traversal Components
type = layers
layers =
    edge_processor
    skip_propagator
containers =
    core.workflow.graph_engine.graph_traversal

[importlinter:contract:command-channels]
name = Command Channels Independence
type = independence
modules =
    core.workflow.graph_engine.command_channels.in_memory_channel
    core.workflow.graph_engine.command_channels.redis_channel
