How turynx/flash-sale-inventory-engine works
Flash Sale Inventory Engine is a NestJS backend for user authentication, product catalog management, inventory reservation, and Stripe checkout. The main flow is: users authenticate, browse products, reserve stock, receive a checkout URL, and complete an order through a verified Stripe webhook; reservation expiry is handled in the background. PostgreSQL-backed repositories and a Redis/BullMQ reservation subsystem support these capabilities. The graph follows documented routes and module wiring; some use-case-to-storage or payment calls are not visible in the sampled excerpts, so those links are omitted or marked unverified.
Main entry points: order.controller.ts Order API · product.controller.ts Product API · app.module.ts Application setup · auth.controller.ts Auth API
Components 22
API and identity
- Application setup
src/app.module.ts - Auth API
src/auth/infrastructure/controllers/auth.controller.ts - Auth use cases
src/auth/application/use-cases - Auth repository
src/auth/infrastructure/repository/db.repository.ts - JWT guard
src/auth/infrastructure/guards/jwt-auth.guard.ts
Product catalog
- Product API
src/product/infrastructure/controllers/product.controller.ts - Product use cases
src/product/application/use-cases - Product repository
src/product/infrastructure/repository/db.repository.ts
Orders and inventory
- Order API
src/order/infrastructure/controllers/order.controller.ts - Reservation use case
src/order/application/use-cases/reserve.use-case.ts - Checkout use case
src/order/application/use-cases/checkout-order.use-case.ts - Checkout URL use case
src/order/application/use-cases/generate-stripe-url.use-case.ts - Order repository
src/order/infrastructure/repository/db.repository.ts - Redis inventory adapter
src/order/infrastructure/services/redis-inventory.adapter.ts - Expiry worker
src/order/infrastructure/worker/reservation-expired.worker.ts - Ledger use case
src/inventory-ledger/application/use-cases/create.inventory-ledger.use-case.ts - Ledger repository
src/inventory-ledger/infrastructure/repositories/inventory-ledger.repository.ts
Persistence and integrations
- PostgreSQL
- Redis and queue
- Stripe
- Stripe service
src/payment/payment.service.ts
Other components
- Client
Connections 31
- Client → Auth API: registers or logs in
README.md - Auth API → Auth use cases: executes
src/auth/infrastructure/controllers/auth.controller.ts - Application setup → Auth API: loads module
src/app.module.ts - Application setup → Product API: loads module
src/app.module.ts - Application setup → Order API: loads module
src/app.module.ts - Application setup → Ledger use case: loads module
src/app.module.ts - Client → Product API: browses catalog
README.md - Product API → Product use cases: executes
src/product/infrastructure/controllers/product.controller.ts - Product API → JWT guard: guards creation
src/product/infrastructure/controllers/product.controller.ts - Client → Order API: places order
README.md - Order API → JWT guard: guards routes
src/order/infrastructure/controllers/order.controller.ts - Order API → Reservation use case: executes
src/order/infrastructure/controllers/order.controller.ts - Order API → Checkout URL use case: executes
src/order/infrastructure/controllers/order.controller.ts - Order API → Checkout use case: executes webhook
src/order/infrastructure/controllers/order.controller.ts - Order API → Stripe: verifies webhook
src/order/infrastructure/controllers/order.controller.ts - Order API → Order repository: configures provider
src/order/order.module.ts - Order API → Redis inventory adapter: configures provider
src/order/order.module.ts - Order API → Expiry worker: registers worker
src/order/order.module.ts - Order API → Stripe service: configures provider
- Order API → Ledger repository: configures provider
- Product API → Product repository: configures provider
src/product/product.module.ts - Auth API → Auth repository: configures provider
src/auth/auth.module.ts - Ledger use case → Ledger repository: configures provider
src/inventory-ledger/inventory-ledger.module.ts - Product repository → PostgreSQL: queries
src/product/infrastructure/repository/db.repository.ts - Order repository → PostgreSQL: queries
src/order/infrastructure/repository/db.repository.ts - Ledger repository → PostgreSQL: queries
src/inventory-ledger/infrastructure/repositories/inventory-ledger.repository.ts - Auth repository → PostgreSQL: persists users
- Redis inventory adapter → Redis and queue: uses inventory queue
- Expiry worker → Redis and queue: processes delayed jobs
- Stripe service → Stripe: creates checkout session
src/payment/payment.service.ts - Checkout URL use case → Stripe service: requests checkout