Skip to content

๐Ÿš€ FastAPI backend for price elasticity calculation using log-log regression. Supports RFM segmentation and what-if pricing simulations. PostgreSQL + Docker.

License

Notifications You must be signed in to change notification settings

Mert-55/elastix-api

๐Ÿš€ elastix-api

FastAPI backend for price elasticity simulation and RFM segment analysis in e-commerce

Python FastAPI PostgreSQL License:  MIT


๐Ÿ“– Overview

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.

Key Features

  • ๐Ÿ“Š 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

๐Ÿ—๏ธ Architecture

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

โšก Quickstart

Option 1: Docker (Recommended)

# 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

Option 2: Local Development

# 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

๐Ÿ“ก API Endpoints

Elasticity

Method Endpoint Description
GET /elasticity Calculate price elasticity for products
GET /elasticity/segments Elasticity by RFM segment

Dashboard

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

Stock Items

Method Endpoint Description
GET /stock-items Search products with elasticity data
GET /stock-items/{code} Product details with full elasticity info

Simulation

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

Transactions

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)

๐Ÿ”ง Configuration

Create .env file:

DATABASE_URL=postgresql+asyncpg://postgres:postgres@localhost: 5432/elastix
DEBUG=false
LOG_LEVEL=INFO
CORS_ORIGINS=http://localhost:5173

๐Ÿ“š References

  • Paczkowski, W. R. (2018). Pricing Analytics. Routledge.
  • Percival, H., & Gregory, B. (2020). Architecture Patterns with Python. O'Reilly.
  • ecommerce-data source

๐Ÿ”— Related

  • Frontend: elastix โ€” React dashboard for visualization

๐Ÿ“„ License

MIT License โ€” see LICENSE

About

๐Ÿš€ FastAPI backend for price elasticity calculation using log-log regression. Supports RFM segmentation and what-if pricing simulations. PostgreSQL + Docker.

Resources

License

Code of conduct

Contributing

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published