# medusajs/medusa-eats architecture

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

- Interactive diagram: https://gitdiagram.com/medusajs/medusa-eats
- Repository: https://github.com/medusajs/medusa-eats

## Overview

##### Project Type and Core Components

a. Frontend Layer (Next.js)
- Store/Customer Interface
- Restaurant Dashboard
- Driver Dashboard
- Authentication System

b. Backend Layer (Medusa)
- API Services
- Workflow Engine
- Real-time Events System
- Database Layer

**Client Layer**

**Frontend Services**

**Backend Services**

**Data Layer**

##### Key Components

A. Client Layer
- Web Browsers
- Mobile Devices

B. Frontend Services (Next.js)
- Store Routes (/app/(store))
- Checkout System (/app/(checkout))
- Dashboard Routes (/app/dashboard)
- Real-time Components
- API Routes

C. Backend Services (Medusa)
- API Endpoints (/src/api)
- Module Services
- Delivery Module
- Restaurant Module
- Workflow Engine
- Delivery Workflows
- Restaurant Workflows
- User Workflows
- Real-time Event System

D. Data Layer
- PostgreSQL Database
- Redis (for real-time features)

##### Important Flows to Highlight

- Order Creation Flow
- Delivery Assignment Flow
- Real-time Status Updates
- Authentication Flow

##### Detailed Component Breakdown

Frontend Components:
- Store Interface
- Restaurant Listing
- Menu Display
- Cart Management
- Checkout System
- Order Tracking
- Dashboards
- Restaurant Dashboard
- Driver Dashboard

Backend Components:
- API Layer
- Store APIs
- Restaurant APIs
- Driver APIs
- Service Layer
- Delivery Service
- Restaurant Service
- User Service
- Workflow Engine
- Real-time Events

##### Additional Elements

Supporting elements:
- External service integrations
- Security layers
- Caching mechanisms
- API gateway
- Load balancers (if applicable)

##### Notes for Implementation

- Use standard UML or C4 model notation
- Keep component names consistent with codebase
- Clear boundaries between services
- Version numbers for major components
- Document all external dependencies

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Clients
        WB[Web Browsers]
        MD[Mobile Devices]
    end

    subgraph Frontend
        SI["Store Interface"]:::frontend
        click SI "https://github.com/medusajs/medusa-eats/tree/main/frontend/src/app/(store)"
        
        CD["Checkout System"]:::frontend
        click CD "https://github.com/medusajs/medusa-eats/tree/main/frontend/src/app/(checkout)"
        
        RD["Restaurant Dashboard"]:::frontend
        click RD "https://github.com/medusajs/medusa-eats/tree/main/frontend/src/app/dashboard/restaurant"
        
        DD["Driver Dashboard"]:::frontend
        click DD "https://github.com/medusajs/medusa-eats/tree/main/frontend/src/app/dashboard/driver"
        
        RT["Real-time Components"]:::frontend
        click RT "https://github.com/medusajs/medusa-eats/blob/main/frontend/src/components/dashboard/realtime-client.tsx"
        
        Auth["Authentication System"]:::frontend
        click Auth "https://github.com/medusajs/medusa-eats/tree/main/frontend/src/app/(store)/login"
        
        Cart["Cart Management"]:::frontend
        click Cart "https://github.com/medusajs/medusa-eats/tree/main/frontend/src/components/store/cart"
        
        OM["Order Management UI"]:::frontend
        click OM "https://github.com/medusajs/medusa-eats/tree/main/frontend/src/components/store/order"
        
        MM["Menu Management"]:::frontend
        click MM "https://github.com/medusajs/medusa-eats/tree/main/frontend/src/components/dashboard/menu"
    end

    subgraph Backend
        API["API Services"]:::backend
        click API "https://github.com/medusajs/medusa-eats/tree/main/backend/src/api/store"
        
        DM["Delivery Module"]:::backend
        click DM "https://github.com/medusajs/medusa-eats/tree/main/backend/src/modules/delivery"
        
        RM["Restaurant Module"]:::backend
        click RM "https://github.com/medusajs/medusa-eats/tree/main/backend/src/modules/restaurant"
        
        subgraph "Workflow Engine"
            DW["Delivery Workflows"]:::workflow
            click DW "https://github.com/medusajs/medusa-eats/tree/main/backend/src/workflows/delivery"
            
            RW["Restaurant Workflows"]:::workflow
            click RW "https://github.com/medusajs/medusa-eats/tree/main/backend/src/workflows/restaurant"
            
            UW["User Workflows"]:::workflow
            click UW "https://github.com/medusajs/medusa-eats/tree/main/backend/src/workflows/user"
        end
        
        RTS["Real-time Event System"]:::backend
        click RTS "https://github.com/medusajs/medusa-eats/tree/main/backend/src/api/store/deliveries/subscribe"
        
        OMS["Order Management Service"]:::backend
        click OMS "https://github.com/medusajs/medusa-eats/blob/main/backend/src/workflows/delivery/steps/create-order.ts"
        
        RS["Restaurant Service"]:::backend
        click RS "https://github.com/medusajs/medusa-eats/blob/main/backend/src/modules/restaurant/service.ts"
        
        DS["Driver Service"]:::backend
        click DS "https://github.com/medusajs/medusa-eats/blob/main/backend/src/modules/delivery/models/driver.ts"
    end

    subgraph "Data Layer"
        DB[(PostgreSQL)]:::database
        Redis[(Redis)]:::database
    end

    %% Client connections
    WB --> SI
    WB --> RD
    WB --> DD
    MD --> SI
    MD --> RD
    MD --> DD

    %% Frontend to Backend connections
    SI --> API
    CD --> API
    RD --> API
    DD --> API
    RT --> RTS
    Auth --> API
    Cart --> API
    OM --> OMS
    MM --> RM

    %% Backend internal connections
    API --> DM
    API --> RM
    DM --> DW
    RM --> RW
    API --> UW
    DW --> RTS
    RW --> RTS
    UW --> RTS
    
    %% Data layer connections
    DM --> DB
    RM --> DB
    RTS --> Redis
    
    %% Styles
    classDef frontend fill:#3498db,stroke:#2980b9,color:white
    classDef backend fill:#2ecc71,stroke:#27ae60,color:white
    classDef workflow fill:#9b59b6,stroke:#8e44ad,color:white
    classDef database fill:#f1c40f,stroke:#f39c12,color:black
    
    %% Legend
    subgraph Legend
        F[Frontend Component]:::frontend
        B[Backend Service]:::backend
        W[Workflow Component]:::workflow
        D[(Database)]:::database
    end
```
