search-dataflow
Search app data flow - query flow diagram (user input → debounce → alias check → provider dispatch → aggregate → rank → UI), state management patterns (mutableStateOf, mutableStateListOf, StateFlow, SharedFlow), settings JSON persistence in SharedPreferences.
Installation
Follow the repository instructions for this skill and your agent. Review the files and dependencies before adding it to your workflow.
View source ↗GuidesSkill instructions
Data Flow
Query Flow Diagram
┌─────────────────────────────────────────────────────────────────────────────┐
│ SEARCH QUERY FLOW │
├─────────────────────────────────────────────────────────────────────────────┤
│ │
│ ┌───────────────┐ │
│ │ User Types │ │
│ │ in SearchBar │ │
│ └───────┬───────┘ │
│ │ │
│ ▼ │
│ ┌───────────────────────┐ │
│ │ Query Object Created │ Query(text, timestamp) │
│ └───────────┬───────────┘ │
│ │ │
│ ▼ │
│ ┌───────────────────────┐ │
│ │ Debounce (50ms) │ Prevents excessive queries while typing │
│ └───────────┬───────────┘ │
│ │ │
│ ┌───────┴───────────────────────┐ │
│ │ │ │
│ ▼ ▼ │
│ ┌─────────────────┐ ┌─────────────────────────┐ │
│ │ Alias Check │ │ Provider Dispatch │ │
│ │ │ │ │ │
│ │ Does query │ │ For each enabled │ │
│ │ match an alias? │ │ provider where │ │
│ │ │ │ canHandle(query) = true │ │
│ └────────┬────────┘ └────────────┬────────────┘ │
│ │ │ │
│ │ yes │ │
│ ▼ ▼ │
│ ┌─────────────────┐ ┌─────────────────────────┐ │
│ │ buildAliasResult│ │ supervisorScope { │ │
│ │ () │ │ async { p.query(q) } │ Parallel execution │
│ │ │ │ } │ │
│ └────────┬────────┘ └────────────┬────────────┘ │
│ │ │ │
│ └───────────┬───────────────────┘ │
│ │ │
│ ▼ │
│ ┌───────────────────────┐ │
│ │ Aggregate Results │ Combine all provider results │
│ └───────────┬───────────┘ │
│ │ │
│ ▼ │
│ ┌───────────────────────┐ │
│ │ Apply Ranking │ │
│ │ │ │
│ │ 1. Frequency-based │ (if enabled) │
│ │ 2. Provider order │ (fallback) │
│ └───────────┬───────────┘ │
│ │ │
│ ▼ │
│ ┌───────────────────────┐ │
│ │ Update StateList │ providerResults.clear() + addAll() │
│ └───────────┬───────────┘ │
│ │ │
│ ▼ │
│ ┌───────────────────────┐ │
│ │ ItemsList Recomposes │ UI updates with new results │
│ └───────────────────────┘ │
│ │
└─────────────────────────────────────────────────────────────────────────────┘
State Management
| Type | Usage | Example |
|---|---|---|
mutableStateOf |
Simple reactive state | var query by mutableStateOf("") |
mutableStateListOf |
Observable lists | val results = mutableStateListOf<Result>() |
StateFlow |
Repository → UI reactive binding | val settings: StateFlow<Settings> |
SharedFlow |
One-shot events (refresh signals) | val refreshSignal: SharedFlow<Unit> |
State Management Guidelines
-
Settings → StateFlow in Repository:
val setting: StateFlow<T> = repository.setting val value by setting.collectAsState() -
Local UI State → mutableStateOf:
var isExpanded by remember { mutableStateOf(false) } -
Observable Lists → mutableStateListOf:
val results = remember { mutableStateListOf<ProviderResult>() } -
One-shot Events → SharedFlow:
val refreshSignal = MutableSharedFlow<Unit>()
Settings Persistence
Settings are stored as JSON in SharedPreferences:
// Example: WebSearchSettings storage
// Data class
data class WebSearchSettings(
val defaultSiteId: String,
val sites: List<WebSearchSite>,
val quicklinks: List<Quicklink>
)
// Persistence in ProviderSettingsRepository
private val prefs = context.getSharedPreferences("provider_settings", MODE_PRIVATE)
fun saveWebSearchSettings(settings: WebSearchSettings) {
prefs.edit().putString(KEY_WEB_SEARCH, Json.encodeToString(settings)).apply()
_webSearchSettings.value = settings
}
Key Files
| Purpose | Location |
|---|---|
| Query model | provider/model/Query.kt |
| Provider interface | provider/Provider.kt |
| Result model | provider/ProviderResult.kt |
| Settings persistence | settings/ProviderSettingsRepository.kt |
| Ranking logic | settings/ProviderRankingRepository.kt |
Related Skills
-
search-provider- Provider interface and lifecycle -
search-repository- Repository layer patterns
Examples
Read the usage examples in the source repository.
View source ↗Source history
- Indexed on
- 2026-01-20
- Index updated
- 2026-02-03
- Branch
- main
Index and sync dates describe this directory. View the source repository for code history.
GitHub ↗chat Comments (0)
Sign in to join the discussion and leave a comment.
No comments yet. Be the first to share your thoughts!