# ninja1420/trendify_agent architecture

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

## Overview

##### Project Type & Purpose
- This is a full-stack, AI-powered fashion assistant.
- Frontend: Interactive web UI built with Streamlit.
- Backend: REST API built on FastAPI.
- Core functionality: Accepts user queries, forwards them to an AI agent, and returns personalized fashion advice.
- External services: Groq, OpenAI for model inference; Tavily for web search.

##### Top-Level Components
a. Client / User Interface
- Browser running the Streamlit App (streamlit_App.py).
- Streams user inputs (model choice, query, toggles) to backend.
b. Web Server / API Layer
- FastAPI application (backend.py) exposing `/chat` endpoint.
- Listens on a port (e.g., 8000) for JSON requests.
c. Business Logic / AI Agent
- ai_agent.py: orchestrates prompt construction, model calls.
- constants.py: holds system prompts, default settings.
d. External AI & Search Services
- Groq API
- OpenAI API
- Tavily Search API
e. Configuration & Environment
- `.env` file with API keys loaded at runtime.
- requirements.txt drives dependency installation.

##### Interactions & Data Flows
1. User opens Streamlit UI on `http://localhost:8501`.
2. User submits a fashion query + settings.
3. Streamlit App issues an HTTP POST to FastAPI `/chat`.
4. FastAPI handler validates payload, calls ai_agent.
5. AI agent builds prompt (using constants) and:
a. Optionally calls Tavily API for real-time web search.
b. Routes the prompt to the chosen model via Groq or OpenAI SDK.
6. AI model returns generated advice.
7. Backend formats the response JSON and returns to Streamlit.
8. Streamlit displays the advice to the user.

##### Architectural Patterns & Key Principles
- Clear separation of concerns:
- UI (Streamlit)
- API (FastAPI)
- Core logic (AI agent module)
- Environment-based configuration for secrets.
- Stateless API: each request is handled independently.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Layer
    subgraph "Frontend Layer"
        direction TB
        Streamlit["Streamlit App\n(streamlit_App.py)\nPort: 8501"]:::frontend
    end

    %% API Layer
    subgraph "API Layer"
        direction TB
        FastAPI["FastAPI App\n(backend.py)\nPort: 8000"]:::api
    end

    %% Business Logic Layer
    subgraph "Business Logic / AI Agent"
        direction TB
        AIAgent["AI Agent\n(ai_agent.py)"]:::logic
        Constants["Constants\n(constants.py)"]:::logic
    end

    %% External Services
    subgraph "External Services"
        direction TB
        Groq[(Groq API)]:::external
        OpenAI[(OpenAI API)]:::external
        Tavily[(Tavily Search API)]:::external
    end

    %% Configuration & Docs
    subgraph "Config & Docs"
        direction TB
        Env[".env"]:::config
        Req["requirements.txt"]:::config
        Readme["README.md"]:::config
    end

    %% Connections
    Streamlit -->|"HTTP POST /chat"| FastAPI
    FastAPI -->|"calls"| AIAgent
    AIAgent -->|"uses prompts"| Constants
    AIAgent -->|"optional web search"| Tavily
    AIAgent -->|"model inference"| Groq
    AIAgent -->|"model inference"| OpenAI
    FastAPI -->|"returns JSON"| Streamlit

    Env --> Streamlit
    Env --> FastAPI

    %% Click Events
    click Streamlit "https://github.com/ninja1420/trendify_agent/blob/main/src/app/streamlit_App.py"
    click FastAPI "https://github.com/ninja1420/trendify_agent/blob/main/src/app/backend.py"
    click AIAgent "https://github.com/ninja1420/trendify_agent/blob/main/src/app/ai_agent.py"
    click Constants "https://github.com/ninja1420/trendify_agent/blob/main/src/app/constants.py"
    click Req "https://github.com/ninja1420/trendify_agent/blob/main/requirements.txt"
    click Readme "https://github.com/ninja1420/trendify_agent/blob/main/README.md"

    %% Styles
    classDef frontend fill:#D0E8FF,stroke:#0277BD,color:#000
    classDef api fill:#E8F5E9,stroke:#2E7D32,color:#000
    classDef logic fill:#FFF3E0,stroke:#FB8C00,color:#000
    classDef external fill:#F3E5F5,stroke:#6A1B9A,shape:cylinder,color:#000
    classDef config fill:#ECEFF1,stroke:#607D8B,shape:note,color:#000
```
