# muslly-pharmcy/ympharma-b21a19fb architecture

> Architecture diagram of the GitHub repository muslly-pharmcy/ympharma-b21a19fb, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-11-21). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/muslly-pharmcy/ympharma-b21a19fb
- Repository: https://github.com/muslly-pharmcy/ympharma-b21a19fb

## Overview

MUSLLY AI OS is a healthcare operations platform for Yemen, combining a public pharmacy storefront, authenticated clinical and business workflows, and AI-assisted operations. The evidenced shopper path begins at the storefront and loads catalog data; authenticated routes enforce login, while domain APIs support operational work against Supabase. README capabilities also include the AI SUN runtime, functional planets, Mission Control, and specialized agents. Those broader subsystems are represented from documented capabilities and the repository tree; their internal wiring was not sampled, so uncertain links are omitted.

Main entry points: [`src/lib/catalog.functions.ts`](https://github.com/muslly-pharmcy/ympharma-b21a19fb/blob/main/src/lib/catalog.functions.ts) (Catalog service), [`src/lib/ai/runtime/kernel.server.ts`](https://github.com/muslly-pharmcy/ympharma-b21a19fb/blob/main/src/lib/ai/runtime/kernel.server.ts) (AI SUN kernel), [`src/routes/index.tsx`](https://github.com/muslly-pharmcy/ympharma-b21a19fb/blob/main/src/routes/index.tsx) (Storefront entry), [`src/integrations/supabase/client.server.ts`](https://github.com/muslly-pharmcy/ympharma-b21a19fb/blob/main/src/integrations/supabase/client.server.ts) (Admin Supabase client)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_experience["User experience"]
  node_home["Storefront entry<br/>[index.tsx]"]
  node_storefront["Storefront<br/>[Storefront.tsx]"]
  node_authgate["Authenticated routes<br/>[route.tsx]"]
  node_aichat["AI chat<br/>[AIChat.tsx]"]
  node_mission["Mission Control<br/>[MissionControl.tsx]"]
end

subgraph group_operations["Health operations"]
  node_catalog["Catalog service"]
  node_clinical["Clinical engine<br/>[engine.server.ts]"]
  node_clinicalregistry["Clinical providers<br/>[registry.server.ts]"]
  node_medicaltools["Interaction checks"]
  node_inventory["Inventory operations"]
  node_reorder["Reorder planning"]
  node_crm["CRM segments<br/>[engine.server.ts]"]
  node_promotions["Promotion engine<br/>[engine.server.ts]"]
  node_planets["Functional planets<br/>[planets.ts]"]
end

subgraph group_intelligence["AI intelligence"]
  node_kernel{{"AI SUN kernel<br/>[kernel.server.ts]"}}
  node_agents["Specialist agents"]
end

subgraph group_platform["Platform services"]
  node_supabaseclient["Browser Supabase<br/>[client.ts]"]
  node_supabase[("Supabase database<br/>[types.ts]")]
  node_session["Session services<br/>[session.server.ts]"]
  node_serverclient["Admin Supabase client<br/>[client.server.ts]"]
end

node_shopper(("Shopper"))
node_staff(("Clinical staff"))
node_aiuser(("AI chat user"))

node_shopper -->|"opens"| node_home
node_home -->|"renders"| node_storefront
node_home -->|"loads catalog"| node_catalog
node_staff -->|"signs in"| node_authgate
node_authgate -->|"checks user"| node_supabaseclient
node_catalog -->|"uses session"| node_session
node_catalog -->|"reads catalog"| node_supabase
node_catalog -->|"invokes AI"| node_kernel
node_clinical -->|"resolves provider"| node_clinicalregistry
node_clinicalregistry -->|"selects provider"| node_serverclient
node_medicaltools -.->|"supports checks"| node_clinical
node_reorder -->|"reads and writes"| node_serverclient
node_crm -->|"queries customers"| node_serverclient
node_promotions -.->|"uses segment results"| node_crm
node_aiuser -.->|"asks"| node_aichat
node_aichat -.->|"routes request"| node_kernel
node_kernel -.->|"dispatches"| node_agents
node_mission -.->|"monitors"| node_kernel
node_planets -.->|"represented in"| node_mission

click node_home "https://github.com/muslly-pharmcy/ympharma-b21a19fb/blob/main/src/routes/index.tsx"
click node_storefront "https://github.com/muslly-pharmcy/ympharma-b21a19fb/blob/main/src/pages/Storefront.tsx"
click node_catalog "https://github.com/muslly-pharmcy/ympharma-b21a19fb/blob/main/src/lib/catalog.functions.ts"
click node_authgate "https://github.com/muslly-pharmcy/ympharma-b21a19fb/blob/main/src/routes/_authenticated/route.tsx"
click node_supabaseclient "https://github.com/muslly-pharmcy/ympharma-b21a19fb/blob/main/src/integrations/supabase/client.ts"
click node_supabase "https://github.com/muslly-pharmcy/ympharma-b21a19fb/blob/main/src/integrations/supabase/types.ts"
click node_clinical "https://github.com/muslly-pharmcy/ympharma-b21a19fb/blob/main/src/lib/clinical/engine.server.ts"
click node_clinicalregistry "https://github.com/muslly-pharmcy/ympharma-b21a19fb/blob/main/src/lib/clinical/registry.server.ts"
click node_medicaltools "https://github.com/muslly-pharmcy/ympharma-b21a19fb/blob/main/src/lib/medical/interaction-engine.ts"
click node_inventory "https://github.com/muslly-pharmcy/ympharma-b21a19fb/blob/main/src/lib/inventory.functions.ts"
click node_reorder "https://github.com/muslly-pharmcy/ympharma-b21a19fb/blob/main/src/lib/inventory/reorder-engine.server.ts"
click node_crm "https://github.com/muslly-pharmcy/ympharma-b21a19fb/blob/main/src/lib/segments/engine.server.ts"
click node_promotions "https://github.com/muslly-pharmcy/ympharma-b21a19fb/blob/main/src/lib/promotions/engine.server.ts"
click node_aichat "https://github.com/muslly-pharmcy/ympharma-b21a19fb/blob/main/src/pages/AIChat.tsx"
click node_kernel "https://github.com/muslly-pharmcy/ympharma-b21a19fb/blob/main/src/lib/ai/runtime/kernel.server.ts"
click node_agents "https://github.com/muslly-pharmcy/ympharma-b21a19fb/blob/main/src/super-agent/sun-guardian.agent.ts"
click node_mission "https://github.com/muslly-pharmcy/ympharma-b21a19fb/blob/main/src/pages/MissionControl.tsx"
click node_planets "https://github.com/muslly-pharmcy/ympharma-b21a19fb/blob/main/src/data/planets.ts"
click node_session "https://github.com/muslly-pharmcy/ympharma-b21a19fb/blob/main/src/lib/session.server.ts"
click node_serverclient "https://github.com/muslly-pharmcy/ympharma-b21a19fb/blob/main/src/integrations/supabase/client.server.ts"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_home,node_storefront,node_authgate,node_aichat,node_mission,node_aiuser toneBlue
class node_catalog,node_clinical,node_clinicalregistry,node_medicaltools,node_inventory,node_reorder,node_crm,node_promotions,node_planets toneAmber
class node_kernel,node_agents toneMint
class node_supabaseclient,node_supabase,node_session,node_serverclient toneRose
class node_shopper,node_staff toneIndigo
```

## Components

### User experience

- [Storefront entry](https://github.com/muslly-pharmcy/ympharma-b21a19fb/blob/main/src/routes/index.tsx): `src/routes/index.tsx`
- [Storefront](https://github.com/muslly-pharmcy/ympharma-b21a19fb/blob/main/src/pages/Storefront.tsx): `src/pages/Storefront.tsx`
- [Authenticated routes](https://github.com/muslly-pharmcy/ympharma-b21a19fb/blob/main/src/routes/_authenticated/route.tsx): `src/routes/_authenticated/route.tsx`
- [AI chat](https://github.com/muslly-pharmcy/ympharma-b21a19fb/blob/main/src/pages/AIChat.tsx): `src/pages/AIChat.tsx`
- [Mission Control](https://github.com/muslly-pharmcy/ympharma-b21a19fb/blob/main/src/pages/MissionControl.tsx): `src/pages/MissionControl.tsx`

### Health operations

- [Catalog service](https://github.com/muslly-pharmcy/ympharma-b21a19fb/blob/main/src/lib/catalog.functions.ts): `src/lib/catalog.functions.ts`
- [Clinical engine](https://github.com/muslly-pharmcy/ympharma-b21a19fb/blob/main/src/lib/clinical/engine.server.ts): `src/lib/clinical/engine.server.ts`
- [Clinical providers](https://github.com/muslly-pharmcy/ympharma-b21a19fb/blob/main/src/lib/clinical/registry.server.ts): `src/lib/clinical/registry.server.ts`
- [Interaction checks](https://github.com/muslly-pharmcy/ympharma-b21a19fb/blob/main/src/lib/medical/interaction-engine.ts): `src/lib/medical/interaction-engine.ts`
- [Inventory operations](https://github.com/muslly-pharmcy/ympharma-b21a19fb/blob/main/src/lib/inventory.functions.ts): `src/lib/inventory.functions.ts`
- [Reorder planning](https://github.com/muslly-pharmcy/ympharma-b21a19fb/blob/main/src/lib/inventory/reorder-engine.server.ts): `src/lib/inventory/reorder-engine.server.ts`
- [CRM segments](https://github.com/muslly-pharmcy/ympharma-b21a19fb/blob/main/src/lib/segments/engine.server.ts): `src/lib/segments/engine.server.ts`
- [Promotion engine](https://github.com/muslly-pharmcy/ympharma-b21a19fb/blob/main/src/lib/promotions/engine.server.ts): `src/lib/promotions/engine.server.ts`
- [Functional planets](https://github.com/muslly-pharmcy/ympharma-b21a19fb/blob/main/src/data/planets.ts): `src/data/planets.ts`

### AI intelligence

- [AI SUN kernel](https://github.com/muslly-pharmcy/ympharma-b21a19fb/blob/main/src/lib/ai/runtime/kernel.server.ts): `src/lib/ai/runtime/kernel.server.ts`
- [Specialist agents](https://github.com/muslly-pharmcy/ympharma-b21a19fb/blob/main/src/super-agent/sun-guardian.agent.ts): `src/super-agent/sun-guardian.agent.ts`

### Platform services

- [Browser Supabase](https://github.com/muslly-pharmcy/ympharma-b21a19fb/blob/main/src/integrations/supabase/client.ts): `src/integrations/supabase/client.ts`
- [Supabase database](https://github.com/muslly-pharmcy/ympharma-b21a19fb/blob/main/src/integrations/supabase/types.ts): `src/integrations/supabase/types.ts`
- [Session services](https://github.com/muslly-pharmcy/ympharma-b21a19fb/blob/main/src/lib/session.server.ts): `src/lib/session.server.ts`
- [Admin Supabase client](https://github.com/muslly-pharmcy/ympharma-b21a19fb/blob/main/src/integrations/supabase/client.server.ts): `src/integrations/supabase/client.server.ts`

### Other components

- **Shopper**
- **Clinical staff**
- **AI chat user**

## Connections

- Shopper → Storefront entry: opens (evidence: `src/routes/index.tsx`)
- Storefront entry → Storefront: renders (evidence: `src/routes/index.tsx`)
- Storefront entry → Catalog service: loads catalog (evidence: `src/routes/index.tsx`)
- Clinical staff → Authenticated routes: signs in (evidence: `src/routes/_authenticated/route.tsx`)
- Authenticated routes → Browser Supabase: checks user (evidence: `src/routes/_authenticated/route.tsx`)
- Catalog service → Session services: uses session (evidence: `src/lib/catalog.functions.ts`)
- Catalog service → Supabase database: reads catalog (evidence: `src/lib/catalog.functions.ts`)
- Catalog service → AI SUN kernel: invokes AI (evidence: `src/lib/catalog.functions.ts`)
- Clinical engine → Clinical providers: resolves provider (evidence: `src/lib/clinical/engine.server.ts`)
- Clinical providers → Admin Supabase client: selects provider (evidence: `src/lib/clinical/registry.server.ts`)
- Interaction checks → Clinical engine: supports checks
- Reorder planning → Admin Supabase client: reads and writes (evidence: `src/lib/inventory/reorder-engine.server.ts`)
- CRM segments → Admin Supabase client: queries customers (evidence: `src/lib/segments/engine.server.ts`)
- Promotion engine → CRM segments: uses segment results
- AI chat user → AI chat: asks
- AI chat → AI SUN kernel: routes request
- AI SUN kernel → Specialist agents: dispatches
- Mission Control → AI SUN kernel: monitors
- Functional planets → Mission Control: represented in
