# anselmo07/chatbot-de-sushi architecture

> Architecture diagram of the GitHub repository anselmo07/chatbot-de-sushi, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-07). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/anselmo07/chatbot-de-sushi
- Repository: https://github.com/anselmo07/chatbot-de-sushi

## Overview

##### Main Components
- Frontend: Built in React (using Vite), this is where the user interface is implemented. The frontend is responsible for rendering the chatbot UI (e.g., pages like Chatbot.jsx) and communicates with the backend via API calls (configured through environment variables such as NEXT_PUBLIC_API_URL).
- Backend: This is a Node.js server using the NestJS framework. It is organized into multiple modules including “chat”, “menu”, “faqs”, and “orders”. Each module has its own controller, service, and, in some cases, entity definitions.
- Database: Although the file tree only shows connection configuration details (MONGO_URI), the backend connects to a MongoDB database to store persistent data, such as order details, menu items, and FAQ information.
- Middleware & Seeding: The backend includes middleware (e.g., horarios for scheduling) and seed data (for chat help and products) that initialize or enrich the system with default value sets.

##### Relationships & Interactions
- Client-Server Communication: The frontend makes API calls to the backend. For example, the React UI sends GET requests to endpoints like /menu/comida, /faqs/status, /chat/ubicacion, and a POST request to /orders for placing an order.
- Module Interactions within the Backend: Each NestJS module (chat, menu, faqs, orders) encapsulates its responsibilities. They may interact with shared services or use custom middleware for cross-cutting concerns.
- Database Access: The backend modules interact with the MongoDB database using defined entities. These entities (such as chat.entity.ts, menu.entity.ts, and order.entity.ts) map data structures to database collections.

##### Architectural Patterns & Design Principles
- Separation of Concerns: The project clearly distinguishes between presentation (frontend) and business logic (backend). In the backend, the use of NestJS modules enforces modularity.
- RESTful API Design: The endpoints follow REST principles by providing distinct actions (GET for fetching data, POST for creating orders).
- Configuration Management: Environment configuration is managed separately for both the frontend and backend, enhancing security and flexibility.
- Self-seeding and Initialization: The presence of seed scripts within the backend ensures that initial data is loaded into the system.

##### Relevant Technologies and Frameworks
- Frontend: React, Vite (for bundling), and CSS for styling.
- Backend: Node.js with the NestJS framework, and integration with MongoDB as the database.
- Additional Tools: ESLint, Prettier for code quality, and tools like jest for testing, are included in the project.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Layer
    subgraph "Frontend Layer"
        FE1["Chatbot.jsx"]:::frontend
        FE2["index.html"]:::frontend
        FE3["main.jsx"]:::frontend
        FE4["vite.config.js"]:::frontend
    end

    %% Backend Layer
    subgraph "Backend Layer"
        BEEntry["Backend Entry"]:::backend

        %% Chat Module
        subgraph "Chat Module"
            ChatMod["chat.module.ts"]:::backend
            ChatCtrl["chat.controller.ts"]:::controller
            ChatSrv["chat.service.ts"]:::service
            ChatEnt["chat.entity.ts"]:::entity
        end

        %% Menu Module
        subgraph "Menu Module"
            MenuMod["menu.module.ts"]:::backend
            MenuCtrl["menu.controller.ts"]:::controller
            MenuCtrlSpec["menu.controller.spec.ts"]:::test
            MenuSrv["menu.service.ts"]:::service
            MenuEnt["menu.entity.ts"]:::entity
        end

        %% FAQs Module
        subgraph "FAQs Module"
            FAQsMod["faqs.module.ts"]:::backend
            FAQsCtrl["faqs.controller.ts"]:::controller
            FAQSSrv["faqs.service.ts"]:::service
        end

        %% Orders Module
        subgraph "Orders Module"
            OrdersMod["orders.module.ts"]:::backend
            OrdersCtrl["orders.controller.ts"]:::controller
            OrdersCtrlSpec["orders.controller.spec.ts"]:::test
            OrdersSrv["orders.service.ts"]:::service
            OrderEnt["order.entity.ts"]:::entity
        end

        Middleware["horarios.ts"]:::middleware
        Seeding["Seeding"]:::seeding
        subgraph "Chat Help Seed"
            ChatHelpSeed["help.seed.ts"]:::seeding
            ChatHelpFile["helps.ts"]:::seeding
        end
        subgraph "Product Seed"
            ProductSeed["prodcut.seed.ts"]:::seeding
            ProductFile["product.ts"]:::seeding
        end
    end

    %% Database Layer
    subgraph "Database Layer"
        DB["MongoDB (MONGO_URI)"]:::database
    end

    %% Interactions: Frontend to Backend Controllers
    FE1 -->|"API_Call:/chat,/menu,/faqs,/orders"| BEEntry
    FE1 -->|"API_Call"| ChatCtrl
    FE1 -->|"API_Call"| MenuCtrl
    FE1 -->|"API_Call"| FAQsCtrl
    FE1 -->|"API_Call"| OrdersCtrl

    %% Backend Entry interactions
    BEEntry --> Middleware
    BEEntry --> Seeding

    %% Chat Module Flow
    ChatCtrl -->|"calls"| ChatSrv
    ChatSrv -->|"uses"| ChatEnt
    ChatEnt -->|"CRUD"| DB

    %% Menu Module Flow
    MenuCtrl -->|"calls"| MenuSrv
    MenuSrv -->|"uses"| MenuEnt
    MenuEnt -->|"CRUD"| DB

    %% FAQs Module Flow
    FAQsCtrl -->|"calls"| FAQSSrv
    FAQSSrv -->|"accesses"| DB

    %% Orders Module Flow
    OrdersCtrl -->|"calls"| OrdersSrv
    OrdersSrv -->|"uses"| OrderEnt
    OrderEnt -->|"CRUD"| DB

    %% Seeding Flow
    Seeding --> ChatHelpSeed
    Seeding --> ProductSeed

    %% Click Events for Frontend
    click FE1 "https://github.com/anselmo07/chatbot-de-sushi/blob/main/front/src/pages/Chatbot.jsx"
    click FE2 "https://github.com/anselmo07/chatbot-de-sushi/blob/main/front/index.html"
    click FE3 "https://github.com/anselmo07/chatbot-de-sushi/blob/main/front/src/main.jsx"
    click FE4 "https://github.com/anselmo07/chatbot-de-sushi/blob/main/front/vite.config.js"

    %% Click Events for Backend Entry
    click BEEntry "https://github.com/anselmo07/chatbot-de-sushi/blob/main/back/src/main.ts"
    click BEEntry "https://github.com/anselmo07/chatbot-de-sushi/blob/main/back/app.module.ts"
    click BEEntry "https://github.com/anselmo07/chatbot-de-sushi/blob/main/back/app.service.ts"
    click BEEntry "https://github.com/anselmo07/chatbot-de-sushi/blob/main/back/nest-cli.json"
    click BEEntry "https://github.com/anselmo07/chatbot-de-sushi/blob/main/back/package.json"

    %% Click Events for Chat Module
    click ChatMod "https://github.com/anselmo07/chatbot-de-sushi/blob/main/back/src/chat/chat.module.ts"
    click ChatCtrl "https://github.com/anselmo07/chatbot-de-sushi/blob/main/back/src/chat/chat.controller.ts"
    click ChatSrv "https://github.com/anselmo07/chatbot-de-sushi/blob/main/back/src/chat/chat.service.ts"
    click ChatEnt "https://github.com/anselmo07/chatbot-de-sushi/blob/main/back/src/chat/entities/chat.entity.ts"

    %% Click Events for Menu Module
    click MenuMod "https://github.com/anselmo07/chatbot-de-sushi/blob/main/back/src/menu/menu.module.ts"
    click MenuCtrl "https://github.com/anselmo07/chatbot-de-sushi/blob/main/back/src/menu/menu.controller.ts"
    click MenuCtrlSpec "https://github.com/anselmo07/chatbot-de-sushi/blob/main/back/src/menu/menu.controller.spec.ts"
    click MenuSrv "https://github.com/anselmo07/chatbot-de-sushi/blob/main/back/src/menu/menu.service.ts"
    click MenuEnt "https://github.com/anselmo07/chatbot-de-sushi/blob/main/back/src/menu/entities/menu.entity.ts"

    %% Click Events for FAQs Module
    click FAQsMod "https://github.com/anselmo07/chatbot-de-sushi/blob/main/back/src/faqs/faqs.module.ts"
    click FAQsCtrl "https://github.com/anselmo07/chatbot-de-sushi/blob/main/back/src/faqs/faqs.controller.ts"
    click FAQSSrv "https://github.com/anselmo07/chatbot-de-sushi/blob/main/back/src/faqs/faqs.service.ts"

    %% Click Events for Orders Module
    click OrdersMod "https://github.com/anselmo07/chatbot-de-sushi/blob/main/back/src/orders/orders.module.ts"
    click OrdersCtrl "https://github.com/anselmo07/chatbot-de-sushi/blob/main/back/src/orders/orders.controller.ts"
    click OrdersCtrlSpec "https://github.com/anselmo07/chatbot-de-sushi/blob/main/back/src/orders/orders.controller.spec.ts"
    click OrdersSrv "https://github.com/anselmo07/chatbot-de-sushi/blob/main/back/src/orders/orders.service.ts"
    click OrderEnt "https://github.com/anselmo07/chatbot-de-sushi/blob/main/back/src/orders/entities/order.entity.ts"

    %% Click Event for Middleware
    click Middleware "https://github.com/anselmo07/chatbot-de-sushi/blob/main/back/src/middleware/horarios.ts"

    %% Click Events for Seeding
    click ChatHelpSeed "https://github.com/anselmo07/chatbot-de-sushi/blob/main/back/src/seed/ayuda/help.seed.ts"
    click ChatHelpFile "https://github.com/anselmo07/chatbot-de-sushi/blob/main/back/src/seed/ayuda/helps.ts"
    click ProductSeed "https://github.com/anselmo07/chatbot-de-sushi/blob/main/back/src/seed/product/prodcut.seed.ts"
    click ProductFile "https://github.com/anselmo07/chatbot-de-sushi/blob/main/back/src/seed/product/product.ts"

    %% Click Event for Database Configuration
    click DB "https://github.com/anselmo07/chatbot-de-sushi/blob/main/back/.env.example"

    %% Styles
    classDef frontend fill:#add8e6,stroke:#000,stroke-width:1px;
    classDef backend fill:#90ee90,stroke:#000,stroke-width:1px;
    classDef controller fill:#FFA07A,stroke:#000,stroke-width:1px;
    classDef service fill:#FFD700,stroke:#000,stroke-width:1px;
    classDef entity fill:#FFB6C1,stroke:#000,stroke-width:1px;
    classDef middleware fill:#9370DB,stroke:#000,stroke-width:1px;
    classDef seeding fill:#D3D3D3,stroke:#000,stroke-width:1px;
    classDef database fill:#F08080,stroke:#000,stroke-width:1px;
    classDef test fill:#e0ffff,stroke:#000,stroke-width:1px;
```
