Backend Documentation

Getting Started

Use this page to boot the backend locally and understand the minimum contract needed to interact with it safely from the frontend or from external integrations.

Install and Run

  • Work from the `zitrabot-master-node` project root.
  • Install dependencies first, then start the server in development mode.
npm install
npm run dev

Required Environment

  • `MONGODB_URI` for persistence and sessions.
  • `SESSION_SECRET` for JWT signing and session encryption.
  • `FRONTEND_URL` for redirects and CORS-sensitive flows.
  • `OPENAI_API_KEY` for AI chat behavior.

First Checks

Before touching bots or integrations, confirm the server is reachable and understand how authentication is expected to work.

Health Endpoint

A healthy server returns memory, environment, uptime, and database readiness details.

curl -i http://localhost:5000/api/health

Auth Header Shape

After verification or login, protected routes use a bearer token in the standard authorization header.

Authorization: Bearer <jwt>

Recommended Startup Order

  • Verify database connectivity and confirm `/api/health` reports the expected Mongo state.
  • Register or log in through the `/auth` routes and retain the returned token.
  • Create a bot, then create a chat handler bound to that bot.
  • Only after the core chat flow works locally should you connect external channels like WhatsApp or Instagram.