# muraschal/meta architecture

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

- Interactive diagram: https://gitdiagram.com/muraschal/meta
- Repository: https://github.com/muraschal/meta

## Overview

##### Main Components
- External Clients & Devices:
- Meta Glasses: The primary device sending commands and receiving responses.
- WhatsApp Business API: Used for communication and webhook callbacks.
- OpenAI GPT-4 Vision: The AI service engaged for image and language processing.
- API Server / Entry Point:
- The main Node.js server that ties together all functionality (entry point is defined in src/index.js and index.html, which could serve as a landing page or testing interface).
- REST API Endpoints:
- Found in the “api” directory (health.js, logs.js, system-info.js, webhook.js, etc.). These endpoints are used to monitor system health, log data, or handle webhook callbacks.
- GraphQL API:
- Located in “src/graphql” (with schema.js). This exposes a more flexible API endpoint (accessible via http://localhost:3000/graphql) that clients can query for extended functionality.
- Service Modules:
- In the “src/services” directory, there are integrations for “openai.js” (handling communication with OpenAI) and “whatsapp.js” (handling WhatsApp messaging).
- Webhook Processing:
- Handled by modules in both “api” (api/webhook.js) and “src/webhooks” (whatsapp.js) to capture and process real-time callbacks from WhatsApp or Meta Glasses events.
- Deployment & Configuration:
- Files like package.json, vercel.json, and .env.example highlight that the project leverages environment-based configurations and is potentially deployed on Vercel.

##### Relationships and Interactions
- The External Devices (Meta Glasses, WhatsApp Business API, and OpenAI) interact with the API Server.
- REST endpoints in the “api” folder are used for operational tasks like health checking, system info, and log retrieval.
- The GraphQL API (originating from the “src/graphql” folder) serves as an extensible layer for querying and possibly mutating data.
- Service modules (OpenAI and WhatsApp) encapsulate the integration logic—the API Server calls these modules to perform tasks such as sending commands or receiving responses.
- Webhook handlers (both in “api” and “src/webhooks”) provide a communication pathway for real-time updates from WhatsApp and, indirectly, Meta Glasses.
- The project uses WebSocket for real-time communication, ensuring low-latency interactions.

##### Architectural Patterns & Design Principles
- Modularity: The code is separated into distinct folders for API endpoints, GraphQL, service integrations, and webhooks.
- Separation of Concerns: REST and GraphQL serve different client needs; service modules abstract specific integrations with external APIs.
- Extensibility: Using a GraphQL API allows for flexible future expansion of queries and mutations.
- Configuration-Driven: Environment variables (from .env files) keep sensitive configurations separate from code.

##### Relevant Technologies & Frameworks
- Node.js for the backend platform.
- GraphQL for flexible API access.
- WebSocket for real-time communication.
- Vercel (as suggested by vercel.json) for deployment.
- External services: OpenAI API, WhatsApp Business, and a connection with Meta Glasses.

##### Final Advice
- Don’t oversimplify; break down the project into as many functional components as possible to capture the detailed workflow and integrations.

## Diagram (Mermaid)

```mermaid
flowchart TD

  %% External Devices & Services
  subgraph "External Devices & Services"
    MG("Meta Glasses"):::external
    WA("WhatsApp Business API"):::external
    OA("OpenAI GPT-4 Vision"):::external
  end

  %% API Entry Point
  subgraph "API Entry Point"
    API_Server("API Server"):::api
    Testing_Interface("Testing Interface"):::api
  end

  %% API Endpoints
  subgraph "API Endpoints"
    GraphQL_API("GraphQL API"):::endpoint
    subgraph "REST API Endpoints"
      Health("Health Endpoint"):::endpoint
      Logs("Logs Endpoint"):::endpoint
      SystemInfo("System Info Endpoint"):::endpoint
      Webhook_REST("Webhook REST Endpoint"):::endpoint
    end
  end

  %% Service Modules
  subgraph "Service Modules"
    OpenAI_Service("OpenAI Service Module"):::service
    WhatsApp_Service("WhatsApp Service Module"):::service
  end

  %% Webhook Handlers
  subgraph "Webhook Handlers"
    WhatsApp_Webhook("WhatsApp Webhook Handler"):::webhook
  end

  %% Real-time Communication
  subgraph "Real-time Communication"
    WS("WebSocket Communication"):::ws
  end

  %% Configuration & Deployment
  subgraph "Configuration & Deployment"
    Env_Config("Env Configuration"):::config
    Node_Packages("Node Packages"):::config
    Vercel_Config("Vercel Deployment"):::config
  end

  %% Connections from External Devices to API Server
  MG -->|"sendsCommand"| API_Server
  WA -->|"sendsMessage"| API_Server

  %% API Entry Point connections
  Testing_Interface -->|"accesses"| API_Server

  %% API Server to API Endpoints
  API_Server -->|"exposes"| GraphQL_API
  API_Server -->|"exposes"| Health
  API_Server -->|"exposes"| Logs
  API_Server -->|"exposes"| SystemInfo
  API_Server -->|"exposes"| Webhook_REST
  API_Server <-->|"realtime"| WS

  %% API Endpoints to Service Modules
  GraphQL_API -->|"calls"| OpenAI_Service
  GraphQL_API -->|"calls"| WhatsApp_Service

  %% Service Modules to External Services
  OpenAI_Service -->|"queries"| OA
  WhatsApp_Service -->|"sendsMsg"| WA

  %% API Endpoints to Webhook Handlers
  Webhook_REST -->|"triggers"| WhatsApp_Webhook

  %% Configuration affects API Server
  Env_Config -.-> API_Server
  Node_Packages -.-> API_Server
  Vercel_Config -.-> API_Server

  %% Click Events
  click API_Server "https://github.com/muraschal/meta/blob/main/src/index.js"
  click Testing_Interface "https://github.com/muraschal/meta/blob/main/index.html"
  click Health "https://github.com/muraschal/meta/blob/main/api/health.js"
  click Logs "https://github.com/muraschal/meta/blob/main/api/logs.js"
  click SystemInfo "https://github.com/muraschal/meta/blob/main/api/system-info.js"
  click Webhook_REST "https://github.com/muraschal/meta/blob/main/api/webhook.js"
  click GraphQL_API "https://github.com/muraschal/meta/blob/main/src/graphql/schema.js"
  click OpenAI_Service "https://github.com/muraschal/meta/blob/main/src/services/openai.js"
  click WhatsApp_Service "https://github.com/muraschal/meta/blob/main/src/services/whatsapp.js"
  click WhatsApp_Webhook "https://github.com/muraschal/meta/blob/main/src/webhooks/whatsapp.js"
  click Env_Config "https://github.com/muraschal/meta/blob/main/.env.example"
  click Node_Packages "https://github.com/muraschal/meta/blob/main/package.json"
  click Vercel_Config "https://github.com/muraschal/meta/blob/main/vercel.json"

  %% Styles
  classDef external fill:#A0C8F0,stroke:#333,stroke-width:1px;
  classDef api fill:#C1E1C1,stroke:#333,stroke-width:1px;
  classDef endpoint fill:#F0E68C,stroke:#333,stroke-width:1px;
  classDef service fill:#F5B7B1,stroke:#333,stroke-width:1px;
  classDef webhook fill:#F7DC6F,stroke:#333,stroke-width:1px;
  classDef ws fill:#D1F2EB,stroke:#333,stroke-width:1px;
  classDef config fill:#D5DBDB,stroke:#333,stroke-width:1px;
```
