native-update
Version:
Foundation package for building a comprehensive update system for Capacitor apps. Provides architecture and interfaces but requires backend implementation.
588 lines (486 loc) โข 21.1 kB
Markdown
# Task 2: SaaS Platform Architecture
**Created:** 2025-12-27
**Status:** ๐ Planning
**Estimated Time:** 40-60 hours (full transformation)
## ๐ฏ Vision
Transform the native-update marketing website from a static information site into a **full SaaS platform** where users can:
1. **Sign up and log in** to manage their update infrastructure
2. **Connect their Google Drive** account for build storage
3. **Upload app builds** (APK, IPA, web bundles) from the dashboard
4. **Generate configuration** to integrate updates into their app
5. **Manage multiple apps** and update channels from one dashboard
**End Goal:** Users get a complete OTA update backend without setting up their own infrastructure.
## ๐๏ธ High-Level Architecture
### System Components
```
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Marketing Website โ
โ (React 19 + RadixUI + Tailwind + Firebase + Router) โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ โ
โ โโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโ โ
โ โ Public โ โ Auth โ โ Dashboard โ โ
โ โ Pages โ โ Pages โ โ Pages โ โ
โ โ โ โ โ โ (Protected) โ โ
โ โ - Home โ โ - Login โ โ - Overview โ โ
โ โ - Features โ โ - Signup โ โ - Builds โ โ
โ โ - Pricing โ โ - Reset PW โ โ - Upload โ โ
โ โ - Docs โ โ โ โ - Config โ โ
โ โ - About โ โ โ โ - Settings โ โ
โ โโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโ โ
โ โ
โโโโโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ
โผ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Firebase Backend โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ โ
โ โโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโ โ
โ โ Authentication โ โ Firestore โ โ
โ โ โ โ โ โ
โ โ - Email/Password โ โ - users โ โ
โ โ - Google OAuth โ โ - builds โ โ
โ โ - Email Verify โ โ - apps โ โ
โ โ - Password Reset โ โ - drive_tokens โ โ
โ โโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโ โ
โ โ
โ โโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโ โ
โ โ Cloud Functions โ โ Storage โ โ
โ โ โ โ โ โ
โ โ - API Endpoints โ โ - Temp files โ โ
โ โ - Drive Upload โ โ - User uploads โ โ
โ โ - Config Gen โ โ โ โ
โ โโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโ โ
โ โ
โโโโโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ
โผ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Google Drive API โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ โ
โ User's Personal Google Drive โ
โ โโโ NativeUpdate/ โ
โ โ โโโ app-1/ โ
โ โ โ โโโ production/ โ
โ โ โ โ โโโ build-1.0.0.zip โ
โ โ โ โ โโโ build-1.0.1.zip โ
โ โ โ โโโ staging/ โ
โ โ โโโ app-2/ โ
โ โ โโโ production/ โ
โ โ โโโ build-2.0.0.zip โ
โ โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
```
## ๐ Authentication Flow
### User Journey
1. **Landing Page** โ Click "Get Started" or "Dashboard"
2. **Login/Signup Choice** โ Email/password or Google OAuth
3. **Email Verification** (if email/password) โ Confirm email
4. **Dashboard** โ Access protected features
### Authentication States
```typescript
type AuthState =
| { status: 'unauthenticated' }
| { status: 'loading' }
| { status: 'authenticated', user: User }
| { status: 'email-not-verified', user: User };
```
### Protected Routes
```typescript
const routes = [
// Public
{ path: '/', public: true },
{ path: '/features', public: true },
{ path: '/pricing', public: true },
// Auth
{ path: '/login', public: true, authOnly: false },
{ path: '/signup', public: true, authOnly: false },
// Protected
{ path: '/dashboard', protected: true },
{ path: '/dashboard/builds', protected: true },
{ path: '/dashboard/upload', protected: true },
{ path: '/dashboard/config', protected: true },
{ path: '/dashboard/settings', protected: true },
];
```
## ๐พ Data Architecture
### Firestore Collections
**1. `users` Collection**
```typescript
interface User {
uid: string; // Firebase Auth UID
email: string;
displayName: string | null;
photoURL: string | null;
createdAt: Timestamp;
lastLogin: Timestamp;
// Google Drive
driveConnected: boolean;
driveEmail: string | null;
// Subscription (future)
plan: 'free' | 'pro' | 'enterprise';
// Settings
preferences: {
emailNotifications: boolean;
updateNotifications: boolean;
};
}
```
**2. `apps` Collection**
```typescript
interface App {
id: string; // Auto-generated
userId: string; // Owner
name: string; // App name
packageId: string; // com.example.app
platform: 'ios' | 'android' | 'web' | 'all';
createdAt: Timestamp;
updatedAt: Timestamp;
// Update channels
channels: {
production: ChannelConfig;
staging: ChannelConfig;
development: ChannelConfig;
};
}
interface ChannelConfig {
enabled: boolean;
autoUpdate: boolean;
requireUserConsent: boolean;
}
```
**3. `builds` Collection**
```typescript
interface Build {
id: string; // Auto-generated
userId: string;
appId: string;
// Build info
version: string; // Semantic version
buildNumber: number;
channel: 'production' | 'staging' | 'development';
platform: 'ios' | 'android' | 'web';
// File info
fileName: string;
fileSize: number; // Bytes
fileType: string; // .zip, .apk, .ipa
checksum: string; // SHA-256
// Google Drive
driveFileId: string; // Google Drive file ID
driveFileUrl: string; // Direct download URL
// Metadata
releaseNotes: string;
uploadedAt: Timestamp;
uploadedBy: string; // User email
// Status
status: 'uploading' | 'active' | 'archived' | 'failed';
}
```
**4. `drive_tokens` Collection** (Encrypted)
```typescript
interface DriveToken {
userId: string; // Document ID
accessToken: string; // Encrypted
refreshToken: string; // Encrypted
expiresAt: Timestamp;
scope: string[];
updatedAt: Timestamp;
}
```
**5. `analytics` Collection** (Future)
```typescript
interface AnalyticsEvent {
userId: string;
appId: string;
buildId: string;
eventType: 'download' | 'install' | 'rollback' | 'error';
timestamp: Timestamp;
metadata: Record<string, any>;
}
```
### Security Rules
```javascript
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
// Helper functions
function isAuthenticated() {
return request.auth != null;
}
function isOwner(userId) {
return isAuthenticated() && request.auth.uid == userId;
}
// Users collection
match /users/{userId} {
allow read: if isOwner(userId);
allow write: if isOwner(userId);
}
// Apps collection
match /apps/{appId} {
allow read: if isOwner(resource.data.userId);
allow create: if isAuthenticated();
allow update, delete: if isOwner(resource.data.userId);
}
// Builds collection
match /builds/{buildId} {
allow read: if isOwner(resource.data.userId);
allow create: if isAuthenticated();
allow update, delete: if isOwner(resource.data.userId);
}
// Drive tokens (encrypted, very restricted)
match /drive_tokens/{userId} {
allow read, write: if isOwner(userId);
}
}
}
```
## ๐ API Endpoints (Firebase Functions)
### Authentication Endpoints
- `POST /api/auth/signup` - Create new user
- `POST /api/auth/login` - Login user
- `POST /api/auth/logout` - Logout user
- `POST /api/auth/reset-password` - Send reset email
- `POST /api/auth/verify-email` - Send verification email
### User Endpoints
- `GET /api/user/profile` - Get user profile
- `PUT /api/user/profile` - Update profile
- `DELETE /api/user/account` - Delete account
### App Endpoints
- `GET /api/apps` - List user's apps
- `POST /api/apps` - Create new app
- `GET /api/apps/:appId` - Get app details
- `PUT /api/apps/:appId` - Update app
- `DELETE /api/apps/:appId` - Delete app
### Build Endpoints
- `GET /api/builds` - List user's builds
- `GET /api/builds/:buildId` - Get build details
- `POST /api/builds/upload` - Upload new build
- `DELETE /api/builds/:buildId` - Delete build
### Google Drive Endpoints
- `POST /api/drive/connect` - Initiate OAuth flow
- `POST /api/drive/callback` - Handle OAuth callback
- `GET /api/drive/status` - Check connection status
- `POST /api/drive/upload` - Upload file to Drive
- `DELETE /api/drive/disconnect` - Revoke Drive access
### Configuration Endpoints
- `GET /api/config/:appId` - Generate app configuration
- `GET /api/config/:appId/download` - Download config JSON
### Public Endpoints (For End Users' Apps)
- `GET /api/public/check-update/:appId/:channel` - Check for updates
- `GET /api/public/download/:buildId` - Download build (proxy from Drive)
## ๐จ UI/UX Flow
### Page Structure
```
Website Root
โโโ Public Pages (/)
โ โโโ Home
โ โโโ Features
โ โโโ Pricing
โ โโโ Examples
โ โโโ Docs
โ โโโ About
โ โโโ Contact
โ
โโโ Auth Pages (/auth/)
โ โโโ Login
โ โโโ Signup
โ โโโ Reset Password
โ โโโ Verify Email
โ
โโโ Dashboard (/dashboard/)
โโโ Overview (default)
โโโ Apps
โ โโโ List all apps
โ โโโ Create new app
โ โโโ App details/:appId
โ โโโ Builds list
โ โโโ Configuration
โ โโโ Settings
โโโ Builds
โ โโโ All builds (across all apps)
โ โโโ Upload new build
โโโ Google Drive
โ โโโ Connection status
โ โโโ Connect/disconnect
โโโ Configuration
โ โโโ Generate config for each app
โโโ Settings
โโโ Profile
โโโ Preferences
โโโ Account deletion
```
### Dashboard Layout
```
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Header (sticky) โ
โ Logo | Dashboard | [User Profile โผ] | [Logout] โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ โ โ
โ Sidebar โ Main Content Area โ
โ (nav) โ โ
โ โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ Overview โ โ โ โ
โ โ Apps โ โ Page-specific content โ โ
โ โ Builds โ โ โ โ
โ โ Upload โ โ โ โ
โ โ Drive โ โ โ โ
โ โ Config โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ Settings โ โ
โ โ โ
โ โ โ
โ โ โ
โ โ โ
โโโโโโโโโโโโโโโโดโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
```
## ๐ User Workflows
### Workflow 1: New User Onboarding
1. **Visit website** โ See marketing pages
2. **Click "Get Started"** โ Redirect to /signup
3. **Fill signup form** โ Email + password
4. **Receive verification email** โ Click link
5. **Email verified** โ Redirect to /dashboard
6. **See onboarding guide** โ "Connect Google Drive first"
7. **Connect Google Drive** โ OAuth flow
8. **Create first app** โ Fill app details
9. **Upload first build** โ Upload file
10. **Get configuration** โ Copy config to use in app
### Workflow 2: Upload New Build
1. **Login to dashboard** โ /dashboard
2. **Navigate to Upload** โ /dashboard/upload
3. **Select app** โ Dropdown with user's apps
4. **Choose channel** โ Production/Staging/Development
5. **Fill build details** โ Version, release notes
6. **Select file** โ Drag & drop or file picker
7. **Upload** โ Progress bar shows upload status
8. **Upload to Drive** โ Backend uploads to user's Drive
9. **Save metadata** โ Firestore stores build info
10. **Confirmation** โ Build ready for distribution
### Workflow 3: Configure App for Updates
1. **Navigate to Configuration** โ /dashboard/config
2. **Select app** โ Choose from list
3. **View generated config** โ Display JSON with syntax highlighting
4. **Copy config** โ One-click copy button
5. **Follow integration guide** โ Step-by-step instructions
6. **Test in app** โ User integrates into their app
7. **Verify update works** โ App checks for updates successfully
## ๐ Security Considerations
### Data Protection
- **Firebase Auth** handles password security (bcrypt)
- **Google Drive tokens** encrypted before storing in Firestore
- **HTTPS only** for all communications
- **CORS** properly configured for frontend
- **Rate limiting** on API endpoints
### Access Control
- **User can only access their own data** (Firestore rules enforce)
- **Google Drive files** stored in user's personal Drive (full control)
- **No shared storage** between users
- **Token refresh** handled automatically
### Privacy
- **No access to user's Drive** beyond NativeUpdate folder
- **User can disconnect Drive** anytime (revokes tokens)
- **Account deletion** removes all data (GDPR compliant)
- **Privacy policy** updated to reflect Drive usage
## ๐ Scalability & Performance
### Expected Load
- **Free tier**: 100-1000 users (MVP)
- **Average file size**: 10-50 MB per build
- **Uploads per user**: 5-20 per month
- **API requests**: 100-500 per user per month
### Optimization Strategies
- **Chunked uploads** for large files (>10MB)
- **Firebase Storage** for temporary staging (before Drive upload)
- **Lazy loading** in dashboard (paginate builds list)
- **Caching** of configuration (CDN distribution)
- **Firestore indexes** for efficient queries
### Cost Estimates (Firebase Free Tier)
- **Authentication**: 10k/month free โ
- **Firestore**: 50k reads/20k writes/day free โ
- **Storage**: 5GB free โ
- **Cloud Functions**: 2M invocations/month free โ
- **Google Drive API**: Free (user's quota) โ
**Expected to stay within free tier for MVP**
## ๐งช Testing Strategy
### Unit Tests
- Firebase Functions (API endpoints)
- React components (UI)
- Utility functions (config generation)
### Integration Tests
- Auth flow (signup โ login โ logout)
- Drive integration (connect โ upload โ disconnect)
- Build upload (file โ metadata โ Drive)
### E2E Tests
- Complete user journey (signup โ create app โ upload โ configure)
- Error scenarios (network failures, invalid files)
- Cross-browser testing (Chrome, Safari, Firefox)
### Manual Testing
- Mobile responsiveness
- File upload with various sizes
- Google Drive folder structure
- Configuration accuracy
## ๐
Implementation Timeline
### Phase 1: Foundation (Week 1)
- Setup Firebase project
- Configure authentication
- Create database schema
- Implement security rules
### Phase 2: Authentication (Week 2)
- Build login/signup pages
- Implement auth context
- Add protected routes
- Email verification
### Phase 3: Dashboard (Week 3)
- Create dashboard layout
- Build overview page
- Build apps management
- Navigation components
### Phase 4: Google Drive (Week 4)
- Setup Google Cloud project
- Implement OAuth flow
- Build Drive service
- Test file uploads
### Phase 5: Build Upload (Week 5)
- Create upload UI
- Implement chunked upload
- Save to Drive
- Store metadata
### Phase 6: Configuration (Week 6)
- Build config generator
- Create config UI
- Add download option
- Integration guide
### Phase 7: Testing & Polish (Week 7)
- Bug fixes
- UI polish
- Documentation
- Deployment
**Total: ~7 weeks for full implementation**
## โ
Success Criteria
- [ ] Users can sign up and log in
- [ ] Email verification works
- [ ] Google Drive connects successfully
- [ ] Files upload to user's Drive (not shared storage)
- [ ] Builds metadata stored in Firestore
- [ ] Configuration generates correctly
- [ ] Dashboard is fully functional
- [ ] Mobile responsive
- [ ] Zero security vulnerabilities
- [ ] Privacy policy updated
- [ ] Documentation complete
**Plan Status:** โ
Complete and ready for detailed sub-plans
**Next Steps:** Create detailed plans for each subsystem