alloy-guides
Alloy MVC framework guide
Reference for building Titanium mobile applications with the Alloy MVC framework and Backbone.js.
Project detection
️ℹ️ AUTO-DETECTS ALLOY PROJECTS This skill automatically detects Alloy projects when invoked and provides framework-specific guidance.
Detection occurs automatically - no manual command needed.
Alloy project indicators:
app/folder (MVC structure)app/views/,app/controllers/foldersapp/models/folderBehavior based on detection:
- Alloy detected → Provides Alloy MVC documentation, Backbone.js patterns, TSS styling, widgets
- Not detected → Indicates this skill is for Alloy projects only, does not suggest Alloy-specific features
Quick reference
| Topic | Reference File |
|---|---|
| Core concepts, MVC, Backbone.js, conventions | CONCEPTS.md |
| Controllers, events, conditional code, arguments | CONTROLLERS.md |
| Models, collections, data binding, migrations | MODELS.md |
| XML markup, elements, attributes, events | VIEWS_XML.md |
| TSS styling, themes, platform-specific styles | VIEWS_STYLES.md |
| Dynamic styles, autostyle, runtime styling | VIEWS_DYNAMIC.md |
| Controllers-less views, patterns | VIEWS_WITHOUT_CONTROLLERS.md |
| Creating and using widgets | WIDGETS.md |
| CLI commands, code generation | CLI_TASKS.md |
| PurgeTSS integration (optional addon) | PURGETSS.md |
Project structure
Standard Alloy project structure:
app/
├── alloy.js # Initializer file
├── alloy.jmk # Build configuration
├── config.json # Project configuration
├── assets/ # Images, fonts, files (→ Resources/)
├── controllers/ # Controller files (.js)
├── i18n/ # Localization strings (→ i18n/)
├── lib/ # CommonJS modules
├── migrations/ # DB migrations (<DATETIME>_<name>.js)
├── models/ # Model definitions (.js)
├── platform/ # Platform-specific resources (→ platform/)
├── specs/ # Test-only files (dev/test only)
├── styles/ # TSS files (.tss)
├── themes/ # Theme folders
├── views/ # XML markup files (.xml)
└── widgets/ # Widget components
MVC quick start
Controller (app/controllers/index.js):
function doClick(e) {
alert($.label.text);
}
$.index.open();
View (app/views/index.xml):
<Alloy>
<Window class="container">
<Label id="label" onClick="doClick">Hello, World</Label>
</Window>
</Alloy>
Style (app/styles/index.tss):
".container": { backgroundColor: "white" }
"Label": { color: "#000" }
Key concepts
- Models/Collections: Backbone.js objects with sync adapters (sql, properties)
- Views: XML markup with TSS styling
- Controllers: JavaScript logic with
$reference to view components - Data Binding: Bind collections to UI components automatically
- Widgets: Reusable components with MVC structure
- Conventions: File naming and placement drive code generation
Critical rules
Platform-specific properties in TSS
🚨 CRITICAL: Platform-specific properties require modifiers Using
Ti.UI.iOS.*orTi.UI.Android.*properties in TSS without platform modifiers causes cross-platform compilation failures.Example of the failure:
// WRONG - Adds Ti.UI.iOS to Android project "#mainWindow": { statusBarStyle: Ti.UI.iOS.StatusBar.LIGHT_CONTENT // FAILS on Android! }Correct approach - use platform modifiers:
// CORRECT - Only adds to iOS "#mainWindow[platform=ios]": { statusBarStyle: Ti.UI.iOS.StatusBar.LIGHT_CONTENT } // CORRECT - Only adds to Android "#mainWindow[platform=android]": { actionBar: { displayHomeAsUp: true } }Properties that always require platform modifiers:
- iOS:
statusBarStyle,modalStyle,modalTransitionStyle, anyTi.UI.iOS.*- Android:
actionBarconfig, anyTi.UI.Android.*constantAvailable modifiers:
[platform=ios],[platform=android],[formFactor=handheld],[formFactor=tablet],[if=Alloy.Globals.customVar]For more platform-specific patterns, see Code conventions (ti-expert) or Platform UI guides (ti-ui).
Common patterns
Creating a model
alloy generate model book sql title:string author:string
Data binding
<Collection src="book" />
<TableView dataCollection="book">
<TableViewRow title="{title}" />
</TableView>
Platform-specific code
if (OS_IOS) {
// iOS-only code
}
if (OS_ANDROID) {
// Android-only code
}
Widget usage
<Widget src="mywidget" id="foo" />
Compilation process
- Cleanup: Resources folder cleaned
- Build Config: alloy.jmk loaded (pre:load task)
- Framework Files: Backbone.js, Underscore.js, sync adapters copied
- MVC Generation: Models, widgets, views, controllers compiled to JS
- Main App: app.js generated from template
- Optimization: UglifyJS optimization, platform-specific code removal
References
Read detailed documentation from the reference files listed above based on your specific task.
Related skills
For tasks beyond Alloy MVC basics, use these complementary skills:
| Task | Use This Skill |
|---|---|
| Modern architecture, services, patterns | ti-expert |
| Alloy CLI, config files, debugging errors | alloy-howtos |
| Utility-first styling with PurgeTSS (optional) | purgetss |
| Native features (location, push, media) | ti-howtos |
More from maccesar/titanium-sdk-skills
alloy-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.
7ti-expert
Titanium SDK architecture and implementation expert. Use when designing, reviewing, analyzing, or examining Titanium project structure (Alloy or Classic), creating controllers/views/services, choosing models vs collections, implementing communication patterns, handling memory cleanup, testing, auditing code, or migrating legacy apps. Automatically identifies project type.
4