MongoDB
MongoDB holds authoritative data: organizations, users, messages, tasks, simulation settings, and most operational entities. The app manages connections throughMongoClient in src/memory/mongo_client.py.
Repository pattern
Route handlers should call repository helpers insrc/memory/repositories.py (and specialized repositories) instead of issuing raw collection operations inline. That keeps query logic testable and consistent.
Modeling new data
When you add or extend collections, document:- Primary keys — ObjectId vs string, and how APIs expose them (JSON usually uses strings).
- References — Foreign keys such as
organization_idanduser_id. - Indexes — What you need for uniqueness and hot queries (for example per-org constraints).
Schema changes
The codebase and startup scripts enforce shape and indexes; some changes need manual migration steps. Record operator-facing steps in Production rollout when deployments must run them in order.AI usage accounting collections
For AI cost visibility and reporting:ai_usage_eventsstores per-call usage/cost events withorganization_id, optionaluser_id, model/request metadata, token counts, mem0 units, and estimated costs.organization_ai_pricingstores org pricing versions with effective ranges and active status.