SmartRetail_AI

SmartRetail AI

Enterprise multi-camera retail intelligence, loss prevention & store analytics platform.

SmartRetail AI converts existing CCTV infrastructure into an explainable, event-aware retail analytics system — understanding people, products, shelves, carts, staff, checkout events, and camera relationships to surface store intelligence and loss-prevention decision support.

It is a decision-support and human-review platform. It never autonomously declares a person guilty: every alert is scored, explained with evidence (who, what, when, where, which camera, which product, why, how confident), and reviewed by a human operator.

Observe → Track → Associate → Understand → Score → Explain → Alert → Human Review → Learn

High-Level Architecture

  CCTV Cameras (RTSP / ONVIF / Files)
            │
            ▼
  ┌──────────────────────┐        ┌──────────────────────┐
  │   Video Ingestion    │        │   Detection &        │
  │   (services/         │───────▶│   Tracking           │
  │    ingestion)        │        │   (detection/tracking│
  └──────────────────────┘        └──────────┬───────────┘
                                             │
                                             ▼
                              ┌──────────────────────────┐
                              │  Multi-Camera Tracking / │
                              │  Re-ID / Camera Handoff  │
                              └──────────┬───────────────┘
                                         │
                                         ▼
                              ┌──────────────────────────┐
                              │  Event Understanding      │
                              │  (events, product,       │
                              │   interaction)           │
                              └──────────┬───────────────┘
                                         │
                                         ▼
                              ┌──────────────────────────┐
                              │  Risk Engine             │
                              │  (risk-engine)           │
                              └──────────┬───────────────┘
                                         │
                                         ▼
                              ┌──────────────────────────┐
                              │  Dashboard / Alerting    │
                              │  (frontend, notifications)│
                              └──────────────────────────┘

  ┌───────────────┬──────────────┬──────────────┬──────────────┐
  │ PostgreSQL    │    Redis     │   Worker     │  Analytics   │
  │ (persistence) │ (cache/bus)  │  (async jobs)│ (aggregation)│
  └───────────────┴──────────────┴──────────────┴──────────────┘

Event flow: detection → tracking → interaction → behavior → risk → alert.

Repository Layout

Path What lives here
apps/ Deployable applications: backend/ (FastAPI API), frontend/ (dashboard), worker/ (async jobs), ai-services/ (CV/ML inference).
services/ Domain service packages: ingestion, detection, tracking, reid, product, interaction, events, risk-engine, analytics, notifications.
models/ ML model artifacts: detection, tracking, reid, pose, action.
datasets/ Data: raw, annotations, processed, splits.
database/ migrations/ (Alembic) and seeds/.
infrastructure/ docker/, kubernetes/ (stubbed until Phase 19), monitoring/.
tests/ unit/, integration/, scenarios/, performance/.
docs/ architecture/ (living overview), api/, models/, deployment/.
scripts/ Dev/test/lint/migrate helpers (shell + PowerShell).

Every folder above is self-documenting via its own README.md.

Technology Stack

Rationale and the full decision record: docs/architecture/overview.md.

Getting Started

Prerequisites: Docker with Docker Compose (v2). For local (non-Docker) backend dev: Python 3.13+.

  1. Clone the repo

    git clone <repository-url> smartretail-ai
    cd smartretail-ai
    
  2. Copy the environment file

    cp .env.example .env
    

    Everything has sane defaults for local dev; edit if you want different ports or credentials. .env is gitignored.

  3. Start the stack

    docker compose up --build
    

    (or make up, or scripts/dev.ps1 / scripts/dev.sh.) This brings up:

  4. Confirm the stack

    curl http://localhost:8000/health
    

    Expect a structured JSON body with each dependency reported individually:

    {
      "status": "ok",
      "service": "SmartRetail AI Backend",
      "version": "0.1.0",
      "checks": {
        "database": "ok",
        "redis": "ok"
      },
      "timestamp": "..."
    }
    

    curl http://localhost:8000/version reports the running git commit and build tag — useful once multiple services are deployed independently.

  5. Run the test suite

    python -m venv .venv
    .venv/Scripts/pip install -r apps/backend/requirements-dev.txt   # PowerShell
    # or: make install
    .venv/Scripts/python -m pytest                                   # PowerShell
    # or: make test   (or scripts/test.ps1 / scripts/test.sh)
    

    Lint: make lint (or scripts/lint.ps1 / scripts/lint.sh). Migrations: make migrate (or scripts/migrate.ps1 / scripts/migrate.sh).

Common commands

Task Command
Start stack docker compose up --build / make up
Stop stack docker compose down
Tail logs docker compose logs -f
Tests make test
Lint make lint
Format make format
Migrate make migrate

Troubleshooting

Roadmap & Implementation Status

All 10 Specification Roadmap Phases (spec §100; engineering phases 1-21 in docs) are complete and verified end-to-end:

Section 101 Reference Demonstration

Run the complete multi-camera scenario from spec §101:

# Standalone CLI execution
python scripts/run_demo_scenario.py
# Or: make demo / scripts/run_demo.ps1 / scripts/run_demo.sh

# To execute and persist all live entities directly into PostgreSQL:
python scripts/run_demo_scenario.py --persist-db

Dashboard (Phase 20)

make dev (or uvicorn app.main:app) then open:

Testing & Benchmarks

# Run unit tests
pytest tests/unit

# Run end-to-end scenario tests
pytest tests/scenarios

# Run performance and throughput benchmarks
pytest tests/performance

# Run all test suites
pytest

Test databases

Integration tests run against \smartretail_v3\ by default (see conftest.py). The reset path uses ordered DELETE — do NOT reintroduce TRUNCATE … CASCADE (wedges indefinitely on PostgreSQL 18 under this workload).