# StoreSight AI - Complete Platform

AI-powered WooCommerce analytics dashboard with license management and OpenAI proxy.

## Stack

- **Backend**: Laravel 10 + Inertia.js
- **Frontend**: Vue 3 + TailwindCSS
- **Database**: MySQL
- **Auth**: Laravel session-based + JWT tokens for plugin API
- **Payments**: Stripe (integration ready)
- **AI**: OpenAI API proxy

## Database Tables

- `users` - with `first_name`, `last_name`, `is_admin`, `stripe_customer_id`
- `licenses` - license keys, status, plan, max_sites, stripe_subscription_id
- `license_activations` - domain bindings with JWT tokens, last_seen tracking
- `ai_requests` - full logging of prompts, responses, tokens, response times
- `settings` - key/value store for admin configuration

## Pages (16 Vue components)

### Public Website

- `/` - Homepage with hero, features, how-it-works, pricing preview, CTA
- `/pricing` - Detailed pricing page with FAQ accordion
- `/login` - Login form
- `/register` - Registration form

### Customer Dashboard

- `/dashboard` - Stats cards, licenses table, recent AI requests
- `/dashboard/license/{id}` - License details, activations, usage chart, requests
- `/dashboard/account` - Profile, password, billing settings

### Admin Panel

- `/admin` - Dashboard with stats, revenue/requests charts, recent activity
- `/admin/users` - User management with search & filters
- `/admin/licenses` - License management with revoke/reinstate
- `/admin/activations` - Site activation monitoring
- `/admin/ai-logs` - AI request log viewer
- `/admin/settings` - AI config, rate limits, payments, license config, admin account

## Plugin API Endpoints

- `POST /api/license/activate` - Activate license with JWT token response
- `POST /api/license/deactivate` - Deactivate a domain
- `GET /api/plugin/ping` - Heartbeat check
- `POST /api/ai/prompt` - AI proxy (validates token, rate limits, logs, forwards to OpenAI)

## Login Credentials

- **Admin**: `admin@storesight.ai` / `password`
- **Sample user**: `john@example.com` / `password`

## Seeded Data

- 6 users (1 admin + 5 customers)
- 6 licenses with 4 active activations
- 61 sample AI requests
- 11 default settings

## Setup

```bash
# Install dependencies
composer install
npm install

# Configure environment
cp .env.example .env
php artisan key:generate

# Set database credentials in .env then run:
php artisan migrate
php artisan db:seed

# Build frontend
npm run build

# Development server
npm run dev
```

## Environment Variables

Key `.env` variables to configure:

```
DB_DATABASE=analyticsdevelop_store
DB_USERNAME=analyticsdevelop_user
DB_PASSWORD=

STRIPE_KEY=
STRIPE_SECRET=
STRIPE_WEBHOOK_SECRET=

OPENAI_API_KEY=
OPENAI_MODEL=gpt-5-mini
OPENAI_MAX_TOKENS=1024

RATE_LIMIT_PER_DAY=200
RATE_LIMIT_PER_MINUTE=10
MAX_TOKENS_PER_DAY=500000
FREE_TRIAL_DAYS=14
SITES_PER_LICENSE=1
TOKEN_EXPIRY_DAYS=30
```

## Project Structure

```
app/
├── Http/
│   ├── Controllers/
│   │   ├── Admin/
│   │   │   ├── AdminActivationController.php
│   │   │   ├── AdminAiLogController.php
│   │   │   ├── AdminDashboardController.php
│   │   │   ├── AdminLicenseController.php
│   │   │   ├── AdminSettingController.php
│   │   │   └── AdminUserController.php
│   │   ├── Api/
│   │   │   ├── AiProxyController.php
│   │   │   └── LicenseApiController.php
│   │   ├── Auth/
│   │   │   ├── LoginController.php
│   │   │   └── RegisterController.php
│   │   ├── AccountController.php
│   │   ├── DashboardController.php
│   │   ├── LicenseController.php
│   │   └── PageController.php
│   └── Middleware/
│       ├── AdminMiddleware.php
│       └── HandleInertiaRequests.php
├── Models/
│   ├── AiRequest.php
│   ├── License.php
│   ├── LicenseActivation.php
│   ├── Setting.php
│   └── User.php
└── Policies/
    └── LicensePolicy.php

resources/js/
├── Layouts/
│   ├── AdminLayout.vue
│   ├── DashboardLayout.vue
│   └── PublicLayout.vue
├── Pages/
│   ├── Admin/
│   │   ├── Activations.vue
│   │   ├── AiLogs.vue
│   │   ├── Dashboard.vue
│   │   ├── Licenses.vue
│   │   ├── Settings.vue
│   │   └── Users.vue
│   ├── Auth/
│   │   ├── Login.vue
│   │   └── Register.vue
│   ├── Dashboard/
│   │   ├── AccountSettings.vue
│   │   ├── Index.vue
│   │   └── LicenseDetails.vue
│   ├── Home.vue
│   └── Pricing.vue
└── app.js
```
