|
| 1 | +# 🎯 Quick Setup Guide - urBackend Collections |
| 2 | + |
| 3 | +## Step-by-Step Collection Setup |
| 4 | + |
| 5 | +### ⚠️ STEP 0: Enable Authentication (MUST DO FIRST!) |
| 6 | + |
| 7 | +1. Login to urBackend Dashboard: https://urbackend.bitbros.in |
| 8 | +2. Go to your project |
| 9 | +3. Navigate to **Settings** or **Authentication** section |
| 10 | +4. **Enable Authentication** - Click the toggle/button |
| 11 | +5. This will automatically create a `users` collection with these fields: |
| 12 | + - ✅ `email` (String, Required, Unique) |
| 13 | + - ✅ `password` (String, Required, Auto-hashed with bcrypt) |
| 14 | + |
| 15 | +--- |
| 16 | + |
| 17 | +### 📝 STEP 1: Update `users` Collection |
| 18 | + |
| 19 | +After authentication is enabled, go to the `users` collection schema and **ADD** these fields: |
| 20 | + |
| 21 | +``` |
| 22 | +Field Name | Type | Required | Unique | Default |
| 23 | +------------------|---------|----------|--------|---------- |
| 24 | +username | String | Yes | Yes | - |
| 25 | +displayName | String | No | No | - |
| 26 | +bio | String | No | No | - |
| 27 | +avatar | String | No | No | - |
| 28 | +banner | String | No | No | - |
| 29 | +verified | Boolean | No | No | false |
| 30 | +location | String | No | No | - |
| 31 | +website | String | No | No | - |
| 32 | +followersCount | Number | No | No | 0 |
| 33 | +followingCount | Number | No | No | 0 |
| 34 | +``` |
| 35 | + |
| 36 | +**Complete `users` schema will have:** |
| 37 | +- email ✅ (auto-created) |
| 38 | +- password ✅ (auto-created) |
| 39 | +- username + 9 additional fields (you add these) |
| 40 | + |
| 41 | +--- |
| 42 | + |
| 43 | +### 📝 STEP 2: Create `posts` Collection |
| 44 | + |
| 45 | +Create a new collection named **`posts`** with these fields: |
| 46 | + |
| 47 | +``` |
| 48 | +Field Name | Type | Required | Default |
| 49 | +--------------------|---------|----------|---------- |
| 50 | +authorId | String | Yes | - |
| 51 | +authorUsername | String | Yes | - |
| 52 | +authorDisplayName | String | No | - |
| 53 | +authorAvatar | String | No | - |
| 54 | +authorVerified | Boolean | No | false |
| 55 | +content | String | Yes | - |
| 56 | +images | Array | No | [] |
| 57 | +likesCount | Number | No | 0 |
| 58 | +commentsCount | Number | No | 0 |
| 59 | +retweetsCount | Number | No | 0 |
| 60 | +createdAt | Date | No | Date.now |
| 61 | +``` |
| 62 | + |
| 63 | +--- |
| 64 | + |
| 65 | +### 📝 STEP 3: Create `comments` Collection |
| 66 | + |
| 67 | +Create a new collection named **`comments`** with these fields: |
| 68 | + |
| 69 | +``` |
| 70 | +Field Name | Type | Required | Default |
| 71 | +--------------------|---------|----------|---------- |
| 72 | +postId | String | Yes | - |
| 73 | +authorId | String | Yes | - |
| 74 | +authorUsername | String | Yes | - |
| 75 | +authorDisplayName | String | No | - |
| 76 | +authorAvatar | String | No | - |
| 77 | +content | String | Yes | - |
| 78 | +likesCount | Number | No | 0 |
| 79 | +createdAt | Date | No | Date.now |
| 80 | +``` |
| 81 | + |
| 82 | +--- |
| 83 | + |
| 84 | +### 📝 STEP 4: Create `likes` Collection |
| 85 | + |
| 86 | +Create a new collection named **`likes`** with these fields: |
| 87 | + |
| 88 | +``` |
| 89 | +Field Name | Type | Required | Index |
| 90 | +--------------|---------|----------|------- |
| 91 | +userId | String | Yes | Yes |
| 92 | +targetId | String | Yes | Yes |
| 93 | +targetType | String | Yes | No (enum: "post" or "comment") |
| 94 | +createdAt | Date | No | Date.now |
| 95 | +``` |
| 96 | + |
| 97 | +**Important:** Create a compound unique index on `userId + targetId` to prevent duplicate likes. |
| 98 | + |
| 99 | +--- |
| 100 | + |
| 101 | +### 📝 STEP 5: Create `follows` Collection |
| 102 | + |
| 103 | +Create a new collection named **`follows`** with these fields: |
| 104 | + |
| 105 | +``` |
| 106 | +Field Name | Type | Required | Index |
| 107 | +--------------|---------|----------|------- |
| 108 | +followerId | String | Yes | Yes |
| 109 | +followingId | String | Yes | Yes |
| 110 | +createdAt | Date | No | Date.now |
| 111 | +``` |
| 112 | + |
| 113 | +**Important:** Create a compound unique index on `followerId + followingId` to prevent duplicate follows. |
| 114 | + |
| 115 | +--- |
| 116 | + |
| 117 | +## ✅ Verification Checklist |
| 118 | + |
| 119 | +After completing all steps, verify: |
| 120 | + |
| 121 | +- [ ] Authentication is enabled in urBackend dashboard |
| 122 | +- [ ] `users` collection exists with `email` and `password` fields |
| 123 | +- [ ] `users` collection has all 11 additional fields added |
| 124 | +- [ ] `posts` collection created with 11 fields |
| 125 | +- [ ] `comments` collection created with 8 fields |
| 126 | +- [ ] `likes` collection created with 4 fields |
| 127 | +- [ ] `follows` collection created with 3 fields |
| 128 | +- [ ] Total: 5 collections in your urBackend project |
| 129 | + |
| 130 | +--- |
| 131 | + |
| 132 | +## 🔑 Get Your API Keys |
| 133 | + |
| 134 | +1. Go to urBackend Dashboard → Project Settings |
| 135 | +2. Copy your **Public Key** (`pk_live_...`) |
| 136 | +3. Copy your **Secret Key** (`sk_live_...`) |
| 137 | +4. Paste them in your `.env` files (see main README.md) |
| 138 | + |
| 139 | +--- |
| 140 | + |
| 141 | +## 🚀 Ready to Go! |
| 142 | + |
| 143 | +Once all collections are created and API keys are configured, you can run the app: |
| 144 | + |
| 145 | +```bash |
| 146 | +# Terminal 1 |
| 147 | +cd server |
| 148 | +npm start |
| 149 | + |
| 150 | +# Terminal 2 |
| 151 | +cd client |
| 152 | +npm run dev |
| 153 | +``` |
| 154 | + |
| 155 | +Open http://localhost:5173 and create your first account! 🎉 |
| 156 | + |
| 157 | +--- |
| 158 | + |
| 159 | +## ❓ Common Issues |
| 160 | + |
| 161 | +**Q: I don't see "Enable Authentication" option?** |
| 162 | +A: Look for "Auth Settings", "User Management", or check the main settings page. It might be under a different menu. |
| 163 | + |
| 164 | +**Q: Can I use different field names?** |
| 165 | +A: No, the app code expects these exact field names. Changing them will break functionality. |
| 166 | + |
| 167 | +**Q: What if I already created `users` collection manually?** |
| 168 | +A: Delete it and enable Authentication to let urBackend create it properly with password hashing. |
| 169 | + |
| 170 | +**Q: Do I need to add indexes manually?** |
| 171 | +A: urBackend automatically indexes `_id`. For better performance, you can add indexes on frequently queried fields like `authorId`, `userId`, etc. |
| 172 | + |
| 173 | +--- |
| 174 | + |
| 175 | +**Need help?** Check the full [SETUP.md](./SETUP.md) or join the Discord! |
0 commit comments