0
votes

What is the recommended architecture for user groups in a react-native app? I created a simple app with https://github.com/mcnamee/react-native-starter-kit which uses firebase and would like to modify it to fit my needs but am unsure of how to achieve this.

I want to allow users to be part of many groups if they choose (similar to group messaging where a user can choose their friends to be part of a group). So if there are three users user1, user2, and user3 there could potentially be group1 which contains user1/user2 and group2 which contains user2/user3.

In a relational DB setup, I could just use foreign keys to express these relationships but in NoSQL DBs, like firebase, the structure appears to be much different.

Is there a recommended approach? Are there example apps that implement similar functionality somewhere?

I am totally new to mobile app development and won't want to go down the wrong path right from the get-go, so any tips are much appreciated.

2

2 Answers

1
votes

I did something like this.

there will be a users table in firebase which will have all user data. Every user signed up will be added here.

Each group will be added to groups object, with a members array that will point to user id in user table

groups:{
0: {name:'Group1',members:[3,1,8], image:''},
1: {name:'Group1',members:[3,1,8], image:''},
}

users: {
    1: {name:'user1', avatar:''},
    2: {name:'user2', avatar:''},
}

And you are right, choose the right db structure when u design the firebase/fire-store. The example i provided is just a pseudo code which u need to apply in your project.

I can help with Github links that make use of firebase. just run it once an d u can see the data structure they use to implement things better.

https://github.com/FirebaseExtended/firechat

https://github.com/chat-sdk/chat-sdk-android

https://github.com/AleBarreto/FirebaseAndroidChat

0
votes

You can mimic a relational DB's design by normalizing your frontend data and using normalized-reducer to manage it. It's a higher-order-reducer that takes a schema describing the relationships, and returns a reducer, action, and selectors that write/read according to the relationships. Normalized-reducer is usable with React's useReducer and Redux, and it integrates easily with Normalizr and Redux Toolkit.