The backend uses Mongoose with 10 primary models. All models expose a virtual id field (stringified _id) and use created_at / updated_at timestamps.

Entity relationship diagram

Model summary

Key relationships

User ↔ Index Setting

  • User.pageAccess is an array of ObjectId refs to AppSetting.
  • Middleware checks page.index against PageAccess enum values (nifty50, bankNifty).
  • AppSetting.createdBy / updatedBy reference the admin User who modified the setting.

Index Setting ↔ Orders

  • All order models use indexName (string) matching AppSetting.index.
  • Segment-specific config (cash, futures, options) drives recurring buy and trailing sell behaviour.

Setting ↔ Order routing

  • Setting.isDummyOrder is a global switch.
  • When true, controllers read/write DummyOrder instead of Order.
  • Zerodha placement is skipped in dummy mode.

Zerodha token

  • Typically one document with isLoggedIn: true.
  • Deleted and refreshed daily at 6:00 AM IST by the scheduled job.

Index Data vs Index

  • IndexData — snapshots built by the Zerodha market data pipeline (zerodha-event.utils.ts), stored for historical charts and Excel export.
  • Index — legacy TrueData tick format with Symbol, LTP, OI fields. Used by older data paths.

Indexes