# yaslopesyweb/iacai architecture

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

- Interactive diagram: https://gitdiagram.com/yaslopesyweb/iacai
- Repository: https://github.com/yaslopesyweb/iacai

## Overview

##### Project type and purpose
- This is a full-stack, monolithic web application combining a Vaadin-based UI (frontend) with a Spring Boot backend that integrates OpenAI’s GPT API for AI-driven chat.
- Purpose: Provide an intelligent chat assistant on the Acaiacá platform to help users interact, ask questions about sustainable agriculture, and receive context-aware answers.

##### File structure
- Top-level “frontend” folder: houses generated Flow/TypeScript/WebComponent code (Vaadin Flow client artifacts, JS/CSS, index.html, styles).
- “src/main/java/br/com/senac/ia”: backend code – IaApplication (entry point), IaService (OpenAI integration), views (Vaadin server-side UI classes like HomeView).
- Bundles (“src/main/bundles”): pre-packaged resources for production.
- Configuration files: application.properties, .env for OPENAI_API_KEY.
- Build scripts: mvnw (Maven wrapper), package.json & tsconfig.json (Node for building TS assets).

##### README
- Confirms use of Java 17+, Spring Boot 3.1, Vaadin 24+, CSS3, and OpenAI GPT.
- Provides functional overview: intelligent chat, conversation history, rapid response.
- Mentions MVC-style organization (config, controller, service, application class).

a. Client Layer
- Browser / User Agent – loads index.html, CSS, and WebComponents.
- Generated Vaadin Flow client code (TS/JS, Web Components under “frontend/generated”).
b. Server Layer
- Vaadin Flow / Spring Boot service – IaApplication as main, Vaadin views (HomeView), Spring controllers (if any), and business/service layer (IaService).
c. External Services
- OpenAI GPT API (calls from IaService over HTTPS).
d. Static Resources & Bundles
- Bundles folder and frontend static assets (JS bundles, CSS themes).
e. Build & Deployment
- Node.js/NPM for TS build, Maven for Java build, environment variables (.env), and application.properties.

##### Relationships & data flow
- Browser → HTTP(S) GET/POST → Spring Boot server (Vaadin servlet).
- Vaadin server serves dynamic HTML + Web Components + CSS.
- User actions in browser trigger RPC/WebSocket requests (Vaadin protocol) back to server.
- IaService in backend makes outbound HTTPS calls to OpenAI API, processes response.
- Server pushes UI updates to client via Vaadin push or page reload.

##### Architectural patterns & design principles
- Layered (Presentation → Business/Service → Integration)
- MVC-ish (Vaadin Views = Controllers+Templates, IaService = Model/business logic)
- External integration pattern (adapter to OpenAI API)
- Monolithic deployment (all components packaged and run together)

##### Technologies & frameworks to annotate
- Java 17+, Spring Boot 3.1, Vaadin 24 (Flow + Web Components)
- Node.js + TypeScript (frontend codegen)
- Maven (build & dependency management)
- OpenAI GPT HTTP API
- CSS3 (chat-theme.css)

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Client Layer
    subgraph "Client Layer"
        direction TB
        Browser["Browser / User Agent"]:::frontend
        Index["Static HTML Entry (index.html)"]:::frontend
        Generated["Generated Vaadin Flow Client Code"]:::frontend
        CSS["CSS Theme"]:::frontend
    end

    %% Server Layer
    subgraph "Server Layer"
        direction TB
        Server["Vaadin/Spring Boot Server"]:::backend
        subgraph "UI Module"
            direction TB
            HomeView["HomeView (Vaadin View)"]:::backend
        end
        subgraph "Service Module"
            direction TB
            IaService["IaService (OpenAI Integration)"]:::backend
        end
        IaApplication["IaApplication (Entry Point)"]:::backend
        ConfigProps["application.properties"]:::config
        Env[".env.example"]:::config
        Bundles["Pre-packaged Bundles"]:::config
    end

    %% External Service
    External["OpenAI GPT API"]:::external

    %% Build & Deployment
    subgraph "Build & Deployment"
        direction TB
        Maven["Maven Wrapper & pom.xml"]:::build
        Node["Node.js / TS Config"]:::build
    end

    %% Tests
    Test["IaApplicationTests"]:::test

    %% Connections
    Browser -->|HTTPGET| Server
    Server -->|serves| Index
    Server -->|serves| Generated
    Server -->|serves| CSS
    Browser <-->|"VaadinRPC/WebSocket"| Server

    IaApplication -->|"loads UI Module"| HomeView
    IaApplication -->|"initializes Service"| IaService
    IaService -->|HTTPS| External

    ConfigProps -->|"configures"| IaApplication
    Env -->|"provides env vars"| IaApplication
    Bundles -->|"served as static"| Server

    Maven -->|"builds"| IaApplication
    Node -->|"builds assets"| Generated
    Node -->|"builds assets"| CSS

    Test -->|"tests"| IaApplication

    %% Click Events
    click Index "https://github.com/yaslopesyweb/iacai/blob/main/frontend/index.html"
    click Generated "https://github.com/yaslopesyweb/iacai/tree/main/frontend/generated"
    click CSS "https://github.com/yaslopesyweb/iacai/blob/main/frontend/styles/chat-theme.css"
    click IaApplication "https://github.com/yaslopesyweb/iacai/blob/main/src/main/java/br/com/senac/ia/IaApplication.java"
    click HomeView "https://github.com/yaslopesyweb/iacai/blob/main/src/main/java/br/com/senac/ia/views/HomeView.java"
    click IaService "https://github.com/yaslopesyweb/iacai/blob/main/src/main/java/br/com/senac/ia/IaService.java"
    click ConfigProps "https://github.com/yaslopesyweb/iacai/blob/main/src/main/resources/application.properties"
    click Env "https://github.com/yaslopesyweb/iacai/blob/main/.env.example"
    click Bundles "https://github.com/yaslopesyweb/iacai/tree/main/src/main/bundles"
    click Maven "https://github.com/yaslopesyweb/iacai/tree/main/mvnw"
    click Maven "https://github.com/yaslopesyweb/iacai/tree/main/.mvn/wrapper"
    click Maven "https://github.com/yaslopesyweb/iacai/blob/main/pom.xml"
    click Node "https://github.com/yaslopesyweb/iacai/blob/main/package.json"
    click Node "https://github.com/yaslopesyweb/iacai/blob/main/tsconfig.json"
    click Test "https://github.com/yaslopesyweb/iacai/blob/main/src/test/java/br/com/senac/ia/IaApplicationTests.java"

    %% Styles
    classDef frontend fill:#D6E9FE,stroke:#2C7BE5,color:#000
    classDef backend fill:#DFF2BF,stroke:#4F8A10,color:#000
    classDef external fill:#FEF6D6,stroke:#F0AD4E,color:#000
    classDef config fill:#F2DEDE,stroke:#A94442,color:#000
    classDef build fill:#E8EAF6,stroke:#3F51B5,color:#000
    classDef test fill:#FCF8E3,stroke:#8A6D3B,color:#000
```
