Agent Documentation
This page provides structured guidance for AI coding assistants working with mom-based projects.
What is mom?
Mom is an ultra-thin TypeScript library on top of React and MobX implementing micro-stores organized according to the Hierarchical Model-View-ViewModel (HMVVM) pattern. It uses @asimojs/asimo for dependency injection.
Package: @asimojs/mom
Core architecture
A Store is a MobX-observable state object (ViewModel) exposed as read-only, with lifecycle management and hierarchical parent-child relationships. Stores are created via factories defined with defineStore().
The lifecycle is: INITIALIZING → READY → DISPOSING → DISPOSED
Key APIs
All exported from @asimojs/mom:
defineStore(iid, factoryFn)— define a store factorycreateStore(factory, params)— instantiate a root storedisposeStore(store)— dispose a root storeregisterRootService(factory)— register a service on the root DI containerrootContext— the root IoC container
StoreContext API (inside factory functions)
initModel(model)— create the observable model (public data + actions)initState(state)— create private observable stateonInit(fn)/onDispose(fn)— lifecycle hooksmount(factory, params)/unmount(store)— manage child storesautorun()/reaction()— MobX reactions auto-disposed with the storecreateChildContext(services)— create a child IoC containercontext— asimo IoC container for fetching servicesstore— reference to current store instance (available after initModel)
File conventions
Store modules
featureName/├── store.types.ts # Public API types + IID├── store.ts # Implementation (factory)├── store.view.tsx # React component(s)├── store.spec.ts # Tests└── store.example.tsx # Usage example (optional)Services
serviceName/├── service.types.ts # Interface + IID + fake controller type├── service.ts # Implementation├── service.mock.ts # Fake for testing└── service.mock.spec.ts # Mock testsNaming conventions
| Pattern | Example | Purpose |
|---|---|---|
XxxDef |
CounterDef |
Store definition type |
XxxStore |
CounterStore |
Public store type: Store<XxxDef> |
XxxIID |
CounterIID |
Store interface identifier |
| PascalCase | Counter |
Factory constant |
$-prefix |
$id, $ready |
Store metadata properties |
Store pattern template
import { Store, storeIId } from "@asimojs/mom";
type MyFeatureDef = { params: { initialValue?: string; }; model: { value: string; setValue(v: string): void; };};
export type MyFeatureStore = Store<MyFeatureDef>;export const MyFeatureIID = storeIId<MyFeatureDef>("myapp.myFeature");import { defineStore } from "@asimojs/mom";import { MyFeatureIID } from "./store.types";
export const MyFeature = defineStore(MyFeatureIID, (store, params) => { const model = store.initModel({ value: params.initialValue ?? "", setValue(v: string) { model.value = v; }, });
store.onInit(async () => { /* async setup */ }); store.onDispose(() => { /* cleanup */ });});import { observer } from "mobx-react-lite";import { ViewProps } from "@asimojs/mom";import { MyFeatureStore } from "./store.types";
export const MyFeatureView = observer(({ store }: ViewProps<MyFeatureStore>) => ( <div>{store.value}</div>));Testing pattern
import { createContainer, Container } from "@asimojs/asimo";import { createStore, disposeStore, rootContext } from "@asimojs/mom";
describe("MyFeature", () => { let store: MyFeatureStore;
afterEach(() => { store && disposeStore(store); });
async function init(params = {}) { store = createStore(MyFeature, params); await store.$initComplete; }
it("should work", async () => { await init({ initialValue: "hello" }); expect(store.value).toBe("hello"); });});Important rules
- Types in separate files — parent stores import only types/IIDs from children, never implementations
initModelcalled once — must be called exactly once per store factoryrunInActionafter await — any observable mutation afterawaitneedsrunInAction()store.mountfor children — never usecreateStorefor child storesobserveron views — all React components reading store data must be wrapped- Reactions after initModel —
autorunandreactionmust be called afterinitModel
Dependencies
- Runtime:
@asimojs/asimo(DI/IoC) - Peer:
mobx,react,mobx-react-lite