The shared/ directory is organized by import dependency tier to make it clear what's required at runtime and what's optional.
Always required. Minimal dependencies, no AI project imports.
- module_registry.py — Central import hub for all ai-projects; replaces all sys.path manipulation
- Other: script utilities, config validation, helpers
Import into other tiers without restriction.
from shared.core.module_registry import AIProjectsRegistry
# Instead of:
# from chat_providers import detect_provider
# from token_utils import prune_messages
# Use:
registry = AIProjectsRegistry()
chat_api = registry.chat_cli()
detect_provider = chat_api.detect_providerHeavy dependencies: SQL engines, Cosmos DB, telemetry, observability.
sql_engine.py— SQL connection pool managementcosmos_client.py— Azure Cosmos DB integrationtelemetry.py— Application Insights tracingdb_logging.py— Fault-tolerant DB logging
Must be imported with try/except and feature-flagged in production.
# In function_app.py:
try:
from shared.infrastructure.sql_engine import sql_health
db_available = True
except ImportError:
db_available = FalseCan depend on: Core tier
AI-specific utilities: Chat providers, memory systems, token management.
chat_providers.py— Chat provider detection, streaming, fallbackchat_memory.py— Semantic memory and embeddingstoken_utils.py— Token counting and context pruningagi_provider.py— AGI reasoning chain providerconfig_validator.py— YAML schema validation
Used by: AI endpoints (/api/chat), orchestrators, training scripts
Can depend on: Core, Infrastructure tiers
Lightweight helpers with no heavy dependencies.
file_cache.py— In-memory and disk cachinghttp_utils.py— HTTP client helpersjson_utils.py— JSON serialization utilitiesperformance_utils.py— Timing and profilingrequest_validator.py— Request schema validation
Can depend on: Core, Utilities, Domain (limited)
Feature-gated monetization and advanced features.
subscription_manager.py— Tier-based access control (FREE/PRO/ENTERPRISE)referral_system.py— Referral tracking and rewardsstripe_webhooks.py— Stripe payment webhooksemail_notifications.py— Email alerts and notifications
Must be imported with try/except; graceful fallback if missing.
# In function_app.py or endpoints:
try:
from shared.premium.subscription_manager import check_subscription
feature_available = check_subscription(user_id, 'quantum_jobs')
except ImportError:
feature_available = FalseCan depend on: Core, Utilities, Domain (limited)
Core
↑
│ depends on
│
Infrastructure, Domain, Utilities, Premium
↑
│
Applications (function_app.py, scripts/, apps/)
Rule: Never import upward in the dependency graph.
- ✗ Core cannot import from Domain or Infrastructure
- ✓ Domain can import from Core
- ✓ function_app.py can import from all tiers
- Clarity at deployment time — Know exactly what's required vs optional
- Easier to deprecate — Move old modules to
shared/deprecated/without breaking core - Safe feature gating — Premium features don't crash if not available
- Testing — Mock entire tiers without affecting Core
- Microservice extraction — Move Infrastructure tier to separate service later
# ✓ Core imports
from shared.core.module_registry import AIProjectsRegistry
# ✓ Infrastructure imports (with try/except where applicable)
from shared.infrastructure.sql_engine import sql_health
from shared.infrastructure.telemetry import get_tracer
# ✓ Domain imports
from shared.domain.chat_providers import detect_provider
from shared.domain.token_utils import prune_messages
from shared.domain.chat_memory import retrieve_similar
# ✓ Utilities imports
from shared.utilities.file_cache import FileCache
from shared.utilities.performance_utils import timer
# ✓ Premium imports (always with try/except)
try:
from shared.premium.subscription_manager import get_subscription_tier
except ImportError:
get_subscription_tier = lambda uid: "FREE"Each tier should have a clear __init__.py that exports public APIs:
# shared/domain/__init__.py
from .chat_providers import detect_provider, BaseChatProvider
__all__ = ['detect_provider', 'BaseChatProvider']# ❌ Old: root-level shims (deprecated)
from chat_providers import detect_provider
from token_utils import prune_messages
# ✓ New: use registry
from shared.core.module_registry import AIProjectsRegistry
registry = AIProjectsRegistry()
chat_api = registry.chat_cli()
detect_provider = chat_api.detect_provider
prune_messages = chat_api.token_utils.prune_messages# ❌ Old: scattered sys.path
sys.path.insert(0, 'ai-projects/chat-cli/src')
sys.path.insert(0, 'ai-projects/quantum-ml/src')
# ✓ New: centralized registration
from shared.core.module_registry import AIProjectsRegistry
AIProjectsRegistry.register_paths(['chat-cli', 'quantum-ml'])- Move modules to tiers gradually — Start with Infrastructure, Domain, Utilities
- Update imports in function_app.py — Use AIProjectsRegistry for ai-projects
- Create ai.py files in each ai-project — Define public API contracts
- Add safe fallback imports — Wrap Infrastructure and Premium imports with try/except
- Update .github/instructions/ — Document new import patterns for future AI agents