KimTay Pet Supplies is a rapidly growing retailer that offers everything from pet food and toys to grooming accessories. To keep up with expanding inventory, multiple sales channels, and a loyal customer base, the company invested in a robust Database Management System (DBMS) that provides realtime visibility into stock levels, sales performance, supplier contracts, and customer preferences. The DBMS is built on PostgreSQL, chosen for its reliability, strong ACID compliance, and rich extension ecosystem. All application logic is accessed through a RESTful API layer built with Node.js and Express, while a lightweight frontend dashboard powered by React visualises the data for managers and store staff. The architecture follows a threetier pattern: The diagram below summarises the flow: The core data model revolves around five primary entities. Relationships are captured in foreign keys and junction tables. Tracks quantity by warehouse and batch. Customer orders are stored in Each supplier may provide many products; a manytomany relationship is managed through Basic demographic data plus loyalty tier. All tables inherit from a common audit schema that adds Below are representative SQL snippets that power daily operations. This query flags items with low inventory for automatic reorder. All queries are executed against the read replica to keep the primary node free for transactional workloads. KimTay plans to extend the DBMS in several directions: These initiatives will keep KimTay Pet Supplies competitive while preserving data integrity and performance.KimTay Pet Supplies Database Management System
1. Overview
2. System Architecture
2.1. Presentation Layer
2.2. Application Layer
2.3. Data Layer
[Browser] HTTPS [Load Balancer] [Node.js API] [PostgreSQL Master] [Read Replica]
3. Key Entities and Relationships
3.1. Products
Column Type Description product_id SERIAL PK Unique identifier sku VARCHAR(20) Stock keeping unit name VARCHAR(100) Product name category_id INT FK Links to Categories price NUMERIC(10,2) Retail price cost NUMERIC(10,2) Purchase cost created_at TIMESTAMP Record creation 3.2. Inventory
CREATE TABLE inventory ( inventory_id SERIAL PRIMARY KEY, product_id INT REFERENCES products(product_id), warehouse_id INT REFERENCES warehouses(warehouse_id), batch_number VARCHAR(30), quantity INT CHECK (quantity >= 0), expiry_date DATE, last_updated TIMESTAMP DEFAULT now());3.3. Orders
orders with a onetomany link to order_items.CREATE TABLE orders ( order_id SERIAL PRIMARY KEY, customer_id INT REFERENCES customers(customer_id), order_date TIMESTAMP DEFAULT now(), status VARCHAR(20) CHECK (status IN ('Pending','Processing','Shipped','Cancelled')), total_amount NUMERIC(12,2));3.4. Suppliers
supplier_products.3.5. Customers
created_by, updated_by, and deleted_at columns, enabling soft deletes and change tracking.4. Common Queries
4.1. Realtime Stock Availability
SELECT p.sku, p.name, SUM(i.quantity) AS total_stockFROM products pJOIN inventory i ON i.product_id = p.product_idGROUP BY p.sku, p.nameHAVING SUM(i.quantity) < 10ORDER BY total_stock ASC;4.2. TopSelling Products (Last 30 Days)
SELECT p.name, SUM(oi.quantity) AS units_sold, SUM(oi.quantity * p.price) AS revenueFROM order_items oiJOIN orders o ON o.order_id = oi.order_idJOIN products p ON p.product_id = oi.product_idWHERE o.order_date >= now() - INTERVAL '30 days'GROUP BY p.nameORDER BY revenue DESCLIMIT 10;4.3. Supplier Performance
SELECT s.name, COUNT(sp.product_id) AS products_supplied, AVG(DATE_PART('day', i.received_at - i.ordered_at)) AS avg_delivery_daysFROM suppliers sJOIN supplier_products sp ON sp.supplier_id = s.supplier_idJOIN inventory i ON i.product_id = sp.product_idGROUP BY s.nameORDER BY avg_delivery_days;4.4. Customer Lifetime Value (CLV)
SELECT c.customer_id, c.first_name, c.last_name, SUM(o.total_amount) AS lifetime_spend, COUNT(o.order_id) AS order_countFROM customers cJOIN orders o ON o.customer_id = c.customer_idWHERE o.status <> 'Cancelled'GROUP BY c.customer_id, c.first_name, c.last_nameHAVING SUM(o.total_amount) > 500ORDER BY lifetime_spend DESC;5. Security and Backup Strategy
6. Future Enhancements
pgml extension to predict demand spikes and recommend optimal reorder quantities.pggraph to model complex suppliercustomer relationships and detect indirect dependencies.
