# nuxt-modules/medusa architecture

> Architecture diagram of the GitHub repository nuxt-modules/medusa, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-01-05). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/nuxt-modules/medusa
- Repository: https://github.com/nuxt-modules/medusa

## Overview

##### Main Components

a. Client-Side Components:
- Nuxt Application Layer
- useMedusaClient Composable
- Client-side API Handlers

b. Server-Side Components:
- Server Middleware Layer
- serverMedusaClient Service
- API Routes (/server/api)

c. External Systems:
- Medusa E-commerce Backend
- @medusajs/js-sdk Integration

**┌─────────────────────────────────────────────┐**
- Nuxt Application               │
- ┌─────────────────┐    ┌────────────────┐ │
- Components    │    │  Composables   │ │

- Vue Templates │    │- useMedusaClient│ │
- ┘    └────────────────┘ │
- ┤
- Server Middleware                │
- ┌─────────────────┐    ┌────────────────┐ │
- API Routes    │    │ServerMedusaClient│
- /products   │    │    Service      │ │
- /customer   │    │                │ │
- /regions    │    │                │ │
- ┘    └────────────────┘ │
- ┤
- External Services                │
- ┌─────────────────────────────────────────┐│
- Medusa E-commerce Backend       ││
- ┘│
- ┘

##### Key Relationships to Highlight

- How useMedusaClient composable communicates with Medusa backend
- Server middleware's role in handling API requests
- Demonstrate the connection between serverMedusaClient and Medusa backend
- Relationship between the module's components and the host Nuxt application

##### Important Implementation Details

- Configuration flow from .env (MEDUSA_URL)
- TypeScript integration points
- Module's plugin system
- Test coverage areas

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph "Nuxt Application Layer"
        direction TB
        NuxtApp["Nuxt Application"]
        Components["Vue Components"]
        Composables["Composables Layer"]
        UseMedusa["useMedusaClient"]:::composable
        Plugin["Plugin System"]:::plugin
        
        NuxtApp --> Components
        NuxtApp --> Composables
        Composables --> UseMedusa
        NuxtApp --> Plugin
    end

    subgraph "Server Middleware Layer"
        direction TB
        ServerMiddleware["Server Middleware"]
        APIRoutes["API Routes"]
        Products["Products API"]:::api
        Customer["Customer API"]:::api
        Regions["Regions API"]:::api
        ServerClient["serverMedusaClient Service"]:::service
        
        ServerMiddleware --> APIRoutes
        APIRoutes --> Products
        APIRoutes --> Customer
        APIRoutes --> Regions
        ServerMiddleware --> ServerClient
    end

    subgraph "External Services"
        MedusaBackend["Medusa E-commerce Backend"]
        MedusaSDK["@medusajs/js-sdk"]
    end

    subgraph "Configuration"
        ModuleConfig["Module Configuration"]:::config
        EnvConfig[".env Configuration"]
    end

    %% Connections between layers
    UseMedusa -.-> ServerMiddleware
    ServerClient --> MedusaBackend
    MedusaSDK --> MedusaBackend
    UseMedusa --> MedusaSDK
    ModuleConfig --> ServerMiddleware
    EnvConfig --> ModuleConfig

    %% Styling
    classDef api fill:#85C1E9,stroke:#2E86C1
    classDef service fill:#82E0AA,stroke:#27AE60
    classDef composable fill:#F8C471,stroke:#E67E22
    classDef config fill:#BB8FCE,stroke:#8E44AD
    classDef plugin fill:#F1948A,stroke:#E74C3C

    %% Click events
    click UseMedusa "https://github.com/nuxt-modules/medusa/blob/main/src/runtime/composables/useMedusaClient.ts"
    click ServerClient "https://github.com/nuxt-modules/medusa/blob/main/src/runtime/server/services/serverMedusaClient.ts"
    click Products "https://github.com/nuxt-modules/medusa/blob/main/playground/server/api/products.ts"
    click Customer "https://github.com/nuxt-modules/medusa/blob/main/playground/server/api/customer.ts"
    click Regions "https://github.com/nuxt-modules/medusa/blob/main/playground/server/api/regions.ts"
    click ModuleConfig "https://github.com/nuxt-modules/medusa/blob/main/src/module.ts"
    click Plugin "https://github.com/nuxt-modules/medusa/blob/main/src/runtime/plugin.ts"

    %% Legend
    subgraph Legend
        direction TB
        L1["API Component"]:::api
        L2["Service Component"]:::service
        L3["Composable"]:::composable
        L4["Configuration"]:::config
        L5["Plugin"]:::plugin
    end
```
