# 🤖 Canifa AI Platform — Backend & Tools

> **A unified AI ecosystem powering Canifa's fashion retail intelligence, content automation, and inventory monitoring.**

This platform serves as the central hub for all AI-driven workflows at Canifa, integrating Large Language Models (Gemini, GPT) with real-time business data (PostgreSQL, StarRocks, SQLite) to provide actionable insights and automated content.

---

## 📸 Platform Overview

<p align="center">
  <img src="public/screenshots/02_swagger_docs.png" width="45%" alt="API Docs" />
  <img src="public/screenshots/03_chatbot_ui.png" width="45%" alt="Chatbot UI" />
</p>
<p align="center">
  <img src="public/screenshots/04_stock_cache.png" width="45%" alt="Stock Cache" />
  <img src="public/screenshots/05_fashion_matches.png" width="45%" alt="Fashion Matches" />
</p>

---

## 🧠 Core Modules

### 1. 👗 AI Stylist & Fashion Matches
- **Deterministic Styling**: Maps raw Magento categories into a clean 4-slot framework (Top, Bottom, Set, Accessories).
- **Style Pairing**: Generates context-aware outfit combinations based on product attributes and seasonal trends.
- **Grounded Retrieval**: Prevents AI hallucinations by anchoring recommendations in real product metadata.

### 2. ✍️ Ultra Product Descriptions
- **Automated Copywriting**: Generates web-ready, SEO-optimized descriptions from raw product data and images.
- **Human-in-the-loop**: Integrated approval workflow for AI-generated content before publishing to Magento.
- **N8n Integration**: Seamless data flow between Google Sheets, n8n, and the Backend API.

### 3. 📦 Stock & Inventory Intelligence
- **Real-time Monitoring**: Dashboard for tracking stock levels across multiple warehouses.
- **Cache Management**: High-performance SQLite-based caching for instant stock lookups.
- **StarRocks Sync**: Enterprise-grade data warehousing for historical analysis and forecasting.

### 4. 📅 Content Automation
- **Composer**: AI-assisted creation of marketing materials and social media posts.
- **Calendar & Approval**: Full lifecycle management for promotional content.
- **Social Inbox**: Centralized monitoring of customer interactions across social channels.

---

## 🛠 Tech Stack

- **Backend**: [FastAPI](https://fastapi.tiangolo.com/) (Async Python 3.10+)
- **AI Framework**: [LangChain](https://www.langchain.com/) & [LangGraph](https://www.langchain.com/langgraph)
- **Database**: 
  - **Primary**: PostgreSQL (via SQLAlchemy 2.0)
  - **Analytics**: StarRocks
  - **Local Cache**: SQLite
- **Observability**: [Langfuse](https://langfuse.com/) (LLM Tracing & Feedback)
- **Deployment**: Docker, Uvicorn, Redis (Caching & Task Queue)

---

## 🚀 Getting Started

### Prerequisites
- Python 3.10 or higher
- Redis server (optional, for task queueing)
- Virtual Environment (`venv`)

### Installation
1. **Clone the repository**:
   ```bash
   git clone https://github.com/your-org/chatbot-canifa-feedback.git
   cd chatbot-canifa-feedback
   ```

2. **Set up virtual environment**:
   ```bash
   python -m venv .venv
   source .venv/bin/activate  # Windows: .venv\Scripts\activate
   ```

3. **Install dependencies**:
   ```bash
   pip install -r requirements.txt
   ```

4. **Environment Variables**:
   Copy `.env.example` to `.env` and fill in your API keys (Gemini, OpenAI, Database credentials).

### Running the Server
```bash
cd backend
python server.py
```
The application will be available at `http://localhost:5000`.

---

## 📁 Project Structure

```
.
├── .agent/                 # 🤖 AI Agent workflows & skills
├── backend/                # 🐍 FastAPI Backend
│   ├── api/                # 🛣️ REST API Routes
│   ├── common/             # 🛠️ Shared utilities (DB, Cache, etc.)
│   ├── static/             # 🌐 Frontend assets & Dashboards
│   └── server.py           # 🚀 Entry point
├── plan/                   # 📋 SDLC Documentation (Ideas, Doings, Done)
├── public/                 # 🖼️ Static assets & screenshots
└── README.md               # 📖 This file
```

---

## 📜 API Documentation

Once the server is running, you can access the interactive Swagger documentation at:
- **Local**: `http://localhost:5000/docs`
- **ReDoc**: `http://localhost:5000/redoc`

---

<p align="center">
  <strong>Built for Canifa AI Transformation</strong><br/>
  <em>"Fashion meets Intelligence"</em>
</p>
