An AI-powered analytics application that connects to Shopify stores and allows users to ask natural language questions about their store data.
┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐
│ Frontend │────▶│ Rails API │────▶│ AI Service │
│ (Nginx/HTML) │ │ (Gateway) │ │ (FastAPI) │
│ Port: 8080 │ │ Port: 3000 │ │ Port: 8000 │
└─────────────────┘ └────────┬────────┘ └────────┬────────┘
│ │
▼ ▼
┌─────────────────┐ ┌─────────────────┐
│ PostgreSQL │ │ Shopify API │
│ Port: 5432 │ │ + OpenAI API │
└─────────────────┘ └─────────────────┘
-
Frontend (Port 8080)
- Simple HTML/CSS/JS interface
- Shopify OAuth flow initiation
- Question input and response display
-
Rails API (Port 3000)
- Shopify OAuth handling
- Request validation and routing
- Store management and request logging
-
AI Service (Port 8000)
- LLM-powered analytics agent
- Intent classification
- GraphQL query generation
- Natural language response generation
-
PostgreSQL (Port 5432)
- Store credentials
- Request logs
┌──────────────────────────────────────────────────────────────────┐
│ Analytics Agent │
├──────────────────────────────────────────────────────────────────┤
│ 1. UNDERSTAND INTENT │
│ └─▶ Classify question (inventory/sales/customers/products) │
│ │
│ 2. GENERATE QUERY │
│ └─▶ Create appropriate Shopify GraphQL query │
│ │
│ 3. EXECUTE │
│ └─▶ Fetch data from Shopify Admin API │
│ │
│ 4. ANALYZE │
│ └─▶ Process results with LLM │
│ │
│ 5. RESPOND │
│ └─▶ Return human-friendly answer with confidence level │
└──────────────────────────────────────────────────────────────────┘
- Docker and Docker Compose
- Shopify Partner account with app credentials
- OpenAI API key
-
Shopify OAuth Credentials (provided in .env)
SHOPIFY_API_KEYSHOPIFY_API_SECRET
-
OpenAI API Key (you need to provide)
OPENAI_API_KEY- Get one at: https://platform.openai.com/api-keys
-
Clone and configure
cd shopify cp .env.example .env # Edit .env and add your OPENAI_API_KEY
-
Start all services
docker-compose up --build
-
Access the application
- Frontend: http://localhost:8080
- Rails API: http://localhost:3000
- AI Service: http://localhost:8000
-
Connect your Shopify store
- Enter your store domain (e.g.,
your-store.myshopify.com) - Complete OAuth authorization
- Start asking questions!
- Enter your store domain (e.g.,
GET /health
GET /auth/shopify?shop=your-store.myshopify.com
POST /api/v1/questions
Content-Type: application/json
{
"store_id": "your-store.myshopify.com",
"question": "What were my top 5 selling products last week?"
}
Response:
{
"answer": "Based on your order data, your top 5 selling products last week were...",
"confidence": "high",
"intent": "sales",
"store_id": "your-store.myshopify.com"
}
GET /api/v1/stores
GET /api/v1/stores/:shop_domain/verify
GET /health
POST /analyze
Content-Type: application/json
{
"store_id": "your-store.myshopify.com",
"question": "How much inventory should I reorder?",
"access_token": "shpat_xxxxx"
}
- "How many units of Product X will I need next month?"
- "Which products are likely to go out of stock in 7 days?"
- "What were my top 5 selling products last week?"
- "How much inventory should I reorder based on last 30 days sales?"
- "Which customers placed repeat orders in the last 90 days?"
# AI Service only
cd services/ai-service
pip install -r requirements.txt
uvicorn app.main:app --reload --port 8000
# Rails API only
cd services/rails-api
bundle install
rails db:prepare
rails server -p 3000
# Frontend only
cd services/frontend
python -m http.server 8080docker-compose exec rails-api rails db:migrateshopify/
├── docker-compose.yml # Orchestration
├── .env # Environment variables
├── README.md
└── services/
├── ai-service/ # Python FastAPI
│ ├── Dockerfile
│ ├── requirements.txt
│ └── app/
│ ├── main.py # FastAPI app
│ ├── config.py # Settings
│ ├── agents/
│ │ └── analytics_agent.py
│ ├── services/
│ │ ├── llm_service.py
│ │ └── shopify_service.py
│ └── models/
│ └── schemas.py
│
├── rails-api/ # Ruby on Rails
│ ├── Dockerfile
│ ├── Gemfile
│ ├── config/
│ │ ├── routes.rb
│ │ └── initializers/
│ ├── app/
│ │ ├── controllers/
│ │ │ ├── auth_controller.rb
│ │ │ └── api/v1/
│ │ │ ├── questions_controller.rb
│ │ │ └── stores_controller.rb
│ │ └── models/
│ │ ├── store.rb
│ │ └── request_log.rb
│ └── db/
│ └── migrate/
│
└── frontend/ # Simple HTML/JS
├── Dockerfile
├── nginx.conf
├── index.html
├── styles.css
└── app.js
- Access tokens are stored in PostgreSQL (encrypt in production)
- All inter-service communication is within Docker network
- CORS is configured for development (restrict in production)
- Use HTTPS in production
- Ensure your Shopify app's redirect URL is set to
http://localhost:3000/auth/shopify/callback - For production, update the HOST environment variable
- Verify your OpenAI API key is valid and has credits
- Check the AI service logs:
docker-compose logs ai-service
- Reset database:
docker-compose down -v && docker-compose up --build