# samgorax/sleepos architecture

> Architecture diagram of the GitHub repository samgorax/sleepos, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-02). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/samgorax/sleepos
- Repository: https://github.com/samgorax/sleepos

## Overview

SleepOS is a mattress and sleep-commerce platform with customer retail, AI guidance, B2B procurement, tender analysis, and administration capabilities. Its principal customer workflow is product discovery followed by account, order, and post-purchase services; the README also documents distinct AI, procurement, tender, and admin branches. The backend exposes those domains through a FastAPI router, while a separately hosted AI service accepts workflow requests. Frontend-to-backend wiring is not established by the excerpts, so no such edge is asserted; several domain implementations are represented at their service paths based on the tree and README.

Main entry points: [`backend/app/api/router.py`](https://github.com/samgorax/sleepos/blob/main/backend/app/api/router.py) (API routing), [`backend/app/api/v1/endpoints/orders.py`](https://github.com/samgorax/sleepos/blob/main/backend/app/api/v1/endpoints/orders.py) (Orders API), [`backend/app/api/v1/endpoints/auth.py`](https://github.com/samgorax/sleepos/blob/main/backend/app/api/v1/endpoints/auth.py) (Authentication API), [`backend/app/api/v1/endpoints/products.py`](https://github.com/samgorax/sleepos/blob/main/backend/app/api/v1/endpoints/products.py) (Product API)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_web["Customer experience"]
  node_web_experience["Retail and sleep pages"]
  node_b2b_pages["B2B workspace"]
  node_tender_pages["Tender solutions<br/>[page.tsx]"]
  node_customer_dashboard["Customer dashboard"]
  node_admin_dashboard["Admin dashboard"]
end

subgraph group_api["Platform API"]
  node_api_router["API routing<br/>[router.py]"]
  node_auth_api["Authentication API<br/>[auth.py]"]
  node_product_api["Product API<br/>[products.py]"]
  node_engagement_api["Engagement API<br/>[engagement.py]"]
  node_order_api["Orders API<br/>[orders.py]"]
  node_b2b_api["B2B API<br/>[b2b.py]"]
  node_tender_api["Tender API<br/>[tenders.py]"]
  node_warranty_api["Warranty API<br/>[warranties.py]"]
  node_admin_api["Admin API<br/>[admin.py]"]
  node_content_api["Content API<br/>[content.py]"]
  node_auth_service["Identity and tokens<br/>[auth_service.py]"]
  node_product_service["Catalog service<br/>[product_service.py]"]
  node_engagement_service["Engagement service"]
  node_order_service["Order service<br/>[order_service.py]"]
  node_b2b_service["B2B procurement<br/>[b2b_service.py]"]
  node_tender_service["Tender analysis<br/>[tender_service.py]"]
  node_warranty_service["Warranty lifecycle"]
  node_admin_service["Admin operations<br/>[admin_service.py]"]
  node_content_service["Content service<br/>[content_service.py]"]
  node_ai_api["AI API<br/>[ai.py]"]
end

subgraph group_ai["AI workflows"]
  node_ai_client["AI orchestrator<br/>[client.py]"]
  node_ai_service["AI workflow API<br/>[main.py]"]
  node_workflow_registry["Workflow registry<br/>[registry.py]"]
  node_mock_provider["Mock provider<br/>[mock.py]"]
end

subgraph group_integrations["External services"]
  node_payment_service["Payment service"]
  node_razorpay["Razorpay"]
end

node_customer(("Customer"))
node_procurement_user(("Procurement user"))
node_admin_user(("Admin"))

node_customer -->|"browses"| node_web_experience
node_customer -->|"uses"| node_customer_dashboard
node_procurement_user -->|"uses"| node_b2b_pages
node_procurement_user -->|"reviews tenders"| node_tender_pages
node_admin_user -->|"manages"| node_admin_dashboard
node_api_router -->|"routes"| node_auth_api
node_api_router -->|"routes"| node_product_api
node_api_router -->|"routes"| node_engagement_api
node_api_router -->|"routes"| node_order_api
node_api_router -->|"routes"| node_b2b_api
node_api_router -->|"routes"| node_tender_api
node_api_router -->|"routes"| node_warranty_api
node_api_router -->|"routes"| node_admin_api
node_api_router -->|"routes"| node_content_api
node_auth_api -->|"delegates to"| node_auth_service
node_product_api -->|"delegates to"| node_product_service
node_engagement_api -->|"delegates to"| node_engagement_service
node_order_api -->|"delegates to"| node_order_service
node_order_api -->|"creates payments"| node_payment_service
node_payment_service -->|"creates orders"| node_razorpay
node_b2b_api -->|"delegates to"| node_b2b_service
node_tender_api -->|"delegates to"| node_tender_service
node_warranty_api -->|"delegates to"| node_warranty_service
node_admin_api -->|"delegates to"| node_admin_service
node_content_api -->|"delegates to"| node_content_service
node_ai_api -->|"calls"| node_ai_client
node_ai_client -->|"posts workflow"| node_ai_service
node_ai_service -->|"dispatches"| node_workflow_registry
node_workflow_registry -->|"runs"| node_mock_provider

click node_web_experience "https://github.com/samgorax/sleepos/tree/main/frontend/src/components"
click node_b2b_pages "https://github.com/samgorax/sleepos/blob/main/frontend/src/components/b2b/b2b-solutions-page.tsx"
click node_tender_pages "https://github.com/samgorax/sleepos/blob/main/frontend/src/app/(marketing)/tender-solutions/page.tsx"
click node_customer_dashboard "https://github.com/samgorax/sleepos/blob/main/frontend/src/components/customer/customer-dashboard-page.tsx"
click node_admin_dashboard "https://github.com/samgorax/sleepos/blob/main/frontend/src/components/admin/admin-dashboard-page.tsx"
click node_api_router "https://github.com/samgorax/sleepos/blob/main/backend/app/api/router.py"
click node_auth_api "https://github.com/samgorax/sleepos/blob/main/backend/app/api/v1/endpoints/auth.py"
click node_product_api "https://github.com/samgorax/sleepos/blob/main/backend/app/api/v1/endpoints/products.py"
click node_engagement_api "https://github.com/samgorax/sleepos/blob/main/backend/app/api/v1/endpoints/engagement.py"
click node_order_api "https://github.com/samgorax/sleepos/blob/main/backend/app/api/v1/endpoints/orders.py"
click node_b2b_api "https://github.com/samgorax/sleepos/blob/main/backend/app/api/v1/endpoints/b2b.py"
click node_tender_api "https://github.com/samgorax/sleepos/blob/main/backend/app/api/v1/endpoints/tenders.py"
click node_warranty_api "https://github.com/samgorax/sleepos/blob/main/backend/app/api/v1/endpoints/warranties.py"
click node_admin_api "https://github.com/samgorax/sleepos/blob/main/backend/app/api/v1/endpoints/admin.py"
click node_content_api "https://github.com/samgorax/sleepos/blob/main/backend/app/api/v1/endpoints/content.py"
click node_auth_service "https://github.com/samgorax/sleepos/blob/main/backend/app/services/auth/auth_service.py"
click node_product_service "https://github.com/samgorax/sleepos/blob/main/backend/app/services/product_service.py"
click node_engagement_service "https://github.com/samgorax/sleepos/blob/main/backend/app/services/engagement_service.py"
click node_order_service "https://github.com/samgorax/sleepos/blob/main/backend/app/services/order_service.py"
click node_payment_service "https://github.com/samgorax/sleepos/blob/main/backend/app/services/payments/razorpay_service.py"
click node_b2b_service "https://github.com/samgorax/sleepos/blob/main/backend/app/services/b2b_service.py"
click node_tender_service "https://github.com/samgorax/sleepos/blob/main/backend/app/services/tender_service.py"
click node_warranty_service "https://github.com/samgorax/sleepos/blob/main/backend/app/services/warranty_service.py"
click node_admin_service "https://github.com/samgorax/sleepos/blob/main/backend/app/services/admin_service.py"
click node_content_service "https://github.com/samgorax/sleepos/blob/main/backend/app/services/content_service.py"
click node_ai_api "https://github.com/samgorax/sleepos/blob/main/backend/app/api/v1/endpoints/ai.py"
click node_ai_client "https://github.com/samgorax/sleepos/blob/main/backend/app/services/ai/client.py"
click node_ai_service "https://github.com/samgorax/sleepos/blob/main/ai-services/app/main.py"
click node_workflow_registry "https://github.com/samgorax/sleepos/blob/main/ai-services/app/workflows/registry.py"
click node_mock_provider "https://github.com/samgorax/sleepos/blob/main/ai-services/app/providers/mock.py"

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_web_experience,node_b2b_pages,node_tender_pages,node_customer_dashboard,node_admin_dashboard,node_procurement_user toneBlue
class node_api_router,node_auth_api,node_product_api,node_engagement_api,node_order_api,node_b2b_api,node_tender_api,node_warranty_api,node_admin_api,node_content_api,node_auth_service,node_product_service,node_engagement_service,node_order_service,node_b2b_service,node_tender_service,node_warranty_service,node_admin_service,node_content_service,node_ai_api toneAmber
class node_ai_client,node_ai_service,node_workflow_registry,node_mock_provider toneMint
class node_payment_service,node_razorpay toneRose
class node_customer,node_admin_user toneIndigo
```

## Components

### Customer experience

- [Retail and sleep pages](https://github.com/samgorax/sleepos/tree/main/frontend/src/components): `frontend/src/components`
- [B2B workspace](https://github.com/samgorax/sleepos/blob/main/frontend/src/components/b2b/b2b-solutions-page.tsx): `frontend/src/components/b2b/b2b-solutions-page.tsx`
- [Tender solutions](https://github.com/samgorax/sleepos/blob/main/frontend/src/app/(marketing)/tender-solutions/page.tsx): `frontend/src/app/(marketing)/tender-solutions/page.tsx`
- [Customer dashboard](https://github.com/samgorax/sleepos/blob/main/frontend/src/components/customer/customer-dashboard-page.tsx): `frontend/src/components/customer/customer-dashboard-page.tsx`
- [Admin dashboard](https://github.com/samgorax/sleepos/blob/main/frontend/src/components/admin/admin-dashboard-page.tsx): `frontend/src/components/admin/admin-dashboard-page.tsx`

### Platform API

- [API routing](https://github.com/samgorax/sleepos/blob/main/backend/app/api/router.py): `backend/app/api/router.py`
- [Authentication API](https://github.com/samgorax/sleepos/blob/main/backend/app/api/v1/endpoints/auth.py): `backend/app/api/v1/endpoints/auth.py`
- [Product API](https://github.com/samgorax/sleepos/blob/main/backend/app/api/v1/endpoints/products.py): `backend/app/api/v1/endpoints/products.py`
- [Engagement API](https://github.com/samgorax/sleepos/blob/main/backend/app/api/v1/endpoints/engagement.py): `backend/app/api/v1/endpoints/engagement.py`
- [Orders API](https://github.com/samgorax/sleepos/blob/main/backend/app/api/v1/endpoints/orders.py): `backend/app/api/v1/endpoints/orders.py`
- [B2B API](https://github.com/samgorax/sleepos/blob/main/backend/app/api/v1/endpoints/b2b.py): `backend/app/api/v1/endpoints/b2b.py`
- [Tender API](https://github.com/samgorax/sleepos/blob/main/backend/app/api/v1/endpoints/tenders.py): `backend/app/api/v1/endpoints/tenders.py`
- [Warranty API](https://github.com/samgorax/sleepos/blob/main/backend/app/api/v1/endpoints/warranties.py): `backend/app/api/v1/endpoints/warranties.py`
- [Admin API](https://github.com/samgorax/sleepos/blob/main/backend/app/api/v1/endpoints/admin.py): `backend/app/api/v1/endpoints/admin.py`
- [Content API](https://github.com/samgorax/sleepos/blob/main/backend/app/api/v1/endpoints/content.py): `backend/app/api/v1/endpoints/content.py`
- [Identity and tokens](https://github.com/samgorax/sleepos/blob/main/backend/app/services/auth/auth_service.py): `backend/app/services/auth/auth_service.py`
- [Catalog service](https://github.com/samgorax/sleepos/blob/main/backend/app/services/product_service.py): `backend/app/services/product_service.py`
- [Engagement service](https://github.com/samgorax/sleepos/blob/main/backend/app/services/engagement_service.py): `backend/app/services/engagement_service.py`
- [Order service](https://github.com/samgorax/sleepos/blob/main/backend/app/services/order_service.py): `backend/app/services/order_service.py`
- [B2B procurement](https://github.com/samgorax/sleepos/blob/main/backend/app/services/b2b_service.py): `backend/app/services/b2b_service.py`
- [Tender analysis](https://github.com/samgorax/sleepos/blob/main/backend/app/services/tender_service.py): `backend/app/services/tender_service.py`
- [Warranty lifecycle](https://github.com/samgorax/sleepos/blob/main/backend/app/services/warranty_service.py): `backend/app/services/warranty_service.py`
- [Admin operations](https://github.com/samgorax/sleepos/blob/main/backend/app/services/admin_service.py): `backend/app/services/admin_service.py`
- [Content service](https://github.com/samgorax/sleepos/blob/main/backend/app/services/content_service.py): `backend/app/services/content_service.py`
- [AI API](https://github.com/samgorax/sleepos/blob/main/backend/app/api/v1/endpoints/ai.py): `backend/app/api/v1/endpoints/ai.py`

### AI workflows

- [AI orchestrator](https://github.com/samgorax/sleepos/blob/main/backend/app/services/ai/client.py): `backend/app/services/ai/client.py`
- [AI workflow API](https://github.com/samgorax/sleepos/blob/main/ai-services/app/main.py): `ai-services/app/main.py`
- [Workflow registry](https://github.com/samgorax/sleepos/blob/main/ai-services/app/workflows/registry.py): `ai-services/app/workflows/registry.py`
- [Mock provider](https://github.com/samgorax/sleepos/blob/main/ai-services/app/providers/mock.py): `ai-services/app/providers/mock.py`

### External services

- [Payment service](https://github.com/samgorax/sleepos/blob/main/backend/app/services/payments/razorpay_service.py): `backend/app/services/payments/razorpay_service.py`
- **Razorpay**

### Other components

- **Customer**
- **Procurement user**
- **Admin**

## Connections

- Customer → Retail and sleep pages: browses (evidence: `README.md`)
- Customer → Customer dashboard: uses (evidence: `README.md`)
- Procurement user → B2B workspace: uses (evidence: `README.md`)
- Procurement user → Tender solutions: reviews tenders (evidence: `README.md`)
- Admin → Admin dashboard: manages (evidence: `README.md`)
- API routing → Authentication API: routes (evidence: `backend/app/api/router.py`)
- API routing → Product API: routes (evidence: `backend/app/api/router.py`)
- API routing → Engagement API: routes (evidence: `backend/app/api/router.py`)
- API routing → Orders API: routes (evidence: `backend/app/api/router.py`)
- API routing → B2B API: routes (evidence: `backend/app/api/router.py`)
- API routing → Tender API: routes (evidence: `backend/app/api/router.py`)
- API routing → Warranty API: routes (evidence: `backend/app/api/router.py`)
- API routing → Admin API: routes (evidence: `backend/app/api/router.py`)
- API routing → Content API: routes (evidence: `backend/app/api/router.py`)
- Authentication API → Identity and tokens: delegates to (evidence: `backend/app/api/v1/endpoints/auth.py`)
- Product API → Catalog service: delegates to (evidence: `backend/app/api/v1/endpoints/products.py`)
- Engagement API → Engagement service: delegates to (evidence: `backend/app/api/v1/endpoints/engagement.py`)
- Orders API → Order service: delegates to (evidence: `backend/app/api/v1/endpoints/orders.py`)
- Orders API → Payment service: creates payments (evidence: `backend/app/api/v1/endpoints/orders.py`)
- Payment service → Razorpay: creates orders (evidence: `backend/app/services/payments/razorpay_service.py`)
- B2B API → B2B procurement: delegates to (evidence: `backend/app/api/v1/endpoints/b2b.py`)
- Tender API → Tender analysis: delegates to (evidence: `backend/app/api/v1/endpoints/tenders.py`)
- Warranty API → Warranty lifecycle: delegates to (evidence: `backend/app/api/v1/endpoints/warranties.py`)
- Admin API → Admin operations: delegates to (evidence: `backend/app/api/v1/endpoints/admin.py`)
- Content API → Content service: delegates to (evidence: `backend/app/api/v1/endpoints/content.py`)
- AI API → AI orchestrator: calls (evidence: `backend/app/api/v1/endpoints/ai.py`)
- AI orchestrator → AI workflow API: posts workflow (evidence: `backend/app/services/ai/client.py`)
- AI workflow API → Workflow registry: dispatches (evidence: `ai-services/app/main.py`)
- Workflow registry → Mock provider: runs (evidence: `ai-services/app/workflows/registry.py`)
