|
| 1 | +# CRM App - Quick Start Guide |
| 2 | + |
| 3 | +Get the CRM demo running in **3 minutes** with MSW (Mock Service Worker). |
| 4 | + |
| 5 | +## Prerequisites |
| 6 | + |
| 7 | +- Node.js 18+ and pnpm installed |
| 8 | +- Basic understanding of React |
| 9 | + |
| 10 | +## Installation |
| 11 | + |
| 12 | +### 1. Clone and Install |
| 13 | + |
| 14 | +```bash |
| 15 | +# From the repository root |
| 16 | +pnpm install |
| 17 | +``` |
| 18 | + |
| 19 | +### 2. Navigate to Example |
| 20 | + |
| 21 | +```bash |
| 22 | +cd examples/crm-app |
| 23 | +``` |
| 24 | + |
| 25 | +### 3. Start Development Server |
| 26 | + |
| 27 | +```bash |
| 28 | +pnpm dev |
| 29 | +``` |
| 30 | + |
| 31 | +The application will start at `http://localhost:5173`. |
| 32 | + |
| 33 | +## What You'll See |
| 34 | + |
| 35 | +### 🏠 Dashboard Page |
| 36 | +- Revenue: $125,000 |
| 37 | +- Active Leads: 45 |
| 38 | +- Open Deals: 12 |
| 39 | +- Recent contacts list |
| 40 | + |
| 41 | +### 👥 Contacts Page |
| 42 | +- Grid view of all contacts |
| 43 | +- Search and filter capabilities |
| 44 | +- Click any row to view details |
| 45 | +- Create new contacts with the form |
| 46 | + |
| 47 | +### 💼 Opportunities Page |
| 48 | +- Sales opportunities pipeline |
| 49 | +- Stage-based tracking |
| 50 | +- Amount and close date information |
| 51 | + |
| 52 | +## How It Works |
| 53 | + |
| 54 | +### MSW Service Worker |
| 55 | + |
| 56 | +When you run `pnpm dev`, the app automatically: |
| 57 | + |
| 58 | +1. Starts the MSW service worker in the browser |
| 59 | +2. Loads the ObjectStack Runtime with in-memory database |
| 60 | +3. Seeds initial data (3 contacts, 3 opportunities) |
| 61 | +4. Intercepts all `/api/v1/*` requests |
| 62 | +5. Handles CRUD operations in memory |
| 63 | + |
| 64 | +**No backend server needed!** Everything runs in your browser. |
| 65 | + |
| 66 | +### Browser Console Logs |
| 67 | + |
| 68 | +Open DevTools Console to see: |
| 69 | + |
| 70 | +``` |
| 71 | +🛑 Bootstrapping Mock Server... |
| 72 | +[MSW] Starting ObjectStack Runtime (Browser Mode)... |
| 73 | +[MSW] Loaded Config: Found 2 |
| 74 | +[MSW] Objects in Config: contact, opportunity, account |
| 75 | +[Kernel] Bootstrapping... |
| 76 | +[Kernel] Bootstrap Complete |
| 77 | +[MockServer] Initializing mock data... |
| 78 | +🔌 Connecting Clients... |
| 79 | +🚀 Rendering App... |
| 80 | +``` |
| 81 | + |
| 82 | +## Making Changes |
| 83 | + |
| 84 | +### Add a New Contact |
| 85 | + |
| 86 | +1. Navigate to `/contacts` |
| 87 | +2. Scroll to "Object Form (Create Contact)" section |
| 88 | +3. Fill in the form: |
| 89 | + - Name: "John Doe" |
| 90 | + - Email: "john@example.com" |
| 91 | + - Phone: "555-1234" |
| 92 | + - Company: "Acme Corp" |
| 93 | +4. Click "Create" |
| 94 | + |
| 95 | +The contact will be added to the in-memory database and appear in the grid immediately. |
| 96 | + |
| 97 | +### Edit Contact Data |
| 98 | + |
| 99 | +Contact data is defined in `examples/crm/objectstack.config.ts`: |
| 100 | + |
| 101 | +```typescript |
| 102 | +data: [ |
| 103 | + { |
| 104 | + object: 'contact', |
| 105 | + mode: 'upsert', |
| 106 | + records: [ |
| 107 | + { |
| 108 | + _id: "1", |
| 109 | + name: "Alice Johnson", |
| 110 | + email: "alice@example.com", |
| 111 | + // ... add more fields |
| 112 | + } |
| 113 | + ] |
| 114 | + } |
| 115 | +] |
| 116 | +``` |
| 117 | + |
| 118 | +After editing, refresh the browser to see changes. |
| 119 | + |
| 120 | +### Customize the Schema |
| 121 | + |
| 122 | +Object definitions are in `examples/crm/src/objects/`: |
| 123 | + |
| 124 | +- `contact.object.ts` - Contact fields and validation |
| 125 | +- `opportunity.object.ts` - Opportunity fields |
| 126 | +- `account.object.ts` - Account/company fields |
| 127 | + |
| 128 | +Example: Add a new field to Contact: |
| 129 | + |
| 130 | +```typescript |
| 131 | +// examples/crm/src/objects/contact.object.ts |
| 132 | +fields: { |
| 133 | + name: { type: 'text', required: true }, |
| 134 | + email: { type: 'email', required: true }, |
| 135 | + phone: { type: 'text' }, |
| 136 | + linkedin: { type: 'text', label: 'LinkedIn Profile' }, // NEW FIELD |
| 137 | + // ... |
| 138 | +} |
| 139 | +``` |
| 140 | + |
| 141 | +## Testing API Calls |
| 142 | + |
| 143 | +### Using Browser DevTools |
| 144 | + |
| 145 | +1. Open Network tab |
| 146 | +2. Filter by `Fetch/XHR` |
| 147 | +3. Perform actions in the app |
| 148 | +4. See requests to `/api/v1/*` intercepted by MSW |
| 149 | + |
| 150 | +### Using Console |
| 151 | + |
| 152 | +```javascript |
| 153 | +// In browser console |
| 154 | +const client = window.client; // If exposed |
| 155 | +const contacts = await fetch('/api/v1/contact').then(r => r.json()); |
| 156 | +console.log(contacts); |
| 157 | +``` |
| 158 | + |
| 159 | +## Common Tasks |
| 160 | + |
| 161 | +### Reset Data |
| 162 | + |
| 163 | +Refresh the browser - the in-memory database is cleared and reseeded. |
| 164 | + |
| 165 | +### Debug MSW |
| 166 | + |
| 167 | +Check `src/mocks/browser.ts` - `logRequests: true` enables detailed request logging. |
| 168 | + |
| 169 | +### Add Custom API Endpoints |
| 170 | + |
| 171 | +Edit `src/mocks/browser.ts` and add to `customHandlers`: |
| 172 | + |
| 173 | +```typescript |
| 174 | +customHandlers: [ |
| 175 | + http.get('/api/custom-endpoint', async () => { |
| 176 | + return HttpResponse.json({ message: 'Custom response' }); |
| 177 | + }) |
| 178 | +] |
| 179 | +``` |
| 180 | + |
| 181 | +## Next Steps |
| 182 | + |
| 183 | +1. **Explore the Code**: Check `src/App.tsx` to see how schemas are rendered |
| 184 | +2. **Modify Schemas**: Edit `src/schemas/*.ts` to change UI layouts |
| 185 | +3. **Add Features**: Create new pages, forms, or widgets |
| 186 | +4. **Read Documentation**: See main [README.md](./README.md) for architecture details |
| 187 | + |
| 188 | +## Troubleshooting |
| 189 | + |
| 190 | +### MSW not intercepting requests? |
| 191 | + |
| 192 | +- Check browser console for MSW registration messages |
| 193 | +- Ensure `public/mockServiceWorker.js` exists |
| 194 | +- Try hard refresh (Ctrl+Shift+R / Cmd+Shift+R) |
| 195 | + |
| 196 | +### Module not found errors? |
| 197 | + |
| 198 | +```bash |
| 199 | +# Rebuild workspace packages |
| 200 | +cd ../../ |
| 201 | +pnpm install |
| 202 | +pnpm build |
| 203 | +``` |
| 204 | + |
| 205 | +### Port already in use? |
| 206 | + |
| 207 | +Vite will automatically use the next available port. Check the terminal output. |
| 208 | + |
| 209 | +## Getting Help |
| 210 | + |
| 211 | +- Check the [main README](./README.md) for detailed architecture |
| 212 | +- Review [ObjectStack docs](https://objectstack.ai) |
| 213 | +- Inspect browser console logs for errors |
0 commit comments