Titanium expert
Practical architecture and implementation guidance for Titanium SDK apps (Alloy and Classic). Focus on maintainability, clear boundaries, and low-friction testing.
Project detection
️ℹ️ Auto-detects Alloy vs Classic projects
This skill detects project type automatically and tailors guidance.
Alloy indicators:
app/ folder (MVC structure)
app/views/, app/controllers/ folders
alloy.jmk or config.json files
Classic indicators:
Resources/ folder with app.js at root
- No
app/ folder structure
Behavior:
- Alloy detected: provides Alloy MVC patterns and Backbone.js guidance
- Classic detected: avoids Alloy-only patterns and recommends Classic options or migration
- Unknown: asks the user to clarify the project type
Workflow
- Architecture: define structure by technical type with flat folders (
lib/api, lib/services, lib/actions, lib/repositories, lib/helpers)
- Data strategy: choose Models (SQLite) or Collections (API)
- Contracts: define I/O specs between layers
- Implementation: write XML views and ES6+ controllers
- Quality: testing, error handling, logging, performance
- Cleanup: implement a
cleanup() pattern for memory management
Architectural Maturity Tiers
Choose the appropriate tier based on project complexity:
Tier 1: Basic (Rapid Prototyping)
- Best for: Simple utility apps or developers transitioning from Classic.
- Structure: Logic resides directly within
index.js.
- UI Access: Direct usage of the
$ object throughout the file.
- Pros: Zero boilerplate, extremely fast start.
- Cons: Unmaintainable beyond 500 lines of code.
Tier 2: Intermediate (Modular Alloy)
- Best for: Standard commercial applications.
- Structure: Business logic extracted to
app/lib/ using a flat technical-type organization.
- Pattern: Slim Controllers that
require() services.
- Memory: Mandatory implementation of
$.cleanup = cleanup.
Tier 3: Advanced / Enterprise (Service-Oriented)
- Best for: High-complexity apps (IDEs like TiDesigner, multi-state platforms).
- Architecture: Dependency Injection via a
ServiceRegistry.
- ID Scoping: Services do not receive the entire
$ object. They receive a "Scoped UI" object containing only relevant IDs.
- Cognitive Load: "Black Box" logic—encapsulated units that reduce mental fatigue.
- Observability: Structured logging with a mandatory
service context.
Detailed examples and full implementation samples are available in: Architectural Tiers Detail
Organization policy (low freedom)
- Use technical-type organization in
lib (for example: api, services, actions, repositories, helpers, policies, providers).
- Keep
lib flat and predictable: lib/<type>/<file>.js only.
- Do not recommend deep nesting like
lib/services/auth/session/login.js.
- Keep UI layers aligned by screen (
controllers/, views/, styles/) and avoid unnecessary depth.
Code standards (low freedom)
- No semicolons: let ASI handle it
- Modern syntax:
const/let, destructuring, template literals
- Prefer stable property ordering in JS objects and
applyProperties() calls
- Default to alphabetical property order when it does not break a meaningful semantic grouping
applyProperties(): batch UI updates to reduce bridge crossings
- Memory cleanup: any controller with global listeners must set
$.cleanup = cleanup
- Error handling: use AppError classes, log with context, never swallow errors
- Testable code: inject dependencies, avoid hard coupling
Titanium style sheets rules (low freedom)
🚨 Critical: platform-specific properties require modifiers
Using Ti.UI.iOS.* or Ti.UI.Android.* properties without platform modifiers breaks cross-platform builds.
Example of the damage:
// Wrong: adds Ti.UI.iOS to Android project
"#mainWindow": {
statusBarStyle: Ti.UI.iOS.StatusBar.LIGHT_CONTENT
}
Correct: always use platform modifiers
// Correct: only adds to iOS
"#mainWindow[platform=ios]": {
statusBarStyle: Ti.UI.iOS.StatusBar.LIGHT_CONTENT
}
Properties that always need platform modifiers:
- iOS:
statusBarStyle, modalStyle, modalTransitionStyle, any Ti.UI.iOS.*
- Android:
actionBar configuration, any Ti.UI.Android.* constant
Available modifiers: [platform=ios], [platform=android], [formFactor=handheld], [formFactor=tablet], [if=Alloy.Globals.customVar]
For more platform-specific patterns, see the ti-ui skill.
Titanium layout system:
- Three layout modes:
layout: 'horizontal', layout: 'vertical', and composite (default, no layout needed)
- No padding on container Views: use margins on children instead
width: Ti.UI.FILL fills available space (preferred), width: '100%' = 100% of parent
height: Ti.UI.SIZE wraps content, height: Ti.UI.FILL fills available space
Alloy builtins quick reference
Key builtins: OS_IOS/OS_ANDROID (compile-time), Alloy.CFG (config.json), Alloy.Globals (shared state), $.args (controller params), $.destroy() (cleanup bindings), platform="ios" / formFactor="tablet" (XML conditionals).
For the complete reference with examples, see Alloy builtins and globals.
Quick decision matrix
| Question |
Answer |
| How to create a new Alloy project? |
ti create -t app --alloy (not --classic + alloy new) |
| Fastest way to build? |
tn <recipe> (using TiNy CLI wrapper) |
| Controller > 100 lines? |
Extract to Tier 2 (Services) |
| More than 50 IDs in XML? |
Use Tier 3 (ID Scoping) |
| Where does API call go? |
lib/api/ |
| Where does business logic go? |
lib/services/ |
How deep should lib folders be? |
One level: lib/<type>/<file>.js |
| 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) |
| Inline styles or TSS files? |
Always TSS files (per-controller + app.tss for global) |
Reference guides (progressive disclosure)
Architecture & Patterns
- Architectural Tiers Detail
- Architectural Patterns (Factory, Singleton, Repository)
- Structure & Organization
- Contracts & Communication
- State Management
- Anti-patterns to Avoid
- Adaptive Layouts (responsive breakpoints, tablet/foldable/desktop support, Android 17 resizability compliance)
Implementation & API
- Alloy Builtins & Globals
- Code Conventions
- Controller Patterns
- Theming & Dark Mode
- Migration Patterns
- Examples Collection
Quality & Performance
- Performance Optimization
- ListView & ScrollView Performance
- Error Handling & Logging
- Unit & Integration Testing
- E2E Testing & CI/CD
Security
- Security Fundamentals
- Device Security
Tools
Converted and distributed by TomeVault — claim your Tome and manage your conversions.
1---2name: maccesar-titools-ti-expert3description: Titanium expert4---56# Titanium expert78Practical architecture and implementation guidance for Titanium SDK apps (Alloy and Classic). Focus on maintainability, clear boundaries, and low-friction testing.910## Project detection1112> **️ℹ️ Auto-detects Alloy vs Classic projects**13> This skill detects project type automatically and tailors guidance.14>15> Alloy indicators:16> - `app/` folder (MVC structure)17> - `app/views/`, `app/controllers/` folders18> - `alloy.jmk` or `config.json` files19>20> Classic indicators:21> - `Resources/` folder with `app.js` at root22> - No `app/` folder structure23>24> Behavior:25> - Alloy detected: provides Alloy MVC patterns and Backbone.js guidance26> - Classic detected: avoids Alloy-only patterns and recommends Classic options or migration27> - Unknown: asks the user to clarify the project type2829## Workflow30311. Architecture: define structure by technical type with flat folders (`lib/api`, `lib/services`, `lib/actions`, `lib/repositories`, `lib/helpers`)322. Data strategy: choose Models (SQLite) or Collections (API)333. Contracts: define I/O specs between layers344. Implementation: write XML views and ES6+ controllers355. Quality: testing, error handling, logging, performance366. Cleanup: implement a `cleanup()` pattern for memory management3738## Architectural Maturity Tiers3940Choose the appropriate tier based on project complexity:4142### Tier 1: Basic (Rapid Prototyping)43- **Best for**: Simple utility apps or developers transitioning from Classic.44- **Structure**: Logic resides directly within `index.js`.45- **UI Access**: Direct usage of the `$` object throughout the file.46- **Pros**: Zero boilerplate, extremely fast start.47- **Cons**: Unmaintainable beyond 500 lines of code.4849### Tier 2: Intermediate (Modular Alloy)50- **Best for**: Standard commercial applications.51- **Structure**: Business logic extracted to `app/lib/` using a flat technical-type organization.52- **Pattern**: Slim Controllers that `require()` services.53- **Memory**: Mandatory implementation of `$.cleanup = cleanup`.5455### Tier 3: Advanced / Enterprise (Service-Oriented)56- **Best for**: High-complexity apps (IDEs like TiDesigner, multi-state platforms).57- **Architecture**: Dependency Injection via a `ServiceRegistry`.58- **ID Scoping**: Services do not receive the entire `$` object. They receive a "Scoped UI" object containing only relevant IDs.59- **Cognitive Load**: "Black Box" logic—encapsulated units that reduce mental fatigue.60- **Observability**: Structured logging with a mandatory `service` context.6162Detailed examples and full implementation samples are available in: [Architectural Tiers Detail](references/architecture-tiers.md)6364## Organization policy (low freedom)6566- Use technical-type organization in `lib` (for example: `api`, `services`, `actions`, `repositories`, `helpers`, `policies`, `providers`).67- Keep `lib` flat and predictable: `lib/<type>/<file>.js` only.68- Do not recommend deep nesting like `lib/services/auth/session/login.js`.69- Keep UI layers aligned by screen (`controllers/`, `views/`, `styles/`) and avoid unnecessary depth.707172## Code standards (low freedom)7374- No semicolons: let ASI handle it75- Modern syntax: `const/let`, destructuring, template literals76- Prefer stable property ordering in JS objects and `applyProperties()` calls77- Default to alphabetical property order when it does not break a meaningful semantic grouping78- `applyProperties()`: batch UI updates to reduce bridge crossings79- Memory cleanup: any controller with global listeners must set `$.cleanup = cleanup`80- Error handling: use AppError classes, log with context, never swallow errors81- Testable code: inject dependencies, avoid hard coupling8283## Titanium style sheets rules (low freedom)8485> **🚨 Critical: platform-specific properties require modifiers**86> Using `Ti.UI.iOS.*` or `Ti.UI.Android.*` properties without platform modifiers breaks cross-platform builds.87>88> Example of the damage:89> ```tss90> // Wrong: adds Ti.UI.iOS to Android project91> "#mainWindow": {92> statusBarStyle: Ti.UI.iOS.StatusBar.LIGHT_CONTENT93> }94> ```95>96> Correct: always use platform modifiers97> ```tss98> // Correct: only adds to iOS99> "#mainWindow[platform=ios]": {100> statusBarStyle: Ti.UI.iOS.StatusBar.LIGHT_CONTENT101> }102> ```103>104> Properties that always need platform modifiers:105> - iOS: `statusBarStyle`, `modalStyle`, `modalTransitionStyle`, any `Ti.UI.iOS.*`106> - Android: `actionBar` configuration, any `Ti.UI.Android.*` constant107>108> Available modifiers: `[platform=ios]`, `[platform=android]`, `[formFactor=handheld]`, `[formFactor=tablet]`, `[if=Alloy.Globals.customVar]`109>110> For more platform-specific patterns, see the `ti-ui` skill.111112Titanium layout system:113- Three layout modes: `layout: 'horizontal'`, `layout: 'vertical'`, and composite (default, no `layout` needed)114- No padding on container Views: use margins on children instead115- `width: Ti.UI.FILL` fills available space (preferred), `width: '100%'` = 100% of parent116- `height: Ti.UI.SIZE` wraps content, `height: Ti.UI.FILL` fills available space117118## Alloy builtins quick reference119120Key builtins: `OS_IOS`/`OS_ANDROID` (compile-time), `Alloy.CFG` (config.json), `Alloy.Globals` (shared state), `$.args` (controller params), `$.destroy()` (cleanup bindings), `platform="ios"` / `formFactor="tablet"` (XML conditionals).121122For the complete reference with examples, see [Alloy builtins and globals](references/alloy-builtins.md).123124## Quick decision matrix125126| Question | Answer |127| ---------------------------------- | -------------------------------------------------------------- |128| How to create a new Alloy project? | `ti create -t app --alloy` (not `--classic` + `alloy new`) |129| Fastest way to build? | `tn <recipe>` (using TiNy CLI wrapper) |130| Controller > 100 lines? | Extract to Tier 2 (Services) |131| More than 50 IDs in XML? | Use Tier 3 (ID Scoping) |132| Where does API call go? | `lib/api/` |133| Where does business logic go? | `lib/services/` |134| How deep should `lib` folders be? | One level: `lib/<type>/<file>.js` |135| Where do I store auth tokens? | Keychain (iOS) / KeyStore (Android) via service |136| Models or Collections? | Collections for API data, Models for SQLite persistence |137| Ti.App.fireEvent or EventBus? | Always EventBus (Backbone.Events) |138| Direct navigation or service? | Always Navigation service (auto cleanup) |139| Inline styles or TSS files? | Always TSS files (per-controller + `app.tss` for global) |140141## Reference guides (progressive disclosure)142143### Architecture & Patterns144- [Architectural Tiers Detail](references/architecture-tiers.md)145- [Architectural Patterns](references/patterns.md) (Factory, Singleton, Repository)146- [Structure & Organization](references/alloy-structure.md)147- [Contracts & Communication](references/contracts.md)148- [State Management](references/state-management.md)149- [Anti-patterns to Avoid](references/anti-patterns.md)150- [Adaptive Layouts](references/adaptive-layouts.md) (responsive breakpoints, tablet/foldable/desktop support, Android 17 resizability compliance)151152### Implementation & API153- [Alloy Builtins & Globals](references/alloy-builtins.md)154- [Code Conventions](references/code-conventions.md)155- [Controller Patterns](references/controller-patterns.md)156- [Theming & Dark Mode](references/theming.md)157- [Migration Patterns](references/migration-patterns.md)158- [Examples Collection](references/examples.md)159160### Quality & Performance161- [Performance Optimization](references/performance-optimization.md)162- [ListView & ScrollView Performance](references/performance-listview.md)163- [Error Handling & Logging](references/error-handling.md)164- [Unit & Integration Testing](references/testing-unit.md)165- [E2E Testing & CI/CD](references/testing-e2e-ci.md)166167### Security168- [Security Fundamentals](references/security-fundamentals.md)169- [Device Security](references/security-device.md)170171### Tools172- [CLI Expert & TiNy](references/cli-expert.md)173174---175> Converted and distributed by [TomeVault](https://tomevault.io/claim/maccesar) — claim your Tome and manage your conversions.176<!-- tomevault:4.0:skill_md:2026-04-13 -->