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.
- Host: GitHub
- URL: https://github.com/xshopai/inventory-service
- Owner: xshopai
- License: mit
- Created: 2025-08-27T21:51:05.000Z (10 months ago)
- Default Branch: main
- Last Pushed: 2026-02-27T14:52:32.000Z (4 months ago)
- Last Synced: 2026-02-27T18:44:59.892Z (4 months ago)
- Topics: flask, microservice, mysql, python, xshopai
- Language: Python
- Homepage:
- Size: 567 KB
- Stars: 1
- Watchers: 0
- Forks: 0
- Open Issues: 8
-
Metadata Files:
- Readme: README.md
- License: LICENSE
- Security: .github/SECURITY.md
Awesome Lists containing this project
README
# ๐ฆ Inventory Service
**Enterprise-grade inventory management microservice for the xshopai e-commerce platform**
[](https://python.org)
[](https://flask.palletsprojects.com)
[](https://mysql.com)
[](https://dapr.io)
[](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