# suecalystegia00/susan-next architecture

> Architecture diagram of the GitHub repository suecalystegia00/susan-next, 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/suecalystegia00/susan-next
- Repository: https://github.com/suecalystegia00/susan-next

## Overview

##### Main Components
- FrontEnd Web Application:
- Next.js application that serves the LIFF (LINE Front-end Framework) web interface and exposes API routes (using Next.js API Routing).
- Mention the UI components, page routing (pages folder), and hooks/contexts that manage state.
- BackEnd API Server:
- PHP-based API found in the “back” directory (with controllers for bot communication, questions, users, and LINE webhook endpoints).
- That this part acts as a pseudo REST API built in PHP 5.6 and that environment configuration is managed with .env files and Composer.
- Database:
- External Services:
- External integration with LINE Messaging API. Indicate how the chatbot service interacts with LINE’s webhook endpoints.
- Dialogflow, which is used to manage intents. Show how the system uses its service account keys (provided via the .env) for processing natural language inputs.
- Docker & Containerization:
- Incorporate the Docker components – containers for front, back, and MySQL – coordinated with docker-compose (docker-compose.yml).

##### Relationships and Data Flows
- Front end sending requests to the backend API:
- How the backend communicates with the MySQL database for CRUD operations.
- Integration with external services:
- Interactions between the LIFF client (browser) and the API endpoints hosted on Vercel (in production) or via Docker (development).

##### Architectural Patterns and Design Principles
- Separation of concerns between the frontend (UI/LIFF and webhook handling) and backend (REST API) – a common full-stack pattern.
- That even though the backend is “vanilla” PHP, it is organized into controllers (e.g., for bot, line, questions, etc.) following an MVC-like approach.
- Use of environment variables (.env files) and container orchestration using Docker, which are critical for deployment and local development.

##### Final Recommendations
- Be as detailed as possible by breaking the system down into all its significant components.
- Incorporate any necessary environmental or configuration aspects, emphasizing the usage of .env files and Docker containerization.

## Diagram (Mermaid)

```mermaid
graph TD
    subgraph "Infrastructure & Containerization"
        DOCKER["Docker & Containerization"]:::container
    end

    subgraph "Application Layer"
        FE["Next.js Frontend App"]:::frontend
        BE["PHP BackEnd API"]:::backend
        DB["MySQL Database"]:::database
    end

    subgraph "External Services"
        LINE["LINE Messaging API"]:::external
        DF["Dialogflow"]:::external
    end

    DOCKER --> FE
    DOCKER --> BE
    DOCKER --> DB

    FE -->|"API-request"| BE
    BE -->|"CRUD_operations"| DB
    BE -->|"webhook_event"| LINE
    FE -->|"intent_detection"| DF

    click FE "https://github.com/suecalystegia00/susan-next/tree/main/front"
    click BE "https://github.com/suecalystegia00/susan-next/tree/main/back/api/v2/controllers"
    click DB "https://github.com/suecalystegia00/susan-next/tree/main/mysql"
    click LINE "https://github.com/suecalystegia00/susan-next/blob/main/back/api/v2/controllers/line.php"
    click DF "https://github.com/suecalystegia00/susan-next/tree/main/front/src/pages/api/v1/dialogflow"
    click DOCKER "https://github.com/suecalystegia00/susan-next/blob/main/docker-compose.yml"

    classDef frontend fill:#8ecae6,stroke:#219ebc,stroke-width:2px;
    classDef backend fill:#ffb703,stroke:#fb8500,stroke-width:2px;
    classDef database fill:#aed9e0,stroke:#0077b6,stroke-width:2px;
    classDef external fill:#ffcd38,stroke:#ff9f1c,stroke-width:2px;
    classDef container fill:#d8e2dc,stroke:#95a3a4,stroke-width:2px;
```
