FastAPI backend for price elasticity simulation and RFM segment analysis in e-commerce
elastix-api powers the elastix frontend with real-time price elasticity calculations based on log-log regression (Paczkowski, 2018). It enables e-commerce managers to simulate pricing scenarios and analyze customer behavior across RFM segments.
- ๐ Price Elasticity Calculation โ Log-log regression with Rยฒ metrics
- ๐ฏ RFM Segmentation โ Customer segment analytics (Champions, At-Risk, etc.)
- ๐ฎ What-If Simulation โ Project revenue impact of price changes
- ๐ Dashboard Metrics โ Aggregated KPIs and time-series data
elastix-api/
โโโ api/
โ โโโ app. py # FastAPI application
โ โโโ settings.py # Configuration
โ โโโ database/ # SQLAlchemy async setup
โ โโโ models/ # ORM models
โ โโโ schemas/ # Pydantic schemas
โ โโโ services/ # Business logic
โ โโโ endpoints/ # Route handlers
โโโ alembic/ # Database migrations
โโโ tests/ # Test suite
โโโ docker-compose.yml
โโโ requirements.txt
# Clone repository
git clone https://github.com/Mert-55/elastix-api.git
cd elastix-api
# Start services
docker-compose up -d
# API available at http://localhost:8000
# Docs at http://localhost:8000/docs# Create virtual environment
python -m venv venv
source venv/bin/activate # Windows: venv\Scripts\activate
# Install dependencies
pip install -r requirements.txt
# Start PostgreSQL
docker run --name elastix-db -e POSTGRES_PASSWORD=postgres \
-e POSTGRES_DB=elastix -p 5432:5432 -d postgres:16
# Run migrations
alembic upgrade head
# Start server
uvicorn api.app:app --reload| Method | Endpoint | Description |
|---|---|---|
GET |
/elasticity |
Calculate price elasticity for products |
GET |
/elasticity/segments |
Elasticity by RFM segment |
| Method | Endpoint | Description |
|---|---|---|
GET |
/dashboard/kpis |
Segment KPI metrics (priceSensitivity, walletShare, churnRisk) |
GET |
/dashboard/segments |
Segment distribution for TreeMap visualization |
GET |
/dashboard/trends |
Time-series revenue data by segment for Area Chart |
| Method | Endpoint | Description |
|---|---|---|
GET |
/stock-items |
Search products with elasticity data |
GET |
/stock-items/{code} |
Product details with full elasticity info |
| Method | Endpoint | Description |
|---|---|---|
POST |
/simulate |
Quick simulation of price change impact |
GET |
/simulations |
List saved simulations |
POST |
/simulations |
Create new simulation |
GET |
/simulations/{id} |
Get simulation by ID |
PUT |
/simulations/{id} |
Update simulation |
DELETE |
/simulations/{id} |
Delete simulation |
GET |
/simulations/{id}/metrics |
Get segment-based simulation metrics |
| Method | Endpoint | Description |
|---|---|---|
GET |
/transactions/{transaction_id} |
Get a single transaction by ID |
PUT |
/transactions/{transaction_id} |
Update a transaction (partial updates supported) |
DELETE |
/transactions/{transaction_id} |
Delete a single transaction |
DELETE |
/transactions?confirm=true |
Delete all transactions (requires confirmation) |
Create .env file:
DATABASE_URL=postgresql+asyncpg://postgres:postgres@localhost: 5432/elastix
DEBUG=false
LOG_LEVEL=INFO
CORS_ORIGINS=http://localhost:5173- Paczkowski, W. R. (2018). Pricing Analytics. Routledge.
- Percival, H., & Gregory, B. (2020). Architecture Patterns with Python. O'Reilly.
- ecommerce-data source
- Frontend: elastix โ React dashboard for visualization
MIT License โ see LICENSE