Skip to content

RRimeKS/InventoryFlow

Repository files navigation

InventoryFlow

Microservices tabanlı envanter ve stok yönetim sistemi. .NET 9 ile geliştirilmiş, FIFO (First In, First Out) stok takibi yapan bir çözüm.

Mimari Genel Bakış

                            ┌──────────────────┐
                            │     GATEWAY      │
                            │   (YARP Proxy)   │
                            └────────┬─────────┘
                                     │
           ┌─────────────────────────┼─────────────────────────┐
           │                         │                         │
           ▼                         ▼                         ▼
┌──────────────────┐     ┌──────────────────┐     ┌──────────────────┐
│   PROCUREMENT    │     │    INVENTORY     │     │      SALES       │
│   Port: 7034     │     │   Port: 7198     │     │    Port: 7029    │
│                  │     │                  │     │                  │
│  • Tedarikçiler  │     │  • Stok Lotları  │     │  • Satış Sipariş │
│  • Ürünler       │     │  • FIFO Takip    │     │                  │
│  • Mal Kabul     │     │                  │     │                  │
└────────┬─────────┘     └────────▲─────────┘     └────────┬─────────┘
         │                        │                        │
         │    RabbitMQ            │         RabbitMQ       │
         └──────────────────────▶ │ ◀───────────────────────┘
              StockArrivedEvent        OrderCreatedEvent

Servisler

Procurement Service (Satın Alma)

Tedarikçi ve ürün yönetimi, mal kabul işlemleri.

Entities:

  • Supplier - Tedarikçi bilgileri (ad, vergi no, email)
  • Product - Ürün bilgileri (ad, SKU, barkod)
  • InboundOrder - Mal kabul siparişi (beyanname no, tarih, kalemler)

API Endpoints:

  • POST /api/supplier - Yeni tedarikçi oluştur
  • GET /api/product - Tüm ürünleri listele
  • POST /api/product - Yeni ürün oluştur
  • POST /api/orders - Mal kabul siparişi oluştur (stok girişi tetikler)

Inventory Service (Stok)

FIFO bazlı stok lot takibi. Sadece event consumer olarak çalışır.

Entity:

  • InventoryLot - Stok partisi (ürün ID, beyanname no, maliyet, miktar)

Consumers:

  • StockArrivedConsumer - Mal kabul eventi geldiğinde stok lotu oluşturur
  • OrderCreatedConsumer - Satış eventi geldiğinde FIFO ile stok düşer

Sales Service (Satış)

Satış sipariş yönetimi.

Entities:

  • SalesOrder - Satış siparişi (müşteri adı, tarih)
  • SalesOrderItem - Sipariş kalemi (ürün, miktar, fiyat)

API Endpoint:

  • POST /api/sales - Yeni satış oluştur (stok düşümü tetikler)

Gateway

YARP tabanlı reverse proxy. Tüm servisleri tek endpoint üzerinden sunar.

Kurulum

Gereksinimler

  • .NET 9 SDK (Gateway için .NET 10)
  • Docker & Docker Compose
  • MySQL 8.0
  • RabbitMQ 3.x

Altyapıyı Başlatma

# MySQL, RabbitMQ ve phpMyAdmin'i başlat
docker-compose up -d

Erişim Bilgileri:

Servis URL Kullanıcı/Şifre
MySQL localhost:3306 root / e1e2e3e4
RabbitMQ localhost:15672 guest / guest
phpMyAdmin localhost:8080 root / root

Servisleri Çalıştırma

Her servisi ayrı terminal penceresinde çalıştırın:

# Procurement Service
dotnet run --project src/Services/Procurement/InventoryFlow.Procurement.Api.csproj

# Inventory Service
dotnet run --project src/Services/Inventory/InventoryFlow.Inventory.Api.csproj

# Sales Service
dotnet run --project src/Services/Sales/InventoryFlow.Sales.Api.csproj

# Gateway
dotnet run --project src/Gateways/InventoryFlow.Gateway/InventoryFlow.Gateway.csproj

İş Akışı Örneği

1. Ürün ve Tedarikçi Oluştur

# Tedarikçi oluştur
curl -X POST https://localhost:7034/api/supplier \
  -H "Content-Type: application/json" \
  -d '{"name": "ABC Tedarik", "taxNumber": "1234567890", "contactEmail": "info@abc.com"}'

# Ürün oluştur
curl -X POST https://localhost:7034/api/product \
  -H "Content-Type: application/json" \
  -d '{"name": "Laptop", "sku": "LPT-001", "barcode": "8690000000001", "description": "Gaming Laptop"}'

2. Mal Kabul (Stok Girişi)

curl -X POST https://localhost:7034/api/orders \
  -H "Content-Type: application/json" \
  -d '{
    "supplierId": "<supplier-guid>",
    "declarationNumber": "TR-2024-001",
    "declarationDate": "2024-01-15",
    "items": [
      {"productId": "<product-guid>", "quantity": 100, "unitCost": 15000}
    ]
  }'

Bu işlem:

  1. InboundOrder kaydı oluşturur
  2. IStockArrivedEvent publish eder
  3. Inventory servisi eventi alır ve InventoryLot oluşturur

3. Satış (Stok Çıkışı)

curl -X POST https://localhost:7029/api/sales \
  -H "Content-Type: application/json" \
  -d '{
    "customerName": "Mehmet Yılmaz",
    "items": [
      {"productId": "<product-guid>", "quantity": 5, "unitPrice": 20000}
    ]
  }'

Bu işlem:

  1. SalesOrder kaydı oluşturur
  2. IOrderCreatedEvent publish eder
  3. Inventory servisi FIFO ile stok düşer (en eski lottan başlar)

Veritabanları

Her servis kendi veritabanını kullanır (Database per Service pattern):

Servis Veritabanı
Procurement inventory_flow
Inventory inventory_stock
Sales inventory_sales

FIFO Stok Yönetimi

Inventory servisi stokları "lot" bazında takip eder. Her lot:

  • Hangi beyanname ile geldiğini (DeclarationNumber)
  • Maliyet fiyatını (CostPrice)
  • Orijinal ve kalan miktarı (OriginalQuantity, RemainingQuantity)

Satış olduğunda:

  1. İlgili ürünün lotları CreatedDate'e göre sıralanır (eskiden yeniye)
  2. En eski lottan stok düşülür
  3. Lot tükenirse sonraki lota geçilir

Proje Yapısı

InventoryFlow/
├── src/
│   ├── Gateways/
│   │   └── InventoryFlow.Gateway/        # YARP Reverse Proxy
│   ├── Services/
│   │   ├── Procurement/                   # Satın alma servisi
│   │   │   ├── Controllers/
│   │   │   ├── Data/
│   │   │   ├── Entities/
│   │   │   ├── Features/                  # CQRS Commands & Queries
│   │   │   │   ├── Orders/
│   │   │   │   ├── Products/
│   │   │   │   └── Suppliers/
│   │   │   └── Repositories/
│   │   ├── Inventory/                     # Stok servisi
│   │   │   ├── Consumers/                 # RabbitMQ event handlers
│   │   │   ├── Data/
│   │   │   └── Entities/
│   │   └── Sales/                         # Satış servisi
│   │       ├── Controllers/
│   │       ├── Data/
│   │       ├── Entities/
│   │       └── Features/
│   └── Shared/
│       └── InventoryFlow.Shared/          # Paylaşılan event ve DTO'lar
├── docker-compose.yml
└── InventoryFlow.sln

Teknoloji Stack

Kategori Teknoloji
Framework .NET 9 / .NET 10
ORM Entity Framework Core 9
Database MySQL 8.0 (Pomelo Provider)
Message Broker RabbitMQ
Messaging Library MassTransit
CQRS MediatR
API Gateway YARP
API Docs Swagger (Swashbuckle)

RabbitMQ Kuyrukları

Kuyruk Publisher Consumer Event
stock-arrived-queue Procurement Inventory IStockArrivedEvent
stock-sales-queue Sales Inventory IOrderCreatedEvent

Frontend (React Dashboard)

Modern, responsive admin dashboard. src/client klasoründe bulunur.

Teknolojiler

Kategori Teknoloji
Build Tool Vite
Framework React 18 + TypeScript
State Management Redux Toolkit + RTK Query
Styling Tailwind CSS
UI Components shadcn/ui + Radix UI
Charts Recharts
Icons Lucide React
Routing React Router v6

Özellikler

  • Dashboard: Gerçek zamanlı istatistikler, satış grafikleri, düşük stok uyarıları
  • Ürünler: CRUD işlemleri, arama, silme onayı
  • Tedarikçiler: CRUD işlemleri, sipariş sayısı takibi
  • Mal Kabul: Çok kalemli sipariş oluşturma, tedarikçi seçimi
  • Satışlar: Stok kontrollü satış, müşteri bilgileri
  • Envanter: Stok seviyeleri, FIFO lot takibi
  • Tema: Light/Dark mode desteği
  • Bildirimler: Toast mesajları, silme onay dialogları

Frontend Kurulumu

cd src/client

# Bağımlılıkları yükle
npm install

# Geliştirme sunucusunu başlat (Port 3000)
npm run dev

# Production build
npm run build

Frontend Yapısı

src/client/
├── src/
│   ├── app/
│   │   ├── store.ts          # Redux store
│   │   ├── baseApi.ts        # RTK Query config
│   │   └── hooks.ts          # Typed hooks
│   ├── components/
│   │   ├── ui/               # shadcn components
│   │   └── layout/           # Sidebar, Header, Layout
│   ├── features/
│   │   ├── auth/             # Login, Register
│   │   ├── products/         # Products API
│   │   ├── suppliers/        # Suppliers API
│   │   ├── orders/           # Orders API
│   │   ├── sales/            # Sales API
│   │   ├── inventory/        # Inventory API
│   │   └── dashboard/        # Dashboard API
│   ├── pages/                # Route pages
│   ├── hooks/                # Custom hooks
│   ├── types/                # TypeScript types
│   └── lib/                  # Utilities
├── vite.config.ts
└── package.json

API Proxy Yapılandırması

Frontend, Gateway üzerinden backend servislerine erişir:

// vite.config.ts
server: {
  port: 3000,
  proxy: {
    '/api': {
      target: 'https://localhost:5000',
      changeOrigin: true,
      secure: false,
    },
  },
}

Gateway Üzerinden Routing

Frontend Path Gateway Route Backend Service
/api/auth/* auth-cluster Auth (7100)
/api/products/* procurement-cluster Procurement (7034)
/api/suppliers/* procurement-cluster Procurement (7034)
/api/orders/* procurement-cluster Procurement (7034)
/api/sales/* sales-cluster Sales (7029)
/api/inventory/* inventory-cluster Inventory (7198)

Tüm Sistemi Başlatma

1. Altyapı (Docker)

docker-compose up -d

2. Backend Servisleri (Ayrı terminallerde)

# Auth Service (Port 7100)
dotnet run --project src/Services/Auth/InventoryFlow.Auth.Api

# Procurement Service (Port 7034)
dotnet run --project src/Services/Procurement

# Sales Service (Port 7029)
dotnet run --project src/Services/Sales

# Inventory Service (Port 7198)
dotnet run --project src/Services/Inventory

# Gateway (Port 5000)
dotnet run --project src/Gateways/InventoryFlow.Gateway

3. Frontend

cd src/client && npm run dev

Tarayıcıda http://localhost:3000 adresini açın.


Lisans

MIT License

About

Full-stack microservices inventory management system with .NET 9, React, YARP Gateway, RabbitMQ/MassTransit, and MySQL. Implements CQRS, Vertical Slice Architecture, JWT authentication, and event-driven communication.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors