This document provides a comprehensive overview of the VibeBuilder application architecture, design patterns, and technical decisions.
VibeBuilder is a React Native application built with Expo that enables users to create other React Native applications using AI. The architecture follows clean code principles with clear separation of concerns.
┌─────────────────────────────────────────────────┐
│ User Interface │
│ (React Native Components) │
└────────────┬────────────────────────────────────┘
│
┌────────────▼────────────────────────────────────┐
│ Navigation Layer │
│ (React Navigation Stack/Tabs) │
└────────────┬────────────────────────────────────┘
│
┌────────────▼────────────────────────────────────┐
│ State Management │
│ (Zustand Stores) │
└────┬───────┬────────┬──────────────────────────┘
│ │ │
┌────▼───┐ ┌▼────┐ ┌─▼──────┐
│ Auth │ │ App │ │ UI │
│ Store │ │Store│ │ Store │
└────┬───┘ └┬────┘ └─┬──────┘
│ │ │
┌────▼──────▼───────▼──────────────────────────────┐
│ Service Layer │
│ (AI, GitHub, Storage, Code Generation) │
└────────────┬──────────────────────────────────────┘
│
┌────────────▼────────────────────────────────────┐
│ External Services │
│ (GitHub API, AI API, AsyncStorage, SecureStore)│
└──────────────────────────────────────────────────┘
Purpose: Handle UI rendering and user interaction
Components Structure:
- Common Components: Reusable UI elements (Button, Card, Input, etc.)
- Feature Components: Domain-specific components (TemplateCard, AppCard, PhoneMockup)
- Screens: Full-screen views with business logic
Key Principles:
- Components are pure and functional
- Props are fully typed with TypeScript
- Theme-aware using
useTheme()hook - Accessibility considerations built-in
Purpose: Manage app routing and screen transitions
Structure:
- Stack Navigator: For screens requiring back navigation
- Tab Navigator: For main app sections
- Nested Navigation: Tabs within Stack for complex flows
Key Features:
- Type-safe navigation with TypeScript
- Authentication-aware routing
- Deep linking support ready
- Screen-specific options and headers
Purpose: Manage global application state
Stores:
- User authentication state
- Session management
- GitHub connection status
- Secure token storage
- Generated apps collection
- Template library
- Current app selection
- CRUD operations for apps
- Theme preference (light/dark/system)
- Toast notifications
- Modal state
- Loading states
State Architecture:
Store
├── State (data)
├── Computed Values (derived state)
└── Actions (state modifiers)Purpose: Business logic and external integrations
- App code generation
- Template customization
- Code enhancement
- Prompt processing
Current Implementation: Mock responses for development Production: Replace with actual AI API integration
- Repository creation
- Code commits
- Organization management
- Authentication
Security: Uses Octokit with secure token storage
- Secure credential storage (expo-secure-store)
- App data caching (AsyncStorage)
- Type-safe storage operations
- React Native code generation
- Expo configuration creation
- Dependency management
- File structure generation
Purpose: Shared utilities and custom hooks
Utils:
validation.ts: Input validation and sanitizationhelpers.ts: Common helper functions (date formatting, text truncation, etc.)
Hooks:
useTheme(): Theme access and managementuseAppGeneration(): App generation workflow- Standard React hooks for component logic
User Input (Prompt)
│
▼
Validation & Sanitization
│
▼
AI Service (generateApp)
│
├──▶ Code Generation
│ └──▶ AppCode object
│
├──▶ Preview Generation
│ └──▶ PreviewData object
│
└──▶ Suggestions Generation
└──▶ String array
│
▼
GitHub Service (optional)
│
├──▶ Create Repository
└──▶ Commit Code
│
▼
AppStore (addApp)
│
└──▶ Persist to AsyncStorage
│
▼
Navigation to AppDetail
Template Selection
│
▼
Template Data Retrieval
│
▼
User Customization (optional)
│
▼
AI Service (remixApp)
│
├──▶ Base Template Code
└──▶ Apply Modifications
│
▼
[Same as App Generation Flow]
User Credentials
│
▼
Validation (client-side)
│
▼
Hash/Encrypt (in production)
│
▼
Secure Storage (expo-secure-store)
│
├──▶ USER_TOKEN
├──▶ GITHUB_TOKEN
└──▶ USER_DATA (AsyncStorage)
-
Sensitive Data:
- Stored in expo-secure-store (encrypted)
- Never logged or exposed
- Auto-cleared on logout
-
User Input:
- Validated with strict rules
- Sanitized to prevent injection
- Length limits enforced
-
GitHub Tokens:
- Encrypted at rest
- Used only in secure context
- Revocable through settings
// User and Authentication
User
AuthState
// Apps and Templates
GeneratedApp
AppTemplate
AppCode
AppPreviewData
// Navigation
RootStackParamList
MainTabParamList
// API
AIGenerationRequest
AIGenerationResponse
APIResponse<T>
// Store
AppState
UIStateUser Input
│
▼
Runtime Validation
│
▼
TypeScript Compilation
│
▼
Type-Safe State Update
│
▼
Type-Safe Rendering
// Container (Screen)
export function HomeScreen() {
const { generateApp, isGenerating } = useAppGeneration();
const [prompt, setPrompt] = useState('');
const handleGenerate = async () => {
await generateApp(prompt);
};
return <HomeView {...{ prompt, setPrompt, handleGenerate, isGenerating }} />;
}
// Presenter (Component)
function HomeView({ prompt, setPrompt, handleGenerate, isGenerating }) {
return (
<View>
<Input value={prompt} onChangeText={setPrompt} />
<Button onPress={handleGenerate} loading={isGenerating} />
</View>
);
}export function useAppGeneration() {
const [isGenerating, setIsGenerating] = useState(false);
const { addApp } = useAppStore();
const generateApp = useCallback(async (prompt: string) => {
setIsGenerating(true);
try {
const result = await aiService.generateApp({ prompt });
await addApp(result);
return result;
} finally {
setIsGenerating(false);
}
}, [addApp]);
return { generateApp, isGenerating };
}-
State Updates:
- Zustand for efficient re-renders
- Selective subscriptions
- Computed values cached
-
Navigation:
- Native stack for performance
- Lazy loading of screens
- Optimized transitions
-
Lists:
- FlatList for large datasets
- Proper keyExtractor
- Item separation
-
Images:
- Lazy loading
- Proper resizeMode
- Cached network images
-
Code Generation:
- Async operations
- Progress indicators
- Cancelable operations
Error Occurs
│
▼
Caught in try/catch
│
▼
Logged (console.error)
│
▼
User-Friendly Message
│
├──▶ Toast Notification
└──▶ Error State in UI
│
▼
Recovery Options Offered
- Network Errors: Retry with exponential backoff
- Validation Errors: Inline form feedback
- GitHub Errors: Fallback to local storage
- Generation Errors: Offer retry or template alternative
- Single user device
- Local data storage
- Client-side generation
- Multi-user backend
- Cloud storage
- Server-side generation
- Caching layer
- Load balancing
users
- id, email, name, github_username, created_at
apps
- id, user_id, name, description, code_json, status, created_at
templates
- id, name, category, code_json, remix_count, rating
app_versions
- id, app_id, version, code_json, created_at- Utility functions
- Validation logic
- Store actions
- Service methods
- Component with hooks
- Store with services
- Navigation flows
- API integrations
- User registration
- App generation
- Template remix
- GitHub integration
- Implement proper error boundaries
- Add crash reporting (Sentry)
- Implement analytics
- Add performance monitoring
- Implement proper logging
- Real-time collaboration
- Version control for apps
- App preview in WebView
- Export to Expo Snack
- Template marketplace
- Cloud sync
- Backend API layer
- GraphQL for data fetching
- WebSocket for real-time features
- CDN for assets
- Microservices for scaling
Local Machine
│
▼
Expo Dev Server
│
▼
Expo Go App
EAS Build
│
├──▶ iOS Build → App Store
└──▶ Android Build → Google Play
- App generation success rate
- Template remix frequency
- GitHub connection rate
- Error rates by type
- User engagement metrics
- Performance metrics (load times, render times)
- Info: User actions
- Warn: Recoverable errors
- Error: Critical failures
- Debug: Development only
This architecture provides a solid foundation for building and scaling VibeBuilder. The clean separation of concerns, type safety, and security considerations make it maintainable and extensible.
Key Strengths:
- Type-safe with TypeScript
- Modular and testable
- Security-first approach
- Scalable patterns
- Clear data flow
For questions or clarifications, refer to the codebase or contact the development team.