MicroSaaSFast Mobile App

    This documentation provides step-by-step instructions on how to set up and configure the MicroSaaSFast mobile application built with Expo and React Native.

    Project Structure

    The mobile app follows Expo Router's file-based routing system with the following structure:

    Project Structure

  1. microsaasfast-mobile/
  2. ├── app/
  3. │ ├── _layout.tsx # Root layout with ClerkProvider
  4. │ ├── index.tsx # Entry point with auth redirect
  5. │ ├── checkout-success.tsx # Stripe checkout success handler
  6. │ ├── (auth)/
  7. │ │ ├── _layout.tsx # Auth stack layout
  8. │ │ ├── sign-in.tsx # Sign in screen
  9. │ │ └── sign-up.tsx # Sign up screen
  10. │ └── (tabs)/
  11. │ ├── _layout.tsx # Tabs navigation layout
  12. │ ├── home.tsx # Home screen with projects
  13. │ └── profile.tsx # Profile screen
  14. ├── components/
  15. │ └── OAuthButton.tsx # OAuth provider buttons
  16. ├── constants/
  17. │ └── theme.ts # Theme system (light/dark/system)
  18. ├── assets/ # App icons and splash screens
  19. ├── app.config.js # Expo configuration
  20. ├── app.json # Expo app manifest
  21. └── package.json # Dependencies
  22. Installation

    1. Clone the Repository
    Clone the repository to your local machine and navigate to the project directory.

    bash

  23. git clone <repository-url>
  24. cd microsaasfast-mobile
  25. 2. Install Dependencies
    Install all required npm packages using npm or yarn.

    bash

  26. npm install
  27. 3. Environment Variables
    Create a `.env` file in the root directory with the required environment variables.

    .env

  28. EXPO_PUBLIC_CLERK_PUBLISHABLE_KEY=your_clerk_publishable_key_here
  29. EXPO_PUBLIC_APP_URL=https://your.microsaasfast.domain
  30. 4. Start Development Server
    Start the Expo development server to run the app on iOS, Android, or web.

    bash

  31. npm start
  32. Configuration

    1. Clerk Authentication Setup

    • Create a Clerk account at clerk.com

    • Create a new application in Clerk dashboard

    • Configure OAuth providers (Google, Apple, GitHub, Facebook)

    • Copy your publishable key to the `.env` file

    • Ensure your app URL scheme matches: microsaasfast

    app.config.js

  33. import 'dotenv/config';
  34. export default {
  35. expo: {
  36. name: 'MicroSaaSFast Mobile',
  37. slug: 'microsaasfast-mobile',
  38. scheme: 'microsaasfast',
  39. extra: {
  40. clerkPublishableKey: process.env.EXPO_PUBLIC_CLERK_PUBLISHABLE_KEY,
  41. appUrl: process.env.EXPO_PUBLIC_APP_URL,
  42. },
  43. },
  44. };
  45. 2. Backend API Configuration
    The app connects to a backend API. Ensure your backend API is properly configured and accessible. The following endpoints are used:

    • GET /api/projects - Fetch user projects

    • GET /api/subscription - Check subscription status

    • POST /api/stripe/create-checkout - Create Stripe checkout session

    • POST /api/stripe/create-portal - Create Stripe customer portal session

    API Configuration

  46. // The app URL is configured via environment variable
  47. const appUrl = Constants.expoConfig?.extra?.appUrl || process.env.EXPO_PUBLIC_APP_URL;
  48. // Example API call
  49. const response = await axios.get(`${appUrl}/api/projects`, {
  50. headers: {
  51. 'Authorization': `Bearer ${token}`,
  52. 'Accept': 'application/json',
  53. },
  54. });
  55. Authentication Flow

    1. Root Layout Setup
    The root layout wraps the app with ClerkProvider and ThemeProvider, handling authentication state.

    app/_layout.tsx

  56. import { ClerkProvider } from '@clerk/clerk-expo';
  57. import { ThemeProvider } from '@/constants/theme';
  58. export default function RootLayout() {
  59. const publishableKey = Constants.expoConfig?.extra?.clerkPublishableKey;
  60. return (
  61. <ClerkProvider tokenCache={tokenCache} publishableKey={publishableKey}>
  62. <ThemeProvider>
  63. <InitialLayout />
  64. </ThemeProvider>
  65. </ClerkProvider>
  66. );
  67. }
  68. 2. Authentication Routing
    The app automatically redirects users based on their authentication state:

    • Signed-in users are redirected to /(tabs)/home

    • Signed-out users are redirected to /(auth)/sign-in

    • Deep links for checkout-success are handled automatically

    app/_layout.tsx - InitialLayout

  69. const InitialLayout = () => {
  70. const { isLoaded, isSignedIn } = useAuth();
  71. const segments = useSegments();
  72. const router = useRouter();
  73. useEffect(() => {
  74. if (!isLoaded) return;
  75. const inAuthGroup = segments[0] === '(auth)';
  76. if (isSignedIn && inAuthGroup) {
  77. router.replace('/(tabs)/home');
  78. } else if (!isSignedIn && !inAuthGroup) {
  79. router.replace('/(auth)/sign-in');
  80. }
  81. }, [isSignedIn, isLoaded, segments, router]);
  82. };
  83. 3. OAuth Providers
    The app supports multiple OAuth providers through Clerk. OAuth buttons are implemented in a reusable component.

    components/OAuthButton.tsx

  84. import { useOAuth } from '@clerk/clerk-expo';
  85. export default function OAuthButton({ provider }: { provider: 'google' | 'apple' }) {
  86. const { startOAuthFlow } = useOAuth({
  87. strategy: `oauth_${provider}`
  88. });
  89. const handlePress = async () => {
  90. const { createdSessionId, setActive } = await startOAuthFlow();
  91. if (createdSessionId) {
  92. await setActive!({ session: createdSessionId });
  93. router.replace('/(tabs)/home');
  94. }
  95. };
  96. }
  97. Theme System

    The app includes a comprehensive theme system supporting light, dark, and system themes. Theme preferences are persisted using Expo SecureStore.
    1. Theme Provider

    • Provides theme context to all components

    • Supports light, dark, and system theme modes

    • Persists theme preference in SecureStore

    • Automatically adapts to system color scheme when set to 'system'

    constants/theme.ts

  98. export const lightTheme = {
  99. background: '#FFFFFF',
  100. text: '#010610',
  101. button: '#007AFF',
  102. // ... other colors
  103. };
  104. export const darkTheme = {
  105. background: '#010814',
  106. text: '#FFFFFF',
  107. button: '#FFFFFF',
  108. // ... other colors
  109. };
  110. export function ThemeProvider({ children }) {
  111. const [themeMode, setThemeMode] = useState<ThemeMode>('system');
  112. // Loads and saves theme preference
  113. }
  114. 2. Using Themes in Components
    Components access the theme through the useTheme hook.

    Example Component

  115. import { useTheme } from '@/constants/theme';
  116. export default function MyComponent() {
  117. const theme = useTheme();
  118. return (
  119. <View style={{ backgroundColor: theme.background }}>
  120. <Text style={{ color: theme.text }}>Hello</Text>
  121. </View>
  122. );
  123. }
  124. Subscription & Payments

    1. Stripe Checkout Flow
    The app integrates with Stripe for subscription management. The checkout flow uses deep links to return users to the app after payment.

    Checkout Implementation

  125. const handlePurchase = async () => {
  126. // Create deep link URL for Stripe redirect
  127. const deepLinkUrl = Linking.createURL('checkout-success', {});
  128. // Create checkout session
  129. const response = await axios.post(`${appUrl}/api/stripe/create-checkout`, {
  130. priceId: 'price_1SaM3rEM1PGI2jZXuF1no3ea',
  131. email: user.primaryEmailAddress?.emailAddress,
  132. userId: user.id,
  133. successUrl: deepLinkUrl,
  134. });
  135. // Open checkout in browser
  136. await WebBrowser.openBrowserAsync(checkoutUrl);
  137. // Deep link listener handles redirect back to app
  138. };
  139. 2. Deep Link Handling
    The app listens for deep links to handle Stripe redirects and subscription updates.

    Deep Link Listener

  140. useEffect(() => {
  141. // Listen for deep links when app is open
  142. const subscription = Linking.addEventListener('url', (event) => {
  143. const { url } = event;
  144. if (url.includes('checkout-success')) {
  145. WebBrowser.dismissBrowser();
  146. setTimeout(() => {
  147. checkSubscription();
  148. }, 1000);
  149. }
  150. });
  151. return () => subscription.remove();
  152. }, []);
  153. 3. Subscription Management
    Users can manage their subscriptions through the Stripe Customer Portal.

    Customer Portal

  154. const handleManageSubscription = async () => {
  155. const response = await axios.post(
  156. `${appUrl}/api/stripe/create-portal`,
  157. {
  158. email: user.primaryEmailAddress?.emailAddress,
  159. userId: user.id,
  160. },
  161. {
  162. headers: {
  163. 'Authorization': `Bearer ${token}`,
  164. },
  165. }
  166. );
  167. const portalUrl = response.data.portalUrl;
  168. await WebBrowser.openBrowserAsync(portalUrl);
  169. };
  170. Building for Production

    1. iOS Build
    Build the iOS app using Expo CLI or EAS Build.

    iOS Build Commands

  171. # Using Expo CLI
  172. expo build:ios
  173. # Using EAS Build (recommended)
  174. eas build --platform ios
  175. 2. Android Build
    Build the Android app using Expo CLI or EAS Build.

    Android Build Commands

  176. # Using Expo CLI
  177. expo build:android
  178. # Using EAS Build (recommended)
  179. eas build --platform android
  180. 3. App Configuration
    Ensure your app.json and app.config.js are properly configured with:

    • Bundle identifier (iOS): com.microsaasfast.mobile

    • Package name (Android): com.microsaasfast.mobile

    • App scheme: microsaasfast

    • Icon and splash screen assets

    app.json

  181. {
  182. "expo": {
  183. "name": "MicroSaaSFast Mobile",
  184. "slug": "microsaasfast-mobile",
  185. "scheme": "microsaasfast",
  186. "ios": {
  187. "bundleIdentifier": "com.microsaasfast.mobile"
  188. },
  189. "android": {
  190. "package": "com.microsaasfast.mobile"
  191. }
  192. }
  193. }
  194. Environment Variables

    The following environment variables are required for the app to function properly.
    Required Variables

    • EXPO_PUBLIC_CLERK_PUBLISHABLE_KEY - Your Clerk publishable key (required)

    • EXPO_PUBLIC_APP_URL - Backend API URL - your microsaasfast-full domain (required)

    .env

  195. EXPO_PUBLIC_CLERK_PUBLISHABLE_KEY=pk_test_...
  196. EXPO_PUBLIC_APP_URL=https://your.microsaasfast.domain
  197. Make sure to never commit your `.env` file to version control. The `.gitignore` file should already exclude it. These environment variables are loaded at build time and are accessible through Constants.expoConfig?.extra in your app code.

    Key Features

    1. Authentication

    • Email/password authentication

    • OAuth providers: Google, Apple, GitHub, Facebook

    • Secure token storage with Expo SecureStore

    • Automatic session management

    2. Project Management

    • View user projects from backend API

    • Chat interface for each project

    • Project status indicators

    • Webhook integration for AI assistants

    3. Subscription Management

    • Stripe checkout integration

    • Subscription status checking

    • Customer portal access

    • Deep link handling for payment flows

    4. Theme System

    • Light, dark, and system themes

    • Persistent theme preferences

    • Smooth theme transitions

    Troubleshooting

    Common Issues

    1. Missing Clerk Key: Ensure EXPO_PUBLIC_CLERK_PUBLISHABLE_KEY is set in .env

    2. API Connection Errors: Verify EXPO_PUBLIC_APP_URL points to your backend

    3. Deep Links Not Working: Check that scheme matches in app.json and Clerk dashboard

    4. Build Errors: Ensure all dependencies are installed and environment variables are set

    For additional support, visit the discord server