AI-powered Inventory Management Platform β proactive demand planning, LLM-powered analytics, and autonomous purchasing agents.
Team: Horizonte Infinito β Ayman Mohamed Β· Omar Wael Β· Mostafa Abdel Aziz Β· Mostafa Abdel Qawy Β· Mawada Alexander
Target Industry: Logistics, E-commerce, and Retail Supply Chain
- Problem
- Solution
- Key Features
- Tech Stack
- Architecture
- Project Structure
- Getting Started
- Production Deployment
- Available Commands
- Testing
- CI/CD
- Post-Deployment Verification
- Security
- Further Reading
- License
E-commerce and logistics enterprises lose revenue to two inventory failure modes: overstocking (immobilised working capital) and stockouts (lost sales). Incumbent systems are reactive β relying on manual audits that miss seasonal demand curves, macroeconomic signals, and supplier lead-time variability.
SmartStock AI couples real-time inventory tracking with AI-driven demand forecasting to shift decision-making from reactive correction to anticipatory action. The system notifies managers of impending shortfalls before they materialise, auto-drafts purchase orders, and provides a natural-language interface for ad-hoc analytics.
- Inventory Management β CRUD for products, SKUs, stock levels with low-stock alerts
- Demand Forecasting β Prophet time-series model per SKU with Recharts visualisation
- NL Analytics β Natural-language queries against inventory data via GPT-4o + LangChain
- RAG Pipeline β Hybrid search (pgvector dense + PostgreSQL FTS) with Cohere reranking and source citations
- Multi-Agent Pipeline β Forecasting Agent β Decision Agent β Purchasing Agent (HITL)
- Multimodal Input β GPT-4o Vision invoice scanning + Whisper speech-to-text
- RBAC β Viewer / Manager / Admin roles with JWT authentication
- Observability β Langfuse tracing for LLM calls, RAG retrieval, and agent actions
| Layer | Technology |
|---|---|
| Frontend | React 19 Β· TypeScript Β· Vite 8 Β· Tailwind CSS 4 Β· Recharts Β· React Query Β· Zustand |
| Backend | Django 5 Β· DRF Β· Python 3.12 Β· Celery |
| Database | PostgreSQL 16 Β· pgvector Β· Redis 7 |
| AI / ML | Prophet Β· LangChain Β· GPT-4o Β· text-embedding-3-small Β· Cohere |
| Infrastructure | Docker Β· GitHub Actions Β· Railway (deploy) |
| Monitoring | Prometheus Β· Grafana Β· Alertmanager Β· Langfuse |
The project follows Clean Architecture with feature-based Django apps. Outer layers depend on inner layers β never the other way around.
Presentation βββΊ Application βββΊ Domain βββΊ Infrastructure
(DRF Views) (Services) (Entities) (DB / Cache / Email)
Each Django app (authentication, inventory, forecasting, purchasing, audit) is a vertical slice containing its own models, views, services, and repositories.
The AI layer (ai/) is fully isolated β swapping GPT-4o for another model only touches ai/llm/chain.py.
smartstock-backend/ # Django REST API (Clean Architecture)
βββ config/ # Project settings (dev/prod), Celery, URL routing
βββ apps/ # Feature-based Django apps
β βββ authentication/ # JWT, RBAC, CustomUser model
β βββ inventory/ # Products, SKUs, stock levels
β βββ forecasting/ # Prophet model, reorder logic
β βββ purchasing/ # Purchase orders, supplier management
β βββ ingestion/ # Document upload, RAG query
β βββ audit/ # Audit logging (signals + middleware)
β βββ monitoring/ # Prometheus metrics, alerting
β βββ notifications/ # Email + dashboard notifications
β βββ health/ # Readiness / liveness probes
βββ ai/ # Isolated AI layer
β βββ llm/ # LangChain chain, prompts, output parser
β βββ rag/ # Ingestion, hybrid retrieval, citation
β βββ agents/ # 3 agents + 8 plugin tools
β βββ multimodal/ # Vision OCR, Whisper STT
β βββ evaluation/ # AI evaluation metrics
β βββ observability/ # Langfuse tracing integration
βββ core/ # Shared abstractions (BaseRepository, exceptions)
βββ infrastructure/ # Redis, email, file storage wrappers
βββ tests/ # Unit, integration, golden dataset
βββ Dockerfile
βββ Dockerfile.prod # Production image (non-root, collectstatic)
βββ entrypoint.sh
βββ railway.toml # Railway web service config
βββ railway.worker.toml # Railway Celery worker config
βββ DEPLOY.md # Detailed deployment guide
smartstock-frontend/ # React + TypeScript SPA
βββ src/
β βββ features/ # Vertical slices per domain
β β βββ ai-assistant/ # AI chat & voice assistant
β β βββ auth/ # Login, register, session management
β β βββ dashboard/ # Dashboard widgets & metrics
β β βββ forecasting/ # Demand forecasting charts & alerts
β β βββ inventory/ # Product & stock management
β β βββ invoice-scan/ # AI-powered invoice scanning
β β βββ purchasing/ # Purchase orders & suppliers
β β βββ users/ # User management (admin)
β βββ lib/ # Axios, React Query, Router config
β βββ shared/ # Reusable components/hooks
β βββ store/ # Zustand (client state only)
βββ Dockerfile # Multi-stage build (Node β Nginx)
βββ nginx.conf # Production reverse proxy
βββ docker-entrypoint.sh # Runtime env injection for Docker
monitoring/ # Observability stack
βββ prometheus/ # Prometheus config + alert rules
βββ grafana/ # Pre-built dashboards + datasources
βββ alertmanager/ # Alert routing config
- Python 3.12+
- Node.js 22+
- PostgreSQL 16+ (with pgvector extension)
- Redis 7+
- OpenAI API key
- Cohere API key (for RAG reranking)
cd smartstock-backend
python -m venv .venv && source .venv/bin/activate
pip install -r requirements.txt
cp .env.example .env # fill in your environment variables
python manage.py migrate
python manage.py runserverThe API is available at http://localhost:8000/api/. Swagger docs at http://localhost:8000/api/schema/swagger-ui/.
cd smartstock-frontend
cp .env.example .env.local
npm install
npm run devDev server starts on http://localhost:5173. API requests to /api are proxied to http://localhost:8000.
docker compose up --buildThis starts all services:
| Service | Container | URL |
|---|---|---|
| Frontend | smartstock_frontend |
http://localhost:5173 |
| Backend API | smartstock_backend |
http://localhost:8000/api/ |
| Celery Worker | smartstock_celery |
β |
| Celery Beat | smartstock_celery_beat |
β |
| PostgreSQL | smartstock_db |
localhost:5433 |
| Redis | smartstock_redis |
localhost:6379 |
| Prometheus | smartstock_prometheus |
http://localhost:9090 |
| Alertmanager | smartstock_alertmanager |
http://localhost:9093 |
| Grafana | smartstock_grafana |
http://localhost:3001 |
Note: This uses
manage.py runserverand volume mounts for live reload. For production, see the Production Deployment section.
Note: The root
.envfile is shared by all Docker services. Copysmartstock-backend/.env.exampleorsmartstock-frontend/.env.examplefor each service.
The Docker Compose stack includes a full observability suite (enabled via the monitoring profile):
docker compose --profile monitoring up -d- Prometheus β scrapes backend metrics, 30-day retention. Config at
monitoring/prometheus/. - Grafana β pre-built dashboards at http://localhost:3001 (admin/password). Datasources and dashboards provisioned from
monitoring/grafana/. - Alertmanager β routes alerts for latency p95 >3s, error rate >1%, and LLM budget caps. Config at
monitoring/alertmanager/. - Langfuse β traces every LLM call, RAG retrieval, and agent tool invocation. Requires
LANGFUSE_PUBLIC_KEYandLANGFUSE_SECRET_KEYenv vars.
Monitoring stack configuration lives in the monitoring/ directory.
-
Generate secrets:
python -c "import secrets; print(secrets.token_urlsafe(50))" -
Set environment variables (minimum required):
DJANGO_SECRET_KEY=<generated-secret> DJANGO_DEBUG=False ALLOWED_HOSTS=.up.railway.app REDIS_URL=redis://default:...@your-redis-host:port OPENAI_API_KEY=sk-... COHERE_API_KEY=... CORS_ALLOWED_ORIGINS=https://your-frontend.vercel.app
-
Deploy to Railway β create a project from the GitHub repo, add the PostgreSQL and Redis plugins, and configure the two services (
smartstock-apiandsmartstock-worker). -
Run the smoke test:
BACKEND_URL=https://your-api.up.railway.app \ FRONTEND_URL=https://your-frontend.vercel.app \ ./scripts/smoke-test.sh
For the full deployment checklist, see smartstock-backend/DEPLOY.md.
Both services use the same Docker image (Dockerfile.prod) β only the start command differs:
| Service | Config File | Start Command |
|---|---|---|
smartstock-api |
railway.toml |
migrate + gunicorn |
smartstock-worker |
railway.worker.toml |
celery worker |
The backend has two Dockerfiles:
Dockerfileβ used bydocker compose up --buildfor local development. Includes dev dependencies, volume-compatible, usesconfig.settings.development.Dockerfile.prodβ used by Railway and production deployments. No volume mounts (fully self-contained), runs as non-root user (appuser), runscollectstaticon startup, usesconfig.settings.production.
| Variable | Purpose |
|---|---|
DJANGO_SECRET_KEY |
Cryptographic signing key |
DJANGO_DEBUG |
Must be False in production |
ALLOWED_HOSTS |
Must include your production domain |
REDIS_URL |
Redis for Celery broker + result backend |
OPENAI_API_KEY |
GPT-4o, embeddings, Whisper |
COHERE_API_KEY |
RAG reranking |
CORS_ALLOWED_ORIGINS |
Must include your frontend URL |
Cost estimate: ~$18β25/month on Railway (web service + worker + Postgres plugin + Redis plugin). See
DEPLOY.mdfor details.
- Vercel: Deploy
dist/to Vercel. SetVITE_API_URLorVITE_API_BASE_URLfor absolute backend URL. - Docker:
docker compose up --buildruns the full stack with Nginx serving the SPA and proxying API calls.
For the complete annotated list of all environment variables, see each service's .env.example:
| Service | See |
|---|---|
| Backend | smartstock-backend/.env.example |
| Frontend | smartstock-frontend/.env.example |
Production-specific notes:
DATABASE_URLis auto-injected by Railway's Postgres plugin β no need to set it manuallyDJANGO_DEBUGmust beFalsein productionALLOWED_HOSTSmust include your production domain (e.g..up.railway.app)CSRF_TRUSTED_ORIGINSmust include your frontend URL if serving from a different domain
ruff check . # Lint
ruff format . # Format
pytest # Run tests (SQLite in-memory)
pytest --cov=. --cov-report=html # With coverage
python manage.py migrate # Run migrations
python manage.py createsuperuser
python manage.py seed_data # Populate test datanpm run dev # Vite dev server (port 5173, HMR)
npm run build # tsc -b + vite build
npm run preview # Preview production build
npm run lint # ESLintdocker compose up --build # Build + start all services
docker compose down # Stop all services
docker compose logs -f backend # Tail backend logs
docker compose exec backend python manage.py shell # Django shellcd smartstock-backend
pytest # Unit + integration (SQLite)
DATABASE_URL=postgres://... pytest # Against real Postgres
pytest tests/unit/ # Unit tests only
pytest tests/integration/ # Integration tests only- Tests use
config.settings.test(Redis disabled, Celery eager, Cloudinary disabled) - CI enforces β₯80% coverage (
--cov-fail-under=80) - Golden dataset: 30 annotated NL queries run in CI on merge to main
- OpenAPI schema validation runs in CI
cd smartstock-frontend
npm run lint # ESLint
npx tsc --noEmit # Type checkingNo test framework is currently configured. CI runs lint + build on every push/PR.
GitHub Actions workflows on push to main/develop and PRs to main:
| Job | What it does |
|---|---|
backend-lint |
ruff check + ruff format --check |
backend-test |
pytest with Postgres service container, β₯80% coverage gate, OpenAPI schema validation |
backend-check |
python manage.py check (system check) |
frontend-lint |
npm run lint + tsc --noEmit |
frontend-build |
npm run build |
See .github/workflows/ci.yml for the full workflow.
After deploying, run the smoke test to verify all endpoints are reachable:
BACKEND_URL=https://your-api.up.railway.app \
FRONTEND_URL=https://your-frontend.vercel.app \
./scripts/smoke-test.shOptional: set HEALTH_SECRET to match the HEALTH_SECRET_HEADER env var configured on the backend.
The smoke test performs the following checks:
| Check | Endpoint | Expected |
|---|---|---|
| Backend liveness | GET /api/health/live/ |
200 |
| Backend readiness | GET /api/health/ready/ |
200 |
| API root | GET /api/ |
200 or 404 |
| Frontend homepage | GET / |
200 |
| SPA shell | HTML body check | Contains SmartStock or <div id="root"> |
| API proxy | GET /api/health/live/ via frontend |
200 (or 404/502 for external backends) |
Health endpoint details:
GET /api/health/live/is unauthenticated and always returns 200 when the process is running.GET /api/health/ready/checks database and Redis connectivity β it can be protected with theHEALTH_SECRET_HEADERenv var (sendsX-Health-Secretheader).GET /api/health/full/requires JWT authentication and checks all subsystems.
- JWT authentication (15-min access + 7-day refresh as HttpOnly cookie)
- RBAC β Viewer (read-only), Manager (approve POs), Admin (full access)
- HITL β No PO dispatched without manager approval
- Prompt injection defence via isolated system prompts + output validation
- Rate limiting β 100 req/min/user, daily LLM token quotas
- All secrets managed via
.env, never hardcoded
| Document | Description |
|---|---|
design-system-prompt.md |
Design system reference (brand colors, tokens) |
smartstock-backend/DEPLOY.md |
Railway deployment guide |
Graduation Project β ITI (Information Technology Institute)