Q:

Isolate and manage collections CRUD done by signed in User - Firebase and Flutter

I'm new to Firebase and I just need clarity on how Firebase DB works overall.
Say I have different collections

users
customers
items
transactions

For each of the above, I created a model class in my flutter app, each having their accompanying fields. My app is set up with FirebaseAuth that handles signIn, signOut, SignUp...
How does Firebase know which customers and items belong to the currentUser()? Does it automatically store and match currentUser() uid to every CRUD data done by this user, or do I have to manually include the current user's uid as a field in each one of my model classes as in the example below?
Also, say those collections/models have some dependency on each other, for example, a user can have many customers and customers may have many items in their shopping list, and many Sales could belong to a customer. What's the best way to represent this in dart / flutter ?
For example, here's my Sales class
class Sales {
  String id;
  String totalAmount;
  Customer customerId;
  Items items;
  Timestamp createdAt;
}

Thanks.

A:

Firestore does not have any implicit knowledge of what Firebase Authentication user the data belongs to. If you need such information, you'll have to store it yourself by adding the relevant fields to the documents.
If you want to enforce these relationships, you'll want to store them in DocumentReference fields, and then use security rules to ensure your rules around the relationship are met.

