SMAPI Best Practices
When to Use This Skill
Use this skill for Stardew Valley SMAPI C# mod work where maintainability, compatibility, robustness, or proven architecture patterns matter:
- Designing a new SMAPI mod architecture.
- Implementing or reviewing
ModEntry, events, config, content edits, i18n, commands, APIs, integrations, multiplayer, or migrations.
- Refactoring an existing mod toward cleaner lifecycle handling and service/manager separation.
- Diagnosing recurring runtime errors, noisy logs, asset reload issues, config migration bugs, or multiplayer/split-screen issues.
- Deciding whether behavior belongs in SMAPI APIs, content APIs, services, optional integrations, reflection, or Harmony patches.
This skill complements stardew-valley-smapi. Use stardew-valley-smapi for general setup, manifest/release workflow, Android compatibility, and broad SMAPI debugging. Use this skill for implementation quality and best-practice review.
Do not use this skill for general Stardew Valley gameplay advice, non-SMAPI C# code, art, writing, or pure Content Patcher content unless SMAPI architecture or integration is involved.
Core Workflow
- Inspect the existing mod first:
manifest.json, .csproj, ModEntry.cs, config models, Framework/, i18n/, assets/, commands, integrations, and patches.
- Choose the smallest reliable SMAPI-native solution before adding abstractions, reflection, or Harmony.
- Keep
ModEntry focused on SMAPI glue: read config, initialize services, subscribe events, register commands, expose APIs, and forward work.
- Move real behavior into focused managers, services, handlers, commands, integrations, and patchers when the mod is more than trivial.
- Treat lifecycle timing, multiplayer host/client roles, split-screen state, content invalidation, config normalization, and migrations as explicit design concerns.
- Verify with the relevant check: build, SMAPI launch/log, asset reload, config reload, multiplayer host/farmhand test, split-screen test, or pure-logic unit tests.
Load References
Load detailed references only when needed:
- references/recommended-patterns.md: rationale and recommended patterns observed across mature SMAPI mods.
- references/implementation-checklist.md: compact checklist for creating, refactoring, or reviewing a SMAPI C# mod.
- references/templates.md: reusable code skeletons for common best-practice patterns.
Reference selection:
- Load
recommended-patterns.md when the user asks why a practice is recommended, asks for robust SMAPI implementation patterns, or needs architecture guidance.
- Load
implementation-checklist.md when reviewing code, planning a refactor, or checking whether an implementation is robust.
- Load
templates.md when writing or rewriting ModEntry, config normalization, content edits, migrations, optional integrations, or multiplayer message handling.
Default Rules
- Prefer
Entry only for basic initialization and event subscription.
- Prefer
GameLaunched for other-mod APIs and late integration registration.
- Prefer
SaveLoaded for per-save state and migrations.
- Prefer
AssetRequested for content edits; avoid legacy asset editor patterns.
- Prefer
Helper.ModContent for internal files and Helper.GameContent for game/mod-editable assets.
- Prefer POCO config classes with defaults,
KeybindList, case-insensitive ID dictionaries, and deserialization normalization.
- Prefer
i18n/default.json and generated I18n helpers for user-facing text.
- Prefer host-only shared world mutation with
Context.IsMainPlayer.
- Prefer
PerScreen<T> or equivalent per-screen storage for split-screen UI/input state.
- Prefer isolated optional integration classes that validate installed mod, version, and API availability.
- Prefer actionable logs, correct log levels, and
LogOnce for repeated failures.
- Treat Harmony as a last resort after SMAPI events, content APIs, public APIs, integrations, input suppression, and reflection helpers.
Review Priorities
When reviewing or refactoring, check these first:
ModEntry is small and lifecycle-aware.
- Event handlers have the right
Context and event-argument guards.
- Expensive work is not done every tick without throttling, dirty flags, or incremental events.
- Config handles old files, null collections, invalid values, and immediate reload after saving.
- Content edits use precise asset-name checks and invalidate only affected caches.
- Multiplayer logic separates host-only world mutation from farmhand-local behavior.
- Split-screen state is not stored in unsafe static/global fields.
- Optional integrations fail gracefully.
- Logs explain what failed, impact, fix, and technical details when useful.
- Migrations are versioned, host-only, logged, and safe against invalid legacy data.
Simple Vs Large Mods
For simple mods, a compact ModEntry, ModConfig, manifest.json, and i18n/default.json may be enough. Still use lifecycle guards, config defaults, translations, and clear logs.
For medium and large mods, split behavior into managers, handlers, command classes, integrations, and patchers. Design cache invalidation, content reloads, multiplayer sync, migrations, APIs, and tests deliberately.
1---2name: smapi-best-practices3description: Apply recommended best practices for Stardew Valley SMAPI mod architecture, lifecycle events, config, content APIs, i18n, multiplayer, diagnostics, migrations, and release-quality code. Use when designing, implementing, reviewing, refactoring, or debugging SMAPI C# mods and when the user asks for robust SMAPI implementation patterns.4---56# SMAPI Best Practices78## When to Use This Skill910Use this skill for Stardew Valley SMAPI C# mod work where maintainability, compatibility, robustness, or proven architecture patterns matter:1112- Designing a new SMAPI mod architecture.13- Implementing or reviewing `ModEntry`, events, config, content edits, i18n, commands, APIs, integrations, multiplayer, or migrations.14- Refactoring an existing mod toward cleaner lifecycle handling and service/manager separation.15- Diagnosing recurring runtime errors, noisy logs, asset reload issues, config migration bugs, or multiplayer/split-screen issues.16- Deciding whether behavior belongs in SMAPI APIs, content APIs, services, optional integrations, reflection, or Harmony patches.1718This skill complements `stardew-valley-smapi`. Use `stardew-valley-smapi` for general setup, manifest/release workflow, Android compatibility, and broad SMAPI debugging. Use this skill for implementation quality and best-practice review.1920Do not use this skill for general Stardew Valley gameplay advice, non-SMAPI C# code, art, writing, or pure Content Patcher content unless SMAPI architecture or integration is involved.2122## Core Workflow23241. Inspect the existing mod first: `manifest.json`, `.csproj`, `ModEntry.cs`, config models, `Framework/`, `i18n/`, `assets/`, commands, integrations, and patches.252. Choose the smallest reliable SMAPI-native solution before adding abstractions, reflection, or Harmony.263. Keep `ModEntry` focused on SMAPI glue: read config, initialize services, subscribe events, register commands, expose APIs, and forward work.274. Move real behavior into focused managers, services, handlers, commands, integrations, and patchers when the mod is more than trivial.285. Treat lifecycle timing, multiplayer host/client roles, split-screen state, content invalidation, config normalization, and migrations as explicit design concerns.296. Verify with the relevant check: build, SMAPI launch/log, asset reload, config reload, multiplayer host/farmhand test, split-screen test, or pure-logic unit tests.3031## Load References3233Load detailed references only when needed:3435- [references/recommended-patterns.md](references/recommended-patterns.md): rationale and recommended patterns observed across mature SMAPI mods.36- [references/implementation-checklist.md](references/implementation-checklist.md): compact checklist for creating, refactoring, or reviewing a SMAPI C# mod.37- [references/templates.md](references/templates.md): reusable code skeletons for common best-practice patterns.3839Reference selection:4041- Load `recommended-patterns.md` when the user asks why a practice is recommended, asks for robust SMAPI implementation patterns, or needs architecture guidance.42- Load `implementation-checklist.md` when reviewing code, planning a refactor, or checking whether an implementation is robust.43- Load `templates.md` when writing or rewriting `ModEntry`, config normalization, content edits, migrations, optional integrations, or multiplayer message handling.4445## Default Rules4647- Prefer `Entry` only for basic initialization and event subscription.48- Prefer `GameLaunched` for other-mod APIs and late integration registration.49- Prefer `SaveLoaded` for per-save state and migrations.50- Prefer `AssetRequested` for content edits; avoid legacy asset editor patterns.51- Prefer `Helper.ModContent` for internal files and `Helper.GameContent` for game/mod-editable assets.52- Prefer POCO config classes with defaults, `KeybindList`, case-insensitive ID dictionaries, and deserialization normalization.53- Prefer `i18n/default.json` and generated `I18n` helpers for user-facing text.54- Prefer host-only shared world mutation with `Context.IsMainPlayer`.55- Prefer `PerScreen<T>` or equivalent per-screen storage for split-screen UI/input state.56- Prefer isolated optional integration classes that validate installed mod, version, and API availability.57- Prefer actionable logs, correct log levels, and `LogOnce` for repeated failures.58- Treat Harmony as a last resort after SMAPI events, content APIs, public APIs, integrations, input suppression, and reflection helpers.5960## Review Priorities6162When reviewing or refactoring, check these first:6364- `ModEntry` is small and lifecycle-aware.65- Event handlers have the right `Context` and event-argument guards.66- Expensive work is not done every tick without throttling, dirty flags, or incremental events.67- Config handles old files, null collections, invalid values, and immediate reload after saving.68- Content edits use precise asset-name checks and invalidate only affected caches.69- Multiplayer logic separates host-only world mutation from farmhand-local behavior.70- Split-screen state is not stored in unsafe static/global fields.71- Optional integrations fail gracefully.72- Logs explain what failed, impact, fix, and technical details when useful.73- Migrations are versioned, host-only, logged, and safe against invalid legacy data.7475## Simple Vs Large Mods7677For simple mods, a compact `ModEntry`, `ModConfig`, `manifest.json`, and `i18n/default.json` may be enough. Still use lifecycle guards, config defaults, translations, and clear logs.7879For medium and large mods, split behavior into managers, handlers, command classes, integrations, and patchers. Design cache invalidation, content reloads, multiplayer sync, migrations, APIs, and tests deliberately.