Storage
Mastra sets the project's default storage from a storage.ts file directly under src/mastra/. The file default-exports a store, which replaces the built-in in-memory store used for memory, workflows, observability, and other storage domains.
Use this page for the file-based convention. For backend choice, storage domains, retention, and provider details, see storage overview.
QuickstartDirect link to Quickstart
Use LibSQLStore for a local file-backed store:
import { LibSQLStore } from '@mastra/libsql'
export default new LibSQLStore({
id: 'mastra-storage',
url: 'file:./mastra.db',
})
Mastra registers the store before file-based agents and workflows, so storage-dependent primitives bind to this store instead of the default in-memory store.
Production backendsDirect link to Production backends
storage.ts can export any Mastra storage adapter, such as LibSQL, PostgreSQL, or MongoDB. For setup patterns, provider support, and schema details, see storage overview, observability storage, and the storage reference.
Precedence with codeDirect link to Precedence with code
Code-registered storage wins over storage.ts. Use storage.ts when one project-wide store is enough; use code registration when setup depends on runtime wiring in src/mastra/index.ts.