Approach for creating 2 purchasable entities one can contain other but both can be purchased individually also

I want 2 custom purchasable entities. Entity A and Entity B. Both can be purchased individually but individual Entity B can be purchased as a group in Entity A like a grouped product. How can I make a relation or grouped product? I need those 2 entities custom because there are other conditions and functionalities related to them.