alloy-expert
Titanium Alloy Expert
Complete architectural and implementation guidance for building scalable, maintainable Titanium Alloy applications with PurgeTSS styling.
Table of Contents
- Titanium Alloy Expert
Workflow
- Architecture: Define structure (
lib/api,lib/services,lib/helpers) - Data Strategy: Choose Models (SQLite) or Collections (API)
- Contracts: Define I/O specs for cross-layer communication
- Implementation: Write XML views + ES6+ controllers
- Quality: Testing, error handling, logging, performance
- Cleanup: Implement
cleanup()pattern for memory management
Quick Start Example
Minimal example following all conventions:
View (views/user/card.xml)
<Alloy>
<View class="m-2 rounded-xl bg-white shadow-md">
<View class="horizontal m-3 w-screen">
<Label class="fa-solid fa-user text-2xl text-blue-500" />
<Label id="name" class="ml-3 text-lg font-bold" />
</View>
<Button class="mx-3 mb-3 h-10 w-screen rounded-md bg-blue-600 text-white"
title="L('view_profile')"
onClick="onViewProfile"
/>
</View>
</Alloy>
Controller (controllers/user/card.js)
const { Navigation } = require('lib/services/navigation')
function init() {
const user = $.args.user
$.name.text = user.name
}
function onViewProfile() {
Navigation.open('user/profile', { userId: $.args.user.id })
}
function cleanup() {
$.destroy()
}
$.cleanup = cleanup
Service (lib/services/navigation.js)
exports.Navigation = {
open(route, params = {}) {
const controller = Alloy.createController(route, params)
const view = controller.getView()
view.addEventListener('close', function() {
if (controller.cleanup) controller.cleanup()
})
view.open()
return controller
}
}
Code Standards (Low Freedom)
- NO SEMICOLONS: Let ASI handle it
- MODERN SYNTAX:
const/let, destructuring, template literals - applyProperties(): Batch UI updates to minimize bridge crossings
- MEMORY CLEANUP: Every controller with global listeners MUST have
$.cleanup = cleanup - ERROR HANDLING: Use AppError classes, log with context, never swallow errors
- TESTABLE: Inject dependencies, avoid hard coupling
PurgeTSS Rules (Low Freedom)
| WRONG | CORRECT | Why |
|---|---|---|
flex-row |
horizontal |
Flexbox not supported |
flex-col |
vertical |
Flexbox not supported |
p-4 on View |
m-4 on children |
No padding on containers |
justify-* |
margins/positioning | Flexbox not supported |
items-center (for centering) |
layout + sizing | Different meaning in Titanium |
rounded-full (for circle) |
rounded-full-12 |
Need size suffix (12×4=48px) |
border-[1px] |
border-(1) |
Parentheses, not brackets |
Note on w-full vs w-screen:
w-full→width: '100%'(100% of parent container) - exists and validw-screen→width: Ti.UI.FILL(fills all available space) - use for full-width elements
Quick Decision Matrix
| Question | Answer |
|---|---|
| Where does API call go? | lib/api/ |
| Where does business logic go? | lib/services/ |
| Where do I store auth tokens? | Keychain (iOS) / KeyStore (Android) via service |
| Models or Collections? | Collections for API data, Models for SQLite persistence |
| Ti.App.fireEvent or EventBus? | Always EventBus (Backbone.Events) |
| Direct navigation or service? | Always Navigation service (auto cleanup) |
| Manual TSS or PurgeTSS? | Always PurgeTSS utility classes |
| Controller 100+ lines? | Extract logic to services |
Reference Guides (Progressive Disclosure)
Architecture
- Structure & Organization: Models vs Collections, folder maps, styling strategies, automatic cleanup
- ControllerAutoCleanup.js: Drop-in utility for automatic controller cleanup (prevents memory leaks)
- Architectural Patterns: Repository, Service Layer, Event Bus, Factory, Singleton
- Contracts & Communication: Layer interaction examples and JSDoc specs
- Anti-Patterns: Fat controllers, flexbox classes, memory leaks, direct API calls
Implementation
- Code Conventions: ES6 features, PurgeTSS usage, accessibility
- Controller Patterns: Templates, animation, dynamic styling
- Examples: API clients, SQL models, full screen examples
Quality & Reliability
- Testing: Unit testing, mocking patterns, controller testing, test helpers
- Error Handling & Logging: AppError classes, Logger service, validation
Performance & Security
- Performance Patterns: ListView, bridge optimization, memory management, lazy loading
- Security Patterns: Token storage, certificate pinning, encryption, OWASP
- State Management: Centralized store, reactive patterns, synchronization
Migration
- Migration Patterns: Step-by-step guide for modernizing legacy apps
Specialized Titanium Skills
For specific feature implementations, defer to these specialized skills:
| Task | Use This Skill |
|---|---|
| PurgeTSS setup, advanced styling, animations | purgetss |
| Location, Maps, Push Notifications, Media APIs | ti-howtos |
| UI layouts, ListViews, gestures, platform-specific UI | ti-ui |
| Alloy CLI, configuration files, debugging | alloy-howtos |
| Alloy MVC complete reference | alloy-guides |
| Hyperloop, native modules, app distribution | ti-guides |
Guiding Principles
- Thin Controllers: Max 100 lines. Delegate to services.
- Single Source of Truth: One state store, not scattered Properties.
- Always Cleanup: Every listener added = listener removed in
cleanup(). - Never Block UI: All API/DB calls are async with loading states.
- Fail Gracefully: Centralized error handling with user-friendly messages.
Response Format
For Architecture Questions:
- Decision: What should be done
- Justification: Technical rationale
- Structure: File and folder placement
- Contract: Clear I/O specification
For Implementation Tasks:
- Code First: Show implementation immediately
- Minimal Comments: Explain only the "Why" for complex logic
- No Explanations: Deliver exactly what was asked concisely
More from maccesar/titanium-sdk-skills
alloy-guides
Titanium Alloy MVC official framework reference. Use when working with, reviewing, analyzing, or examining Alloy models, views, controllers, Backbone.js data binding, TSS styling, widgets, Alloy CLI, sync adapters, migrations, or MVC compilation. AUTO-DETECT: If the project has an app/views/ + app/controllers/ + app/styles/ folder structure, it is an Alloy project — invoke this skill BEFORE editing XML views, JS controllers, or TSS styles. Alloy XML is NOT HTML; TSS is NOT CSS; controllers follow Alloy-specific patterns, not web MVC.
9alloy-howtos
Titanium Alloy CLI and configuration guide. Use when creating, reviewing, analyzing, or examining Alloy projects, running alloy commands (new, generate, compile), configuring alloy.jmk or config.json, debugging compilation errors, creating conditional views, using Backbone.Events for communication, or writing custom XML tags. AUTO-DETECT: If the project has app/views/ + app/controllers/ structure and the task involves Alloy CLI commands, project configuration, or build issues, invoke this skill first.
9ti-ui
Titanium SDK UI/UX patterns and components expert. Use when working with, reviewing, analyzing, or examining Titanium layouts, ListView/TableView performance optimization, event handling and bubbling, gestures (swipe, pinch), animations, accessibility (VoiceOver/TalkBack), orientation changes, custom fonts/icons, app icons/splash screens, or platform-specific UI (Action Bar, Navigation Bar).
7purgetss
Titanium PurgeTSS utility-first styling toolkit. Use when styling, reviewing, analyzing, or examining Titanium UI with utility classes, configuring config.cjs, creating dynamic components with $.UI.create(), building animations, using grid layouts, setting up icon fonts, or working with TSS styles. Never suggest other CSS framework classes - verify in class-index.md first.
7ti-guides
Titanium SDK official fundamentals and configuration guide. Use when working with, reviewing, analyzing, or examining Titanium projects, Hyperloop native access, app distribution (App Store/Google Play), tiapp.xml configuration, CLI commands, memory management, bridge optimization, CommonJS modules, SQLite transactions, or coding standards. Applies to both Alloy and Classic projects.
7ti-howtos
Titanium SDK native feature integration guide. Use when implementing, reviewing, analyzing, or examining Titanium location services, maps (Google Maps v2, Map Kit), push notifications (APNs, FCM), camera/gallery, media APIs, SQLite databases, HTTPClient networking, WKWebView, Android Intents, background services, iOS Keychain/iCloud, WatchKit/Siri integration, or CI/CD with Fastlane and Appium.
7