# ntgx/expo-bot-messenger architecture

> Architecture diagram of the GitHub repository ntgx/expo-bot-messenger, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2024-12-31). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/ntgx/expo-bot-messenger
- Repository: https://github.com/ntgx/expo-bot-messenger

## Overview

##### Main Components

a. External Services Layer:
- Facebook Messenger Platform
- API.ai (now Dialogflow) for NLP
- MongoDB (for data storage)

b. Application Core:
- Message Handler System
- Menu System
- Expo Information System
- Database Interface

c. Data Storage:
- JSON Data Store (static content)
- MongoDB (dynamic content)

##### User Interface Layer
- Facebook Messenger at the top
- Bidirectional connection to the application's webhook

##### Application Core (Middle Layer)
- Message Handling System:
- Handlers/ directory components (message.js, nlp.js, postback.js, start.js)
- To Menu System (menus/ directory)

- Expo Information System:
- Expo/ directory components as separate modules
- Exhibitors, events, schedule, speakers, sponsors modules

- Database Interface:
- Db/ directory components
- To MongoDB

##### Data Layer
- JSON files from data/ directory
- MongoDB connection

Use these specific visual elements:

- Blue: External services (Facebook, API.ai, MongoDB)
- Green: Core application components
- Yellow: Data storage
- Gray: Utility functions

- Double lines: Data flow

Important Implementation Details to Include:

##### Environment Configuration
- Config.js connection to external services
- Environment variables integration

##### Key Workflows
- User message processing flow
- NLP integration flow
- Data retrieval flow
- Lotto registration flow

##### Integration Points
- Facebook Messenger webhook
- API.ai NLP service
- MongoDB connection
- Static JSON data loading

Special Considerations:

1. Modular structure of the expo/ directory, as it contains the core business logic
##### Menu system's integration with the main application flow

Level of Detail:

- Keep the high-level architecture clear and visible
- Use subdiagrams for complex components (like the expo/ directory structure)
- Notes for important configuration requirements

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph External
        FB[Facebook Messenger Platform]:::external
        APIAI[API.ai / Dialogflow]:::external
        MDB[(MongoDB)]:::database
    end

    subgraph "Application Core"
        ENTRY["Entry Points"]:::core
        click ENTRY "https://github.com/ntgx/expo-bot-messenger/blob/master/app/index.js"
        
        subgraph "Message Handling"
            MH["Message Handler"]:::handler
            click MH "https://github.com/ntgx/expo-bot-messenger/blob/master/app/handlers/message.js"
            NLP["NLP Handler"]:::handler
            click NLP "https://github.com/ntgx/expo-bot-messenger/blob/master/app/handlers/nlp.js"
            PB["Postback Handler"]:::handler
            click PB "https://github.com/ntgx/expo-bot-messenger/blob/master/app/handlers/postback.js"
            ST["Start Handler"]:::handler
            click ST "https://github.com/ntgx/expo-bot-messenger/blob/master/app/handlers/start.js"
        end

        subgraph "Menu System"
            MM["Main Menu"]:::menu
            click MM "https://github.com/ntgx/expo-bot-messenger/blob/master/app/menus/main-menu.js"
            PM["Persistent Menu"]:::menu
            click PM "https://github.com/ntgx/expo-bot-messenger/blob/master/app/menus/persistent-menu.js"
        end

        subgraph "Expo Information"
            DAYS["Days"]:::expo
            click DAYS "https://github.com/ntgx/expo-bot-messenger/blob/master/app/expo/days.js"
            EVENTS["Events"]:::expo
            click EVENTS "https://github.com/ntgx/expo-bot-messenger/blob/master/app/expo/events.js"
            EXH["Exhibitors"]:::expo
            click EXH "https://github.com/ntgx/expo-bot-messenger/blob/master/app/expo/exhibitors.js"
            SCH["Schedule"]:::expo
            click SCH "https://github.com/ntgx/expo-bot-messenger/blob/master/app/expo/schedule.js"
            SPK["Speakers"]:::expo
            click SPK "https://github.com/ntgx/expo-bot-messenger/blob/master/app/expo/speakers.js"
            SPO["Sponsors"]:::expo
            click SPO "https://github.com/ntgx/expo-bot-messenger/blob/master/app/expo/sponsors.js"
            REG["Registration"]:::expo
            click REG "https://github.com/ntgx/expo-bot-messenger/blob/master/app/expo/register.js"
            FP["Floor Plan"]:::expo
            click FP "https://github.com/ntgx/expo-bot-messenger/blob/master/app/expo/floor-plan.js"
        end

        subgraph "Database Interface"
            SLP["Save Lotto Player"]:::db
            click SLP "https://github.com/ntgx/expo-bot-messenger/blob/master/app/db/save-lotto-player.js"
            UM["User Model"]:::db
            click UM "https://github.com/ntgx/expo-bot-messenger/blob/master/app/models/user.js"
        end

        CONFIG["Configuration"]:::util
        click CONFIG "https://github.com/ntgx/expo-bot-messenger/blob/master/app/config.js"
        
        UTILS["Parse JSON Utility"]:::util
        click UTILS "https://github.com/ntgx/expo-bot-messenger/blob/master/app/utils/parse-json.js"
    end

    subgraph "Data Storage"
        subgraph "Static JSON"
            EJ["Events JSON"]:::json
            click EJ "https://github.com/ntgx/expo-bot-messenger/blob/master/data/events.json"
            XJ["Exhibitors JSON"]:::json
            click XJ "https://github.com/ntgx/expo-bot-messenger/blob/master/data/exhibitors.json"
            SJ["Schedule JSON"]:::json
            click SJ "https://github.com/ntgx/expo-bot-messenger/blob/master/data/schedule.json"
            PKJ["Speakers JSON"]:::json
            click PKJ "https://github.com/ntgx/expo-bot-messenger/blob/master/data/speakers.json"
            POJ["Sponsors JSON"]:::json
            click POJ "https://github.com/ntgx/expo-bot-messenger/blob/master/data/sponsors.json"
        end
    end

    %% Connections
    FB <--> ENTRY
    ENTRY --> MH
    MH --> NLP
    MH --> PB
    MH --> ST
    NLP <--> APIAI
    
    MH --> MM
    MH --> PM
    
    MH --> DAYS
    MH --> EVENTS
    MH --> EXH
    MH --> SCH
    MH --> SPK
    MH --> SPO
    MH --> REG
    MH --> FP
    
    REG --> SLP
    SLP --> MDB
    UM --> MDB
    
    EVENTS --> UTILS
    EXH --> UTILS
    SCH --> UTILS
    SPK --> UTILS
    SPO --> UTILS
    
    UTILS --> EJ
    UTILS --> XJ
    UTILS --> SJ
    UTILS --> PKJ
    UTILS --> POJ
    
    CONFIG --> FB
    CONFIG --> APIAI
    CONFIG --> MDB

    %% Styles
    classDef external fill:#a8d1f0,stroke:#333,stroke-width:2px
    classDef database fill:#f5b041,stroke:#333,stroke-width:2px
    classDef core fill:#82e0aa,stroke:#333,stroke-width:2px
    classDef handler fill:#85c1e9,stroke:#333,stroke-width:2px
    classDef menu fill:#f9e79f,stroke:#333,stroke-width:2px
    classDef expo fill:#abebc6,stroke:#333,stroke-width:2px
    classDef db fill:#d2b4de,stroke:#333,stroke-width:2px
    classDef util fill:#bfc9ca,stroke:#333,stroke-width:2px
    classDef json fill:#f5cba7,stroke:#333,stroke-width:2px
```
