Skip to main content

๐Ÿ“ฑ Mobile App Module

๐Ÿ“– Overviewโ€‹

The Mobile App module provides version management and update checking for DashClicks mobile applications (iOS and Android). It enables the backend to notify mobile clients when newer versions are available, supporting both standard releases and variant builds (e.g., beta, production).

File Path: internal/api/v1/mobile-app/

Key Featuresโ€‹

  • Version Checking: Mobile apps query latest available version
  • Platform Support: Separate versions for iOS and Android
  • Build Variants: Support for beta, production, staging builds
  • Update Metadata: Version codes, URLs, release notes, minimum versions
  • Forced Updates: Flag critical updates as mandatory

๏ฟฝ Directory Structureโ€‹

mobile-app/
โ”œโ”€โ”€ ๐Ÿ“„ index.js - Module router
โ”œโ”€โ”€ ๐Ÿ“‚ controllers/
โ”‚ โ””โ”€โ”€ updates.js - Update check controller
โ”œโ”€โ”€ ๐Ÿ“‚ services/
โ”‚ โ””โ”€โ”€ updates.js - Business logic for version queries
โ”œโ”€โ”€ ๐Ÿ“‚ routes/
โ”‚ โ””โ”€โ”€ updates.js - Route definitions
โ””โ”€โ”€ ๐Ÿ“‚ validations/
โ””โ”€โ”€ updates.js - Request validation schemas

๏ฟฝ๐Ÿ—„๏ธ Collections Usedโ€‹

mobile-app.updatesโ€‹

  • Purpose: Store mobile app version information
  • Model: shared/models/mobile-app.updates.js
  • Key Fields:
    • platform (String, enum) - 'ios' or 'android'
    • variant (String, enum) - 'dashclicks' or 'whitelabel'
    • version_code (Number, required) - Incremental build number for comparison
    • is_mandatory (Boolean, default: false) - Force update flag
    • message (String) - Update message or release notes
    • created (Date) - Creation timestamp
    • updated (Date) - Last update timestamp

Unique Index: { platform: 1, variant: 1, version_code: 1 }

๐Ÿ”„ Data Flowโ€‹

Version Check Flowโ€‹

sequenceDiagram
participant MobileApp as Mobile App
participant API as Mobile App API
participant DB as MongoDB

MobileApp->>API: GET /api/v1/mobile-app/updates/latest?platform=android&variant=dashclicks
API->>DB: Find latest update: sort by version_code DESC

alt Update Found
DB-->>API: Latest version document
API->>API: Compare version_codes

alt Newer Version Available
API-->>MobileApp: { version_code, is_mandatory, message }

alt Is Mandatory
MobileApp->>MobileApp: Force update dialog
else Optional Update
MobileApp->>MobileApp: Show update prompt (optional)
end
else Current Version
API-->>MobileApp: { no update needed }
end
else No Update Found
API-->>MobileApp: { error: no version data }
end

๐Ÿ”ง Core Functionsโ€‹

Get Latest Updateโ€‹

Endpoint: GET /api/v1/mobile-app/updates/latest

Query Parameters:

  • platform (String, required) - 'ios' or 'android'
  • variant (String, required) - Build variant identifier

Service: services/updates.js

exports.getLatest = async ({ platform, variant }) => {
return await Updates.findOne(
{ platform, variant },
{},
{ sort: { version_code: -1 } }, // Get highest version code
);
};

Response:

{
"success": true,
"data": {
"id": "507f1f77bcf86cd799439011",
"platform": "android",
"variant": "dashclicks",
"version_code": 251,
"is_mandatory": false,
"message": "Bug fixes and performance improvements",
"created": "2024-01-15T10:30:00.000Z",
"updated": "2024-01-15T10:30:00.000Z"
}
}

Validation (validations/updates.js):

  • platform: Required, enum ['ios', 'android']
  • variant: Required, string

๐Ÿ”€ Integration Pointsโ€‹

Mobile App Initializationโ€‹

When Mobile App Launches:

  1. App reads current version_code from build configuration
  2. Makes API call to /updates/latest with platform and variant
  3. Compares server version_code with local version
  4. If server version is higher:
    • Check is_mandatory flag
    • Show update dialog (forced or optional)
    • Redirect to download_url if user accepts

Example Mobile Logic:

const currentVersionCode = 250;
const response = await fetch(
'/api/v1/mobile-app/updates/latest?platform=android&variant=production',
);
const latestUpdate = response.data;

if (latestUpdate.version_code > currentVersionCode) {
if (latestUpdate.is_mandatory) {
// Block app usage, show forced update dialog
showForceUpdateDialog(latestUpdate);
} else {
// Show optional update prompt
showUpdatePrompt(latestUpdate);
}
}

Minimum Version Enforcementโ€‹

Purpose: Ensure compatibility with backend APIs.

Logic:

  • minimum_version_code specifies oldest supported version
  • Mobile apps below this threshold are blocked from API access
  • Prevents outdated apps from causing errors or security issues

Backend Middleware (hypothetical):

// In authentication middleware
if (req.headers['x-app-version-code'] < minimumVersionCode) {
return res.status(426).json({
error: 'UPDATE_REQUIRED',
message: 'Your app version is no longer supported. Please update.',
download_url: latestUpdate.download_url,
});
}

โš™๏ธ Configurationโ€‹

Platform Valuesโ€‹

  • iOS: 'ios' - For Apple App Store versions
  • Android: 'android' - For Google Play Store versions

Variant Typesโ€‹

Common variants:

  • production - Stable release for general users
  • beta - Beta testing builds
  • staging - Internal testing builds
  • development - Development/debug builds

Version Numberingโ€‹

Version Name: Semantic versioning (e.g., 2.5.1)

  • Major.Minor.Patch format
  • Human-readable, displayed in UI

Version Code: Incremental integer (e.g., 251)

  • Auto-incrementing build number
  • Used for programmatic comparison
  • Always increases with each build

Example Mapping:

  • v2.5.0 โ†’ version_code: 250
  • v2.5.1 โ†’ version_code: 251
  • v2.6.0 โ†’ version_code: 260

โš ๏ธ Important Notesโ€‹

  • ๐Ÿ”ข Simple Version Comparison: Only version_code is used (no version names/strings)
  • ๐Ÿšซ Mandatory Updates: Use is_mandatory: true for critical security/compatibility fixes
  • ๐Ÿ” No Authentication: Update check endpoint typically doesn't require auth (pre-login)
  • ๐Ÿ“ฆ Unique Versions: Each platform/variant/version_code combination is unique (enforced by index)
  • ๐Ÿ“ฑ Two Variants: System supports dashclicks and whitelabel apps separately
  • ๏ฟฝ Message Field: Use for release notes or update prompts shown to users

๐Ÿงช Edge Cases & Special Handlingโ€‹

Case: No Version Record Foundโ€‹

Condition: Query for platform/variant that doesn't exist in database

Handling:

  • Service returns null
  • Mobile app treats as "no update available"
  • Logs warning for monitoring

Case: Corrupt Version Dataโ€‹

Condition: version_code or version_name missing/invalid

Handling:

  • Schema validation enforces required fields
  • Unique index prevents duplicate entries
  • Backend validation ensures data integrity

Case: Downgrade Attemptโ€‹

Condition: Server version_code is lower than mobile app version

Handling:

  • Mobile app should ignore (don't show downgrade prompt)
  • Indicates beta user checking production variant
  • Or pre-release build checking stable channel

Case: Multiple Variants on Same Deviceโ€‹

Condition: User switches between beta and production builds

Handling:

  • Each build queries its own variant
  • Separate update checking per variant
  • No cross-contamination of version data

๐Ÿ“ˆ Performance Considerationsโ€‹

Indexingโ€‹

Unique Index:

{ platform: 1, variant: 1, version_code: 1 }

Query Optimization:

  • Index supports: findOne({ platform, variant }) with sort by version_code
  • Very fast lookup (indexed fields + sort)
  • Minimal collection size (few documents per platform/variant)

Caching Strategyโ€‹

Client-Side:

  • Cache update check response for 6-24 hours
  • Only re-check on app restart or manual refresh
  • Reduces API load

Server-Side:

  • Update data changes infrequently (days/weeks)
  • Consider in-memory cache with 1-hour TTL
  • Preload all variants into cache on service startup

Collection Sizeโ€‹

Expected Size: Small (< 100 documents)

  • ~10 versions per variant (keep history)
  • 2-3 variants per platform
  • 2 platforms
  • Total: ~60-80 documents maximum

๐Ÿ“Š Usage Examplesโ€‹

Creating New Version Recordโ€‹

// Admin panel or deployment script
await MobileAppUpdate.create({
platform: 'android',
variant: 'production',
version_name: '2.5.1',
version_code: 251,
download_url: 'https://play.google.com/store/apps/details?id=com.dashclicks',
release_notes: 'Fixed crash on conversation view\nImproved notification handling',
minimum_version_code: 240,
is_mandatory: false,
});

Forcing Critical Updateโ€‹

// Security patch - force all users to update
await MobileAppUpdate.create({
platform: 'ios',
variant: 'production',
version_name: '2.5.2',
version_code: 252,
download_url: 'https://apps.apple.com/app/dashclicks/id123456789',
release_notes: 'Critical security update - please install immediately',
minimum_version_code: 252, // Force update by raising minimum
is_mandatory: true,
});

Beta Channel Releaseโ€‹

// Beta version ahead of production
await MobileAppUpdate.create({
platform: 'android',
variant: 'beta',
version_name: '2.6.0-beta.1',
version_code: 260,
download_url: 'https://play.google.com/apps/testing/com.dashclicks',
release_notes: 'Testing new conversation features',
minimum_version_code: 240,
is_mandatory: false,
});

Last Updated: 2025-01-08
Module Path: internal/api/v1/mobile-app/
Main Route: GET /api/v1/mobile-app/updates/latest
Collection: mobile-app.updates

๐Ÿ’ฌ

Documentation Assistant

Ask me anything about the docs

Hi! I'm your documentation assistant. Ask me anything about the docs!

I can help you with:
- Code examples
- Configuration details
- Troubleshooting
- Best practices

Try asking: How do I configure the API?
09:31 AM