How ridwantaufk/flash-sale-inventory works
Flash Sale Inventory Reservation lets a user inspect stock, place a temporary hold, and confirm it before expiry; otherwise expired units return to availability. The React dashboard tracks local reservation state and countdowns while the Go API owns validation and reservation operations backed by PostgreSQL. A background reaper sweeps expired holds. The principal backend wiring and frontend calls are excerpted; the README documents the database schema/seed and API capabilities, but migration internals were not sampled.
Main entry points: main.go Server lifecycle · App.tsx Dashboard state · ReservationList.tsx Reservation list · server.go HTTP router
Components 21
Stock dashboard
- Dashboard state
frontend/src/App.tsx - Stock panel
frontend/src/components/StockPanel.tsx - Reserve form
frontend/src/components/ReserveForm.tsx - Reservation list
frontend/src/components/ReservationList.tsx - Error display
frontend/src/components/Alert.tsx - Countdown clock
frontend/src/hooks/useNow.ts - Browser reservation cache
frontend/src/storage.ts - Inventory API client
frontend/src/api/client.ts
Inventory API
- HTTP router
backend/internal/server/server.go - Inventory handlers
backend/internal/inventory/handler.go - HTTP support
backend/internal/transport/httpx/httpx.go
Reservation domain
- Reservation service
backend/internal/inventory/service.go - Inventory model
backend/internal/inventory/inventory.go - Expiry reaper
backend/internal/inventory/reaper.go
Runtime infrastructure
- Server lifecycle
backend/cmd/server/main.go - Environment config
backend/internal/config/config.go - Database pool
backend/internal/platform/pg/pg.go
Persistence
- Inventory repository
backend/internal/inventory/repository.go - PostgreSQL
db/migrations
Other components
- Dashboard user
- Browser fetch
Connections 30
- Dashboard user → Dashboard state: uses
README.md - Dashboard state → Stock panel: renders
frontend/src/App.tsx - Dashboard state → Reserve form: renders
frontend/src/App.tsx - Dashboard state → Reservation list: renders
frontend/src/App.tsx - Dashboard state → Browser reservation cache: loads and saves
frontend/src/App.tsx - Dashboard state → Countdown clock: updates time
frontend/src/App.tsx - Stock panel → Inventory API client: fetches stock
frontend/src/components/StockPanel.tsx - Reserve form → Inventory API client: requests hold
frontend/src/components/ReserveForm.tsx - Reservation list → Inventory API client: confirms hold
frontend/src/components/ReservationList.tsx - Stock panel → Error display: renders errors
frontend/src/components/StockPanel.tsx - Reserve form → Error display: renders errors
frontend/src/components/ReserveForm.tsx - Reservation list → Error display: renders errors
frontend/src/components/ReservationList.tsx - Reservation list → Countdown clock: computes countdown
frontend/src/components/ReservationList.tsx - Inventory API client → Browser fetch: fetches
frontend/src/api/client.ts - Browser fetch → HTTP router: sends API requests
README.md - Server lifecycle → Environment config: loads settings
backend/cmd/server/main.go - Server lifecycle → Database pool: opens pool
backend/cmd/server/main.go - Server lifecycle → Inventory repository: constructs
backend/cmd/server/main.go - Server lifecycle → Reservation service: constructs
backend/cmd/server/main.go - Server lifecycle → Expiry reaper: runs
backend/cmd/server/main.go - Server lifecycle → HTTP router: serves
backend/cmd/server/main.go - Server lifecycle → Inventory handlers: constructs
backend/cmd/server/main.go - Server lifecycle → HTTP support: configures readiness
backend/cmd/server/main.go - HTTP router → Inventory handlers: routes inventory
- Inventory handlers → Reservation service: delegates operations
- Reservation service → Inventory repository: executes operations
- Inventory repository → PostgreSQL: reads and writes
- Expiry reaper → Reservation service: sweeps expired holds
- HTTP router → HTTP support: uses support
- Database pool → PostgreSQL: connects