# thuykat/azure-ai-order architecture

> Architecture diagram of the GitHub repository thuykat/azure-ai-order, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-03-30). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/thuykat/azure-ai-order
- Repository: https://github.com/thuykat/azure-ai-order

## Overview

##### Main Components
- Frontend: Represent the React application (located in frontend/voice-order). Include its core functional pages such as New Order Page, Order History Page, Edit Order Page, and Menu Scanner Page. Highlight key utilities such as voice command processing and state management.
- Backend: Include the Node.js/Express server (backend/server.js), MongoDB models (backend/models folder), and defined API endpoints (backend/routes). Also show utility scripts like the order processing and menu parsing utilities.
- Database: Indicate MongoDB as the data store that holds menu items and orders.
- Azure AI Services: Group together the various Azure services in use:
- Azure Speech Services (for real-time speech-to-text/recognition)
- Azure Language Understanding Service (for intent recognition and entity extraction)
- Azure Form Recognizer / Document Intelligence (for menu image/PDF processing)
- Azure OpenAI Service (for advanced menu interpretation and classification)
- External Integrations & Utilities: Include additional layers where GitHub Copilot has accelerated development through code generation and integration patterns.

##### Establish Relationships and Interactions
- The Frontend communicates with the Backend via HTTP API calls. This connection is used for sending processed speech data and receiving order confirmation or status updates.
- The Backend interacts with the MongoDB database for storing and retrieving order and menu information.
- Asynchronous process flows: after processing in the Frontend, the data flows to the Backend, which then confirms and updates order history.
- In the menu scanning process, illustrate the flow from image upload to Azure Form Recognizer to Azure OpenAI, ending with database updates.

##### Architectural Patterns and Design Principles
- Separation of Concerns: Clearly delineate the frontend and backend modules.
- Modular Component-Based Design in the React frontend: Represent pages, hooks, assets, and utilities as individual, inter-dependent modules.
- RESTful API Patterns: Illustrate the API routes and how they serve as a bridge between the frontend and backend.
- Cloud Service Integration: Emphasize the use of Azure AI services as microservices or external API calls integrated into both frontend and backend workflows.
- Event-driven architecture: Some components (e.g., live transcript updates and voice commands) should be depicted as event-driven (with callbacks and hooks).

##### Relevant Technologies
- Frontend: React, JavaScript (ES Modules), Vite as the build tool.
- Backend: Node.js, Express, MongoDB.
- Cloud/AI: Azure Speech Services, Azure Language Understanding, Azure Form Recognizer, Azure OpenAI.
- Additional: GitHub Copilot (as a note on the development acceleration role) and integration with tools like ESLint.

- Use clear, descriptive labels for each component (e.g., “New Order Page,” “Menu Scanner,” “Order API Route,” “Azure Speech Service”).
- Explicitly mark interactions like “API Call,” “Data Flow” and “Service Integration.”
- Annotations to note the development tools (e.g., GitHub Copilot) and how they influence the overall architecture.

- Detail the backend with API endpoints, data processing modules, and utility functions.
- Cloud interactions (each Azure service) and their specific roles (speaking to real-time processing, intent recognition, document processing, etc.).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Layer
    subgraph "Frontend Layer"
        VoiceOrderUI["Voice Order UI (React)"]:::frontend
        subgraph "Pages & Utilities"
            NewOrder["New Order Page"]:::frontend
            OrderHistory["Order History Page"]:::frontend
            EditOrder["Edit Order Page"]:::frontend
            MenuScanner["Menu Scanner Page"]:::frontend
            VoiceCmdUtil["Voice Command Processing Utility"]:::frontend
            SpeechHook["Speech Recognition Hook"]:::frontend
        end
    end

    %% Backend Layer
    subgraph "Backend Layer"
        ExpressServer["Express Server (Node.js/Express)"]:::backend
        subgraph "API Routes"
            OrderAPI["Order Management API"]:::backend
            LangAPI["Language Service API"]:::backend
            ScanMenuAPI["Menu Scanning API"]:::backend
            SpeechTokenAPI["Speech Token API"]:::backend
        end
        MenuUtils["Menu Processing Utilities"]:::backend
        MongoModels["MongoDB Models"]:::backend
    end

    %% Azure AI Services
    subgraph "Azure AI Services"
        AzureSpeech["Azure Speech Service"]:::azure
        AzureLanguage["Azure Language Understanding"]:::azure
        AzureFormRecognizer["Azure Form Recognizer"]:::azure
        AzureOpenAI["Azure OpenAI Service"]:::azure
    end

    %% Database
    subgraph "Database"
        MongoDB["MongoDB Database"]:::database
    end

    %% Frontend Internal Connections
    VoiceOrderUI -->|"navigates"| NewOrder
    VoiceOrderUI -->|"navigates"| OrderHistory
    VoiceOrderUI -->|"navigates"| EditOrder
    VoiceOrderUI -->|"navigates"| MenuScanner
    VoiceOrderUI ---|"uses"| VoiceCmdUtil
    VoiceOrderUI ---|"uses"| SpeechHook

    %% Frontend to Azure Services
    NewOrder ---|"voice_input"| AzureSpeech
    NewOrder ---|"intent_recognition"| AzureLanguage
    EditOrder ---|"voice_input"| AzureSpeech
    EditOrder ---|"intent_recognition"| AzureLanguage
    MenuScanner ---|"upload_menu"| AzureFormRecognizer
    AzureFormRecognizer ---|"extract_data"| AzureOpenAI
    AzureOpenAI ---|"data_processing"| ExpressServer

    %% Frontend to Backend Communication
    VoiceOrderUI -->|"API_call"| ExpressServer

    %% Backend API Routes Connections
    ExpressServer -->|"order_processing"| OrderAPI
    ExpressServer -->|"language_processing"| LangAPI
    ExpressServer -->|"menu_scanning"| ScanMenuAPI
    ExpressServer -->|"token_generation"| SpeechTokenAPI

    %% Backend to Database Connection
    ExpressServer -->|"DB_access"| MongoDB

    %% Backend Utilities Connection
    ExpressServer ---|"utilizes"| MenuUtils
    MenuUtils ---|"uses_models"| MongoModels

    %% Styling
    classDef frontend fill:#D6EAF8,stroke:#3498DB,stroke-width:2px;
    classDef backend fill:#FAD7A0,stroke:#F39C12,stroke-width:2px;
    classDef azure fill:#F5B7B1,stroke:#E74C3C,stroke-width:2px;
    classDef database fill:#D5F5E3,stroke:#27AE60,stroke-width:2px;

    %% Click Events
    click VoiceOrderUI "https://github.com/thuykat/azure-ai-order/tree/main/frontend/voice-order"
    click NewOrder "https://github.com/thuykat/azure-ai-order/tree/main/frontend/voice-order/src/pages/NewOrderPage"
    click OrderHistory "https://github.com/thuykat/azure-ai-order/tree/main/frontend/voice-order/src/pages/OrderHistoryPage"
    click EditOrder "https://github.com/thuykat/azure-ai-order/tree/main/frontend/voice-order/src/pages/EditOrderPage"
    click MenuScanner "https://github.com/thuykat/azure-ai-order/tree/main/frontend/voice-order/src/pages/MenuScanPage"
    click VoiceCmdUtil "https://github.com/thuykat/azure-ai-order/blob/main/frontend/voice-order/src/utils/voiceCommandProcessing.js"
    click SpeechHook "https://github.com/thuykat/azure-ai-order/blob/main/frontend/voice-order/src/hooks/useSpeechRecognition.js"
    click ExpressServer "https://github.com/thuykat/azure-ai-order/blob/main/backend/server.js"
    click OrderAPI "https://github.com/thuykat/azure-ai-order/blob/main/backend/routes/orders.js"
    click LangAPI "https://github.com/thuykat/azure-ai-order/blob/main/backend/routes/languageService.js"
    click ScanMenuAPI "https://github.com/thuykat/azure-ai-order/blob/main/backend/routes/scanMenuService.js"
    click SpeechTokenAPI "https://github.com/thuykat/azure-ai-order/blob/main/backend/routes/speechToken.js"
    click MongoModels "https://github.com/thuykat/azure-ai-order/tree/main/backend/models"
    click MenuUtils "https://github.com/thuykat/azure-ai-order/blob/main/backend/utils/processMenu.js"
```
