# zeuidon/negosy architecture

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

- Interactive diagram: https://gitdiagram.com/zeuidon/negosy
- Repository: https://github.com/zeuidon/negosy

## Overview

##### Project Type and Purpose
- NegoSy is a full-stack AI-powered e-commerce chatbot system for automated price negotiation.
- Frontend: static HTML/CSS/JS (“nino” theme) plus fine-tune data.
- Backend: Python service (app.py) implementing negotiation logic, sentiment analysis, and LLM integration.

##### File Structure Analysis
- NegoSy/frontend
- fine_tune_data.json – dataset for training or prompting the LLM.
- nino/ – static web assets (index.html, CSS/JS).
- NegoSy/negotiation
- app.py – main Flask (or similar) application exposing HTTP endpoints.
- messages.py – modules for message parsing, sentiment analysis or business-rule processing.
- README.md – project overview, methodology (query acquisition, dialogue rollout, sentiment analyzer, LLM).

##### Key Components
a. User Interface (Client Browser)
- Loads index.html, CSS, JS; captures user input.
b. API Layer (Backend Service)
- app.py running Flask/FastAPI.
- Exposes REST/WebSocket endpoints to receive chat messages.
c. Message Processor
- messages.py: pre-processing, tokenization, sentiment analysis.
d. Fine-Tune Data Store
- fine_tune_data.json (could be represented as local file or lightweight database).
e. LLM Integration
- External API call to an LLM provider (OpenAI, local model).
f. Response Generator
- Combines LLM output with business rules, constructs reply.
g. (Optional) Persistence Layer
- If chat logs or negotiation states are stored; even if not present, show a “Chat History” store placeholder.

##### Component Relationships and Data Flow
1. User types a message in the browser UI →
2. JS triggers HTTP POST/WebSocket to Backend API (app.py) →
3. app.py forwards raw message to Message Processor (messages.py) →
4. Message Processor analyzes sentiment & context; selects tag-words →
5. Processor constructs a prompt using fine_tune_data.json →
6. Prompt sent to External LLM API →
7. LLM returns a generated response →
8. Response post-processing (business logic) →
9. app.py returns final chat reply to Browser →
10. Browser JS displays it to the user.

##### Architectural Patterns & Design Principles
- Layered architecture: separation of concerns (UI, API, processing, external services).
- Single-responsibility: messages.py handles only NLP-related logic.
- Minimal state: if persisting negotiation states, isolate state management in its own module/component.

##### Technologies and Frameworks
- Frontend: HTML5, CSS (styles.css), vanilla JS (scripts.js).
- Backend: Python (Flask or FastAPI in app.py).
- NLP: custom sentiment analyzer in messages.py.
- LLM: external API (e.g., OpenAI GPT) accessed via HTTP.
- Data store: JSON file for fine-tune data (can later migrate to a real DB).

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Web Client Layer
    subgraph "Web Client"
        UI((Browser)):::client
        index["index.html"]:::client
        styles["styles.css"]:::client
        scripts["scripts.js"]:::client
        nino_dir["nino/"]:::client
    end

    %% Backend Layer
    subgraph "Backend API" 
        API["app.py"]:::backend
        subgraph "NLP Layer"
            Processor["messages.py"]:::processor
        end
    end

    %% Data Stores
    FT["fine_tune_data.json"]:::datastore
    subgraph "Chat History Store"
        CH[(Chat History)]:::datastore
    end

    %% External Services
    LLM[(LLM Service)]:::external

    %% Documentation
    subgraph "Documentation"
        DOC1["README.md"]:::datastore
        DOC2["negotiation/README.md"]:::datastore
    end

    %% Data Flows
    UI -->|"loads"| index
    UI -->|"loads"| styles
    UI -->|"loads"| scripts
    UI -->|"loads"| nino_dir
    UI -->|"sends message"| API
    API -->|"forwards message"| Processor
    Processor -->|"loads data"| FT
    Processor -->|"sends prompt"| LLM
    LLM -->|"returns response"| Processor
    Processor -->|"returns processed reply"| API
    API -->|"returns reply"| UI
    API -->|"logs chat"| CH

    %% Click Events
    click index "https://github.com/zeuidon/negosy/blob/main/NegoSy/frontend/nino/index.html"
    click styles "https://github.com/zeuidon/negosy/blob/main/NegoSy/frontend/nino/css/styles.css"
    click scripts "https://github.com/zeuidon/negosy/blob/main/NegoSy/frontend/nino/js/scripts.js"
    click nino_dir "https://github.com/zeuidon/negosy/tree/main/NegoSy/frontend/nino/"
    click API "https://github.com/zeuidon/negosy/blob/main/NegoSy/negotiation/app.py"
    click Processor "https://github.com/zeuidon/negosy/blob/main/NegoSy/negotiation/messages.py"
    click FT "https://github.com/zeuidon/negosy/blob/main/NegoSy/frontend/fine_tune_data.json"
    click DOC1 "https://github.com/zeuidon/negosy/blob/main/README.md"
    click DOC2 "https://github.com/zeuidon/negosy/blob/main/NegoSy/negotiation/README.md"

    %% Styles
    classDef client fill:#D5E8D4,stroke:#82B366;
    classDef backend fill:#DAE8FC,stroke:#6C8EBF;
    classDef processor fill:#FFF2CC,stroke:#D6B656;
    classDef datastore fill:#E1D5E7,stroke:#9673A6;
    classDef external fill:#F8CECC,stroke:#B85450;
```
