Skip to main content

System Design

Detailed system design and technical decisions.

Technology Stack​

Frontend​

TechnologyVersionPurpose
Next.js15.xReact framework
React19.xUI library
TypeScript5.xType safety
Tailwind CSS3.xStyling
Radix UILatestComponents
Zustand5.xState management
SWR2.xData fetching
Vitest3.xUnit testing
PlaywrightLatestE2E testing

Backend​

TechnologyVersionPurpose
Python3.11+Runtime
FastAPI0.115+API framework
SQLAlchemy2.xORM
Alembic1.xMigrations
Redis5.xCaching
Pydantic2.xValidation
pytest8.xTesting

Infrastructure​

ComponentTechnology
HostingVercel (Frontend), Railway (Backend)
DatabaseMySQL 8.0+
CacheRedis
CDNCloudflare
MonitoringSentry, OpenTelemetry

API Design​

RESTful Conventions​

GET    /api/v1/resources          # List
GET /api/v1/resources/{id} # Get one
POST /api/v1/resources # Create
PATCH /api/v1/resources/{id} # Update
DELETE /api/v1/resources/{id} # Delete

Pagination​

{
"data": [...],
"pagination": {
"page": 1,
"limit": 50,
"total": 234,
"total_pages": 5
}
}

Error Handling​

{
"error": {
"code": "VALIDATION_ERROR",
"message": "Invalid input",
"details": {
"field": "email",
"issue": "Invalid format"
}
}
}

Database Design​

Core Tables​

-- Users and authentication
users (id, email, password_hash, mfa_secret, ...)
user_sessions (id, user_id, token, expires_at, ...)

-- Business entities
entities (id, type, name, license_number, ...)
locations (id, entity_id, name, address, ...)

-- Products and inventory
products (id, entity_id, name, category, ...)
product_variants (id, product_id, sku, price, ...)
inventory (id, product_id, location_id, quantity, ...)

-- Orders
orders (id, retailer_id, wholesaler_id, status, ...)
order_items (id, order_id, product_id, quantity, ...)

Indexing Strategy​

  • Primary keys: UUID v4
  • Foreign keys: Indexed automatically
  • Search fields: Full-text indexes
  • Query filters: Composite indexes

Caching Strategy​

Cache Layers​

  1. Browser: Service worker, local storage
  2. CDN: Static assets, API responses
  3. Application: Redis for computed data
  4. Database: Query cache

Cache Invalidation​

  • Time-based expiry (TTL)
  • Event-based invalidation
  • Manual purge capabilities

Real-time Features​

WebSockets​

Used for:

  • Live inventory updates
  • Order status changes
  • Notifications

Polling Fallback​

When WebSocket unavailable:

  • 30-second polling interval
  • Exponential backoff on errors

Background Processing​

Job Types​

QueuePurpose
syncPOS synchronization
reportsReport generation
notificationsEmail/SMS delivery
complianceMETRC reporting

Retry Policy​

  • 3 attempts
  • Exponential backoff
  • Dead letter queue for failures