Back to all projects
AIAIin development

AI assistant for a store on Saleor

An AI layer for an online store on Saleor, in development. The first of six stages is done: Claude writes SEO content for product cards, the result is checked against rules, stored in PostgreSQL and reused as a cache, and every model call is logged with its tokens.

My role: Author: idea, architecture and code.

1 of 6
stages done
≈1,100
lines of Python in the service
48
tests
0
paid API calls in tests

The task

The goal is AI features for an online store on a real stack. The project grows stage by stage: from working with the Claude API directly to an assistant with tools, hybrid search, RAG, an MCP server and a Telegram bot.

Stage 1: from a product's data (name, category, attributes, current description) get an SEO title, a meta description, a description and key features, check them against SEO rules and count the tokens spent. It works two ways: through an API for one product or a batch, and through a CLI for the whole catalog.

Architecture

The service is separate from Saleor: it keeps its data in its own PostgreSQL database and talks to the store only through GraphQL, read-only. The API and the CLI share one service layer.

  1. Entry points
    FastAPIone product at once or a background batch with progress
    CLIthe whole catalog from JSON or Saleor GraphQL; a no-model-call mode
  2. Core
    service.pycache → model → log → SEO check → save
    Repositorystorage protocol: PostgreSQL, or memory in tests
  3. Modules
    llm.pystructured answer, typed errors
    prompts.pyprompt version, SEO limits from seo.py
    seo.pylengths and format
    saleor.pyproducts via GraphQL, Editor.js to text
  4. Data and external APIs
    PostgreSQL 17generations as cache, call log, jobs
    Claude APISonnet by default, Haiku to save money
    Saleor GraphQLread-only

Key decisions

A structured answer with no length limits in the schema

The model's answer is parsed straight into a Pydantic schema with messages.parse. The schema itself has no length limits: seo.py checks the lengths and returns a list of issues.

Why
If a limit sits in the schema and the model exceeds it, the SDK drops the whole answer, and the tokens are already paid for.
Trade-off
A result with issues has to be regenerated or fixed by hand.

A cache by product, model and prompt version

A finished generation is stored in PostgreSQL. Processing the same product with the same model and prompt version again does not call the API.

Why
The catalog can be re-run any number of times without extra cost.
Trade-off
After changing the prompt you have to bump its version, otherwise old results stay.

A log of every model call

Every request to Claude is logged with the model, tokens and outcome, and API errors become typed exceptions.

Why
The cost is visible per product and per batch, and a failure is clear without reading logs.
Trade-off
The log grows with every run and will need cleanup.

Storage behind a protocol

The service layer works only through the Repository protocol and knows nothing about SQLAlchemy. In tests an in-memory store replaces it; tests with a real database are marked separately.

Why
The main tests run without an API key, network or database, in seconds.
Trade-off
Two storage implementations must be kept in sync.

Batches in parallel, within limits

A batch of up to 200 products runs as a background job, and its progress is available through a separate request. Products are processed in parallel under a semaphore.

Why
The catalog is processed faster without hitting the API limits.
Trade-off
The background job lives in the service process: after a restart it has to be started again.

The API directly first, frameworks later

Stage 1 works with the official Anthropic SDK, without LangChain or other wrappers. The LLM is called only from Python, never from SQL.

Why
First understand the API itself — errors, tokens, concurrency — and only then take a framework (stage 5).
Trade-off
Some code a framework would provide is written by hand.

Hard parts

Testing an LLM service for free

Real Claude calls cost money. Unit tests replace HTTP, the CLI has a mode without model calls, and the API can be pointed at a local stub. A real run happens only on purpose.

Docs drifting from the installed SDK

The task referred to model IDs that do not exist. The project rule: check SDK behaviour against the installed source code, not against memory or old examples.

What's next

The plan for stages 2–6.

Stage 2

Tool use and agents that call Saleor GraphQL.

Stage 3

Embeddings and hybrid search over the catalog.

Stage 4

RAG over the store's data.

Stage 5

LangChain and LangGraph, an MCP server.

Stage 6

A Telegram bot, a Vue widget and production.

Stack

Backend
Python 3.11+, FastAPI, Pydantic v2, httpx
LLM
Anthropic SDK (Claude), structured outputs
Data
PostgreSQL 17, SQLAlchemy 2 (async), asyncpg, Alembic
Quality
pytest, pytest-asyncio, Ruff

Need a similar system?

Tell me about the task — I reply within a day in RU, RO or EN.