E-Commerce App Firebase

Hello, I am trying to implement an out of stock feature in an e-commerce app. On the products details page, I would like to display the products Colors and Sizes. So say when a user chooses a color, I would like to only display the sizes for that color that is In Stock. How should I model my data in firebase? For Colors, Sizes, and InStock/Out of stock.

This is what I’d like to implement. Any ideas would be greatly appreciated. Thank you!

Just thinking about it (not an expert), I would have products include the color and size field along with onhand. Like I have 50 XL Blue shirts. I would have a function to update the qty on order, so that it reflects accurate stock.

I imagine that there could always be a collision where you and I place an order for 50 of that shirt at the same-ish time and someone loses.

Is that what you were thinking?

This is similar to what I was thinking, thank you for you contribution!