An open API service indexing awesome lists of open source software.

https://github.com/xshopai/inventory-service

Tracks stock levels, availability, and inventory updates.
https://github.com/xshopai/inventory-service

flask microservice mysql python xshopai

Last synced: 3 months ago
JSON representation

Tracks stock levels, availability, and inventory updates.

Awesome Lists containing this project

README

          

# ๐Ÿ“ฆ Inventory Service

**Enterprise-grade inventory management microservice for the xshopai e-commerce platform**

[![Python](https://img.shields.io/badge/Python-3.11+-3776AB?style=for-the-badge&logo=python&logoColor=white)](https://python.org)
[![Flask](https://img.shields.io/badge/Flask-3.0+-000000?style=for-the-badge&logo=flask&logoColor=white)](https://flask.palletsprojects.com)
[![MySQL](https://img.shields.io/badge/MySQL-8.0+-4479A1?style=for-the-badge&logo=mysql&logoColor=white)](https://mysql.com)
[![Dapr](https://img.shields.io/badge/Dapr-Enabled-0D597F?style=for-the-badge&logo=dapr&logoColor=white)](https://dapr.io)
[![License](https://img.shields.io/badge/License-Proprietary-red?style=for-the-badge)](LICENSE)

[Getting Started](#-getting-started) โ€ข
[Documentation](#-documentation) โ€ข
[API Reference](docs/PRD.md) โ€ข
[Contributing](#-contributing)

---

## ๐ŸŽฏ Overview

The **Inventory Service** is a critical microservice responsible for managing real-time stock levels, reservations, stock movements, and event-driven inventory synchronization across the xshopai platform. Built with scalability and reliability in mind, it supports multi-cloud deployments and integrates seamlessly with the broader microservices ecosystem.

---

## โœจ Key Features

### ๐Ÿ“Š Stock Management

- Real-time inventory tracking
- Multi-variant product support
- Low stock alerts & thresholds
- Automatic stock reconciliation

### ๐Ÿ”’ Reservation System

- Time-limited stock reservations
- Automatic expiration handling
- Order processing integration
- Concurrent access control

### ๐Ÿ“ก Event-Driven Architecture

- CloudEvents 1.0 specification
- Pub/sub messaging integration
- Real-time inventory updates
- Cross-service synchronization

### ๐Ÿ›ก๏ธ Enterprise Security

- JWT token authentication
- Service-to-service tokens
- Role-based access control
- Complete audit trail

---

## ๐Ÿš€ Getting Started

### Prerequisites

- Python 3.11+
- MySQL 8.0+
- Docker & Docker Compose (optional)
- Dapr CLI (for production-like setup)

### Quick Start with Docker Compose

```bash
# Clone the repository
git clone https://github.com/xshopai/inventory-service.git
cd inventory-service

# Start all services (MySQL, service, etc.)
docker-compose up -d

# Verify the service is healthy
curl http://localhost:8005/health
```

### Local Development Setup

๐Ÿ”ง Without Dapr (Simple Setup)

```bash
# Create virtual environment
python -m venv venv
source venv/bin/activate # Windows: venv\Scripts\activate

# Install dependencies
pip install -r requirements.txt

# Set up environment variables
cp .env.example .env
# Edit .env with your configuration

# Run database migrations
flask db upgrade

# Start the service
python run.py
```

๐Ÿ“– See [Local Development Guide](docs/LOCAL_DEVELOPMENT.md) for detailed instructions.

โšก With Dapr (Production-like)

```bash
# Ensure Dapr is initialized
dapr init

# Start with Dapr sidecar
dapr run \
--app-id inventory-service \
--app-port 8005 \
--dapr-http-port 3500 \
--resources-path .dapr/components \
--config .dapr/config.yaml \
-- python run.py
```

> **Note:** All services now use the standard Dapr ports (3500 for HTTP, 50001 for gRPC). This simplifies configuration and works consistently whether running via Docker Compose or individual service runs.

๐Ÿ“– See [Dapr Development Guide](docs/LOCAL_DEVELOPMENT_DAPR.md) for detailed instructions.

---

## ๐Ÿ“š Documentation

| Document | Description |
| :--------------------------------------------------------------- | :--------------------------------------------------- |
| ๐Ÿ“˜ [Local Development](docs/LOCAL_DEVELOPMENT.md) | Step-by-step local setup without Dapr |
| โšก [Local Development with Dapr](docs/LOCAL_DEVELOPMENT_DAPR.md) | Local setup with full Dapr integration |
| โ˜๏ธ [Azure Container Apps](docs/ACA_DEPLOYMENT.md) | Deploy to serverless containers with built-in Dapr |
| ๐Ÿ“‹ [Product Requirements](docs/PRD.md) | Complete API specification and business requirements |
| ๐Ÿ—๏ธ [Architecture](docs/ARCHITECTURE.md) | System design, patterns, and data flows |
| ๐Ÿ” [Security](.github/SECURITY.md) | Security policies and vulnerability reporting |

---

## ๐Ÿงช Testing

We maintain high code quality standards with comprehensive test coverage.

```bash
# Run all unit tests
pytest tests/unit/ -v

# Run with coverage report
pytest --cov=src --cov-report=html --cov-report=term-missing

# Run specific test file
pytest tests/unit/test_inventory_service.py -v

# Run integration tests (requires running services)
pytest tests/integration/ -v
```

### Test Coverage

| Metric | Status |
| :------------ | :------------------- |
| Unit Tests | โœ… 33 passing |
| Code Coverage | โœ… 91.4% |
| Security Scan | โœ… 0 vulnerabilities |

---

## ๐Ÿ—๏ธ Project Structure

```
inventory-service/
โ”œโ”€โ”€ ๐Ÿ“ src/ # Application source code
โ”‚ โ”œโ”€โ”€ ๐Ÿ“ controllers/ # REST API endpoints
โ”‚ โ”œโ”€โ”€ ๐Ÿ“ services/ # Business logic layer
โ”‚ โ”œโ”€โ”€ ๐Ÿ“ repositories/ # Data access layer
โ”‚ โ”œโ”€โ”€ ๐Ÿ“ models/ # SQLAlchemy models
โ”‚ โ”œโ”€โ”€ ๐Ÿ“ messaging/ # Messaging abstraction (Dapr/ServiceBus/RabbitMQ)
โ”‚ โ”œโ”€โ”€ ๐Ÿ“ middlewares/ # Authentication, logging, tracing
โ”‚ โ””โ”€โ”€ ๐Ÿ“ utils/ # Helper functions & utilities
โ”œโ”€โ”€ ๐Ÿ“ tests/ # Test suite
โ”‚ โ”œโ”€โ”€ ๐Ÿ“ unit/ # Unit tests
โ”‚ โ”œโ”€โ”€ ๐Ÿ“ integration/ # Integration tests
โ”‚ โ””โ”€โ”€ ๐Ÿ“ e2e/ # End-to-end tests
โ”œโ”€โ”€ ๐Ÿ“ migrations/ # Alembic database migrations
โ”œโ”€โ”€ ๐Ÿ“ .dapr/ # Dapr configuration
โ”‚ โ”œโ”€โ”€ ๐Ÿ“ components/ # Pub/sub, secrets, state stores
โ”‚ โ””โ”€โ”€ ๐Ÿ“„ config.yaml # Dapr runtime configuration
โ”œโ”€โ”€ ๐Ÿ“ docs/ # Documentation
โ”œโ”€โ”€ ๐Ÿ“„ docker-compose.yml # Local containerized environment
โ”œโ”€โ”€ ๐Ÿ“„ Dockerfile # Production container image
โ””โ”€โ”€ ๐Ÿ“„ requirements.txt # Python dependencies
```

---

## ๐Ÿ”ง Technology Stack

| Category | Technology |
| :---------------- | :-------------------------------------------- |
| ๐Ÿ Runtime | Python 3.11+ |
| ๐ŸŒ Framework | Flask 3.0+ with Flask-RESTX (OpenAPI/Swagger) |
| ๐Ÿ—„๏ธ Database | MySQL 8.0+ with SQLAlchemy ORM |
| ๐Ÿ“จ Messaging | Dapr Pub/Sub, Azure Service Bus, RabbitMQ |
| ๐Ÿ“‹ Event Format | CloudEvents 1.0 Specification |
| ๐Ÿ” Authentication | JWT Tokens + Service-to-Service Tokens |
| ๐Ÿงช Testing | pytest with coverage reporting |
| ๐Ÿ“Š Observability | Structured logging, distributed tracing |

---

## โšก Quick Reference

```bash
# ๐Ÿณ Docker Compose
docker-compose up -d # Start all services
docker-compose down # Stop all services
docker-compose logs -f inventory # View logs

# ๐Ÿ Local Development
python run.py # Run without Dapr
flask db upgrade # Apply migrations
flask db migrate -m "message" # Create migration

# โšก Dapr Development
dapr run --app-id inventory-service --app-port 8005 -- python run.py

# ๐Ÿงช Testing
pytest tests/unit/ -v # Run unit tests
pytest --cov=src # Run with coverage

# ๐Ÿ” Health Check
curl http://localhost:8005/health
curl http://localhost:8005/health/ready
```

---

## ๐Ÿค Contributing

We welcome contributions! Please follow these steps:

1. **Fork** the repository
2. **Create** a feature branch
```bash
git checkout -b feature/amazing-feature
```
3. **Write** tests for your changes
4. **Run** the test suite
```bash
pytest && black . && flake8
```
5. **Commit** your changes
```bash
git commit -m 'feat: add amazing feature'
```
6. **Push** to your branch
```bash
git push origin feature/amazing-feature
```
7. **Open** a Pull Request

Please ensure your PR:

- โœ… Passes all existing tests
- โœ… Includes tests for new functionality
- โœ… Follows the existing code style
- โœ… Updates documentation as needed

---

## ๐Ÿ†˜ Support

| Resource | Link |
| :--------------- | :----------------------------------------------------------------------------- |
| ๐Ÿ› Bug Reports | [GitHub Issues](https://github.com/xshopai/inventory-service/issues) |
| ๐Ÿ“– Documentation | [docs/](docs/) |
| ๐Ÿ“‹ API Reference | [docs/PRD.md](docs/PRD.md) |
| ๐Ÿ’ฌ Discussions | [GitHub Discussions](https://github.com/xshopai/inventory-service/discussions) |

---

## ๐Ÿ“„ License

This project is part of the **xshopai** e-commerce platform.
ยฉ 2026 xshopai. All rights reserved.

---

**[โฌ† Back to Top](#-inventory-service)**

Made with โค๏ธ by the xshopai team