;; ---------------------------------------------------------------------------
;; Glue Decoupling
;; ---------------------------------------------------------------------------

(defcomp ()
  (~docs/page :title "Cross-App Decoupling via Glue Services"

    (~docs/section :title "Context" :id "context"
      (p "All cross-domain FK constraints have been dropped (with pragmatic exceptions for OrderItem.product_id and CartItem). Cross-domain writes go through internal HTTP and activity bus. However, " (strong "25+ cross-app model imports remain") " — apps still import from each other's models/ directories. This means every app needs every other app's code on disk to start.")
      (p "The goal: eliminate all cross-app model imports. Every app only imports from its own models/, from shared/, and from a new glue/ service layer."))

    (~docs/section :title "Current state" :id "current"
      (p "Apps are partially decoupled via HTTP interfaces (fetch_data, call_action, send_internal_activity) and DTOs. The Cart microservice split (relations, likes, orders) is complete. But direct model imports persist in:")
      (ul (~tw :tokens "list-disc pl-5 text-stone-700 space-y-1")
        (li (strong "Cart") " — 9 files importing from market, events, blog")
        (li (strong "Blog") " — 8 files importing from cart, events, market")
        (li (strong "Events") " — 5 files importing from blog, market, cart")
        (li (strong "Market") " — 1 file importing from blog")))

    (~docs/section :title "What remains" :id "remains"
      (div (~tw :tokens "space-y-3")
        (div (~tw :tokens "rounded border border-stone-200 p-3")
          (h4 (~tw :tokens "font-semibold text-stone-700") "1. glue/services/pages.py")
          (p (~tw :tokens "text-sm text-stone-600") "Dict-based Post access for non-blog apps: get_page_by_slug, get_page_by_id, get_pages_by_ids, page_exists, search_posts."))
        (div (~tw :tokens "rounded border border-stone-200 p-3")
          (h4 (~tw :tokens "font-semibold text-stone-700") "2. glue/services/page_config.py")
          (p (~tw :tokens "text-sm text-stone-600") "PageConfig CRUD: get_page_config, get_or_create_page_config, get_page_configs_by_ids."))
        (div (~tw :tokens "rounded border border-stone-200 p-3")
          (h4 (~tw :tokens "font-semibold text-stone-700") "3. glue/services/calendars.py")
          (p (~tw :tokens "text-sm text-stone-600") "Calendar queries + entry associations (from blog): get_calendars_for_page, toggle_entry_association, get_associated_entries."))
        (div (~tw :tokens "rounded border border-stone-200 p-3")
          (h4 (~tw :tokens "font-semibold text-stone-700") "4. glue/services/marketplaces.py")
          (p (~tw :tokens "text-sm text-stone-600") "MarketPlace CRUD (from blog+events): get_marketplaces_for_page, create_marketplace, soft_delete_marketplace."))
        (div (~tw :tokens "rounded border border-stone-200 p-3")
          (h4 (~tw :tokens "font-semibold text-stone-700") "5. glue/services/cart_items.py")
          (p (~tw :tokens "text-sm text-stone-600") "CartItem/CalendarEntry queries for cart: get_cart_items, find_or_create_cart_item, clear_cart_for_order."))
        (div (~tw :tokens "rounded border border-stone-200 p-3")
          (h4 (~tw :tokens "font-semibold text-stone-700") "6. glue/services/products.py")
          (p (~tw :tokens "text-sm text-stone-600") "Minimal Product access for cart orders: get_product."))
        (div (~tw :tokens "rounded border border-stone-200 p-3")
          (h4 (~tw :tokens "font-semibold text-stone-700") "7. Model registration + cleanup")
          (p (~tw :tokens "text-sm text-stone-600") "register_models() in glue/setup.py, update all app.py files, delete moved service files."))))

    (~docs/section :title "Docker consideration" :id "docker"
      (p (~tw :tokens "text-stone-600") "For glue services to work in Docker (single app per container), model files from other apps must be importable. Recommended: try/except at import time — glue services that can't import a model raise ImportError at call time, which only happens if called from the wrong app."))))

;; ---------------------------------------------------------------------------
;; Social Sharing
;; ---------------------------------------------------------------------------
