1
+ ---
2
+ description:
3
+ globs:
4
+ alwaysApply: true
5
+ ---
6
+ # Chatwoot Mobile App - Combined Cursor Rules
7
+
8
+ ## Project Overview
9
+
10
+ Chatwoot Mobile is a mobile app for the Chatwoot platform, built with React Native and Expo.
11
+
12
+ ### Main Features:
13
+ - Ability to view conversations
14
+ - Ability to send messages
15
+ - Follow up on customer conversations on the go
16
+ - Reply easily with canned responses
17
+ - Receive real-time notifications about messages
18
+ - Communicate with other te notes
19
+ - Assign statuses to conversa and Structure
20
+
21
+ You are an expeScript, React Native, Expo, and Mobile UI development.
22
+
23
+ ### General Principles
24
+ - Write concise, technical TypeScript code with accurate examples
25
+ - Use functional and declarative programming patterns; avoid classes
26
+ - Prefer iteration and modularization over code duplication
27
+ - Use descriptive variable names with auxiliary verbs (e.g., isLoading, hasError)
28
+ - Structure files: exported component, subcomponents, helpers, static content, types
29
+ - Component Modularity: Break down components into smaller, reusable pieces. Keep components focused on a single responsibility
30
+ - Follow Expo's official documentation for setting up and configuring your projects: https://docs.expo.dev/
31
+
32
+ ### Naming Conventions
33
+ - Use lowercase with dashes for directories (e.g., components/auth-wizard)
34
+ - Favor named exports for components
35
+
36
+ ### TypeScript Usage
37
+ - Use TypeScript for all code; prefer interfaces over types
38
+ - Avoid enums; use maps instead
39
+ - Use functional components with TypeScript interfaces
40
+ - Use strict mode in TypeScript for better type safety
41
+
42
+ ### Syntax and Formatting
43
+ - Use the "function" keyword for pure functions
44
+ - Avoid unnecessary curly braces in conditionals; use concise syntax for simple statements
45
+ - Use declarative JSX
46
+ - Use Prettier for consistent code formatting
47
+
48
+ ## UI and Styling
49
+
50
+ - Use the package @https://github.com/jaredh159/tailwind-react-native-classnames for styles
51
+ - Use Expo's built-in components for common UI patterns and layouts
52
+ - Implement responsive design with Flexbox and Expo's useWindowDimensions for screen size adjustments
53
+ - Use styled-components or Tailwind CSS for component styling
54
+ - Implement dark mode support using Expo's useColorScheme
55
+ - Ensure high accessibility (a11y) standards using ARIA roles and native accessibility props
56
+ - Leverage react-native-reanimated and react-native-gesture-handler for performant animations and gestures
57
+
58
+ ## Safe Area Management
59
+ - Use SafeAreaProvider from react-native-safe-area-context to manage safe areas globally in your app
60
+ - Wrap top-level components with SafeAreaView to handle notches, status bars, and other screen insets on both iOS and Android
61
+ - Use SafeAreaScrollView for scrollable content to ensure it respects safe area boundaries
62
+ - Avoid hardcoding padding or margins for safe areas; rely on SafeAreaView and context hooks
63
+
64
+ ## Performance Optimization
65
+ - Minimize the use of useState and useEffect; prefer context and reducers for state management
66
+ - Use Expo's AppLoading and SplashScreen for optimized app startup experience
67
+ - Optimize images: implement lazy loading with expo-image
68
+ - Implement code splitting and lazy loading for non-critical components with React's Suspense and dynamic imports
69
+ - Profile and monitor performance using React Native's built-in tools and Expo's debugging features
70
+ - Avoid unnecessary re-renders by memoizing components and using useMemo and useCallback hooks appropriately
71
+ - Always clearTimeout or clearInterval when using them — especially in event listeners, effects (useEffect), or animations
72
+
73
+ ## Navigation
74
+ - Use react-navigation for routing and navigation; follow its best practices for stack, tab, and drawer navigators
75
+ - Leverage deep linking and universal links for better user engagement and navigation flow
76
+ - Use dynamic routes with expo-router for better navigation handling
77
+
78
+ ## State Management
79
+ - Use React Context and useReducer for managing global state
80
+ - Leverage react-query for data fetching and caching; avoid excessive API calls
81
+ - For complex state management, consider using Zustand or Redux Toolkit
82
+ - Handle URL search parameters using libraries like expo-linking
83
+
84
+ ## Security
85
+ - Sanitize user inputs to prevent XSS attacks
86
+ - Use react-native-encrypted-storage for secure storage of sensitive data
87
+ - Ensure secure communication with APIs using HTTPS and proper authentication
88
+ - Use Expo's Security guidelines to protect your app: https://docs.expo.dev/guides/security/
89
+
90
+ ## Key Conventions
91
+ - Rely on Expo's managed workflow for streamlined development and deployment
92
+ - Prioritize Mobile Web Vitals (Load Time, Jank, and Responsiveness)
93
+ - Use expo-constants for managing environment variables and configuration
94
+ - Use expo-permissions to handle device permissions gracefully
95
+ - Follow Expo's best practices for app deployment and publishing: https://docs.expo.dev/distribution/introduction/
96
+ - Ensure compatibility with iOS and Android by testing extensively on both platforms
97
+
98
+ ## Project Structure
99
+
100
+ ### Directories:
101
+ - **src/** - Main source code directory containing app components, screens, and business logic
102
+ - **ios/** - iOS native code and configuration
103
+ - **android/** - Android native code and configuration
104
+ - **assets/** - Static assets like images, fonts, and other media files
105
+ - **__mocks__/** - Jest test mocks and fixtures
106
+ - **.expo/** - Expo development environment configuration
107
+ - **.storybook/** - Component documentation and testing environment
108
+ - **.circleci/** - CI/CD pipeline configuration
109
+ - **.github/** - GitHub workflows and templates
110
+ - **.cursor/** - IDE-specific configuration
111
+ - **node_modules/** - Project dependencies
112
+ - **App.tsx** - Main application entry point
113
+ - **package.json** - Project dependencies and scripts
114
+ - **app.config.ts** - Expo app configuration
115
+ - **metro.config.js** - Metro bundler configuration
116
+ - **babel.config.js** - Babel transpiler configuration
117
+ - **tsconfig.json** - TypeScript configuration
118
+ - **.env & .env.example** - Environment variables
119
+ - **firebase.json & google-services.json** - Firebase configuration
120
+ - **eas.json** - Expo Application Services configuration
121
+ - **jest.config.js** - Jest testing configuration
122
+ - **reanimatedConfig.js** - React Native Reanimated configuration
123
+ - **wdyr.js** - Why Did You Render debugging configuration
124
+
125
+ ### Main Source Code Structure:
126
+ - **theme/** - UI theme configuration and styling constants
127
+ - **navigation/** - Navigation stack and routing configuration
128
+ - **assets/** - Local assets specific to the app
129
+ - **types/** - TypeScript type definitions and interfaces
130
+ - **utils/** - Utility functions and helper methods
131
+ - **i18n/** - Internationalization and localization setup
132
+ - **components-next/** - Next generation UI components
133
+ - **constants/** - Application-wide constants and configuration
134
+ - **context/** - React Context providers and state management
135
+ - **hooks/** - Custom React hooks
136
+ - **screens/** - Application screens and pages
137
+ - **services/** - API services and external integrations
138
+ - **store/** - State management (likely Redux/Redux Toolkit)
139
+ - **svg-icons/** - SVG icon components and assets
140
+ - **app.tsx** - Main application component
141
+ - **hooks.ts** - Exports of custom hooks
142
+
143
+ ### Application Modules:
144
+
145
+ 1. **Auth Module**
146
+ - Login screen
147
+ - Forgot password screen
148
+ - Change URL screen
149
+
150
+ 2. **Dashboard Module**
151
+ - Inbox screen
152
+ - Conversation screen
153
+ - Chat screen (Message view and Actions View)
154
+ - Contact details screen
155
+ - Dashboard Apps
156
+ - Settings screen
157
+
158
+ ## Redux Store Architecture
159
+
160
+ ### Overview
161
+ The Chatwoot mobile app uses Redux Toolkit for state management with the following key features:
162
+ - Redux Persist for state persistence
163
+ - Middleware support for side effects
164
+ - TypeScript integration
165
+ - Reactotron debugging support in development
166
+ - State migration handling
167
+
168
+ ### Store Structure
169
+ ```typescript
170
+ RootState {
171
+ auth: AuthState
172
+ settings: SettingsState
173
+ conversations: {
174
+ filter: ConversationFilterState
175
+ selected: ConversationSelectedState
176
+ header: ConversationHeaderState
177
+ list: ConversationState
178
+ actions: ConversationActionState
179
+ typing: ConversationTypingState
180
+ sendMessage: SendMessageState
181
+ audioPlayer: AudioPlayerState
182
+ localRecordedAudioCache: LocalRecordedAudioCacheState
183
+ participants: ConversationParticipantState
184
+ }
185
+ contacts: {
186
+ list: ContactState
187
+ labels: ContactLabelState
188
+ conversations: ContactConversationState
189
+ }
190
+ labels: LabelState
191
+ inboxes: InboxState
192
+ assignableAgents: AssignableAgentState
193
+ notifications: {
194
+ list: NotificationState
195
+ filter: NotificationFilterState
196
+ }
197
+ teams: TeamState
198
+ macros: MacroState
199
+ dashboardApps: DashboardAppState
200
+ customAttributes: CustomAttributeState
201
+ cannedResponses: CannedResponseState
202
+ }
203
+ ```
204
+
205
+ ### Redux Best Practices
206
+
207
+ 1. **State Organization**
208
+ - Each feature has its own slice
209
+ - Related features are grouped in nested state
210
+ - Clear separation of concerns
211
+
212
+ 2. **Action Handling**
213
+ - Use Redux Toolkit's `createSlice` for reducers
214
+ - Implement feature-specific middleware when needed
215
+ - Handle global actions (e.g., logout) at root reducer
216
+
217
+ 3. **State Updates**
218
+ - Use immer-powered mutations in reducers
219
+ - Implement optimistic updates where appropriate
220
+ - Handle loading and error states consistently
221
+
222
+ 4. **TypeScript Integration**
223
+ - Define strong types for all state slices
224
+ - Use typed selectors and actions
225
+ - Leverage Redux Toolkit's built-in type helpers
226
+
227
+ 5. **Performance**
228
+ - Implement proper memoization
229
+ - Use selective state persistence
230
+ - Configure appropriate warning thresholds
231
+
232
+ ### Implementation Examples
233
+
234
+ 1. **Creating a New Slice**
235
+ ```typescript
236
+ import { createSlice, PayloadAction } from '@reduxjs/toolkit';
237
+
238
+ interface YourState {
239
+ data: any[];
240
+ loading: boolean;
241
+ error: string | null;
242
+ }
243
+
244
+ const initialState: YourState = {
245
+ data: [],
246
+ loading: false,
247
+ error: null,
248
+ };
249
+
250
+ const yourSlice = createSlice({
251
+ name: 'yourFeature',
252
+ initialState,
253
+ reducers: {
254
+ setLoading: (state, action: PayloadAction<boolean>) => {
255
+ state.loading = action.payload;
256
+ },
257
+ // ... more reducers
258
+ },
259
+ });
260
+ ```
261
+
262
+ 2. **Using Typed Selectors**
263
+ ```typescript
264
+ import { RootState } from '@/store';
265
+
266
+ export const selectYourData = (state: RootState) => state.yourFeature.data;
267
+ ```
268
+
269
+ 3. **Dispatching Actions**
270
+ ```typescript
271
+ import { useAppDispatch } from '@/store/hooks';
272
+
273
+ const dispatch = useAppDispatch();
274
+ dispatch(yourSlice.actions.setLoading(true));
275
+ ```
276
+
277
+ ## Theme System
278
+
279
+ ### Core Files
280
+ - `tailwind.config.ts`: Base theme configuration
281
+ - `tailwind.ts`: Tailwind instance creation and export
282
+ - `colors/light.ts`: Light theme color definitions
283
+ - `colors/dark.ts`: Dark theme color definitions
284
+ - `colors/blackA.ts`: Black with alpha variations
285
+ - `colors/whiteA.ts`: White with alpha variations
286
+
287
+ ### Base Configuration
288
+ ```typescript
289
+ // tailwind.config.ts
290
+ const twConfig = {
291
+ theme: {
292
+ ...defaultTheme,
293
+ extend: {
294
+ colors: { ...chatwootAppColors },
295
+ fontSize: {
296
+ xs: '12px',
297
+ cxs: '13px',
298
+ md: '15px'
299
+ },
300
+ fontFamily: {
301
+ 'inter-normal-20': ['Inter-400-20'],
302
+ 'inter-420-20': ['Inter-420-20'],
303
+ 'inter-medium-24': ['Inter-500-24'],
304
+ 'inter-580-24': ['Inter-580-24'],
305
+ 'inter-semibold-20': ['Inter-600-20']
306
+ }
307
+ }
308
+ },
309
+ plugins: []
310
+ };
311
+ ```
312
+
313
+ ### Color System
314
+
315
+ #### Color Categories
316
+ 1. **UI Colors** - gray, mauve, slate
317
+ 2. **Nature Colors** - sage, olive, sand
318
+ 3. **Primary Colors** - blue, indigo, violet
319
+ 4. **Accent Colors** - tomato, red, ruby, crimson
320
+ 5. **Special Colors** - mint, lime, yellow, amber
321
+ 6. **Neutral Colors** - brown, bronze, gold
322
+
323
+ ### Font System
324
+
325
+ The app uses the Inter font family with various weights and optical sizes:
326
+
327
+ | Font Name | Weight | Optical Size |
328
+ |-----------|---------|--------------|
329
+ | Inter-400-20 | Normal (400) | 20 |
330
+ | Inter-420-20 | Light Medium (420) | 20 |
331
+ | Inter-500-24 | Medium (500) | 24 |
332
+ | Inter-580-24 | Semi Medium (580) | 24 |
333
+ | Inter-600-20 | Semi Bold (600) | 20 |
334
+
335
+ ### Theme Usage Examples
336
+ ```typescript
337
+ // Basic styling
338
+ <View style={tailwind('bg-blue-500 p-4')}>
339
+ <Text style={tailwind('text-md font-inter-normal-20')}>
340
+ Hello World
341
+ </Text>
342
+ </View>
343
+
344
+ // Combining styles
345
+ <TouchableOpacity
346
+ style={tailwind('bg-blue-600 rounded-lg p-3 active:bg-blue-700')}>
347
+ <Text style={tailwind('text-white font-inter-medium-24')}>
348
+ Submit
349
+ </Text>
350
+ </TouchableOpacity>
351
+ ```
352
+
353
+ ## Design Principles
354
+
355
+ 1. **Consistency**
356
+ - Unified color palette across the app
357
+ - Consistent spacing and typography scales
358
+ - Standardized component styles
359
+
360
+ 2. **Flexibility**
361
+ - Support for both light and dark modes
362
+ - Alpha variations for transparency
363
+ - Multiple color variations for different states
364
+
365
+ 3. **Accessibility**
366
+ - Proper contrast ratios
367
+ - Clear visual hierarchies
368
+ - Readable typography scales
369
+
370
+ 4. **Maintainability**
371
+ - Modular color files
372
+ - TypeScript support
373
+ - Clear naming conventions
374
+
375
+ 5. **Scalability**
376
+ - Extensive color variations
377
+ - Flexible component styling
378
+ - Easy theme extensions
379
+
380
+ ## Best Practices Summary
381
+
382
+ 1. Always use the `tailwind` utility for styling
383
+ 2. Use semantic color names when possible
384
+ 3. Maintain consistent spacing using the built-in scale
385
+ 4. Follow the established typography system
386
+ 5. Consider dark mode implications when styling
387
+ 6. Use alpha variations for overlay and hover states
388
+ 7. Leverage TypeScript for type safety
389
+ 8. Test extensively on both iOS and Android platforms
390
+ 9. Follow Expo's official documentation and best practices
391
+ 10. Implement proper error handling and security measures
392
+
393
+ ## API Documentation
394
+ - Use Expo's official documentation for setting up and configuring your projects: https://docs.expo.dev/
395
+ - Refer to Expo's documentation for detailed information on Views, Blueprints, and Extensions for best practices
0 commit comments