calisthenics-course-booking-server

Public
OVERVIEW.md

The coaching MVP's server makes accounts real while the booking flow remains a prototype.

The client is a UX demo I built around a friend's coaching idea while trying an agent-assisted coding workflow. Its screens show a complete-looking path through plans, payment, sessions, and progress. The backend took one narrower piece of that idea: who is allowed into each role, and how can the browser recognize that person on the next request? This repository implements that account foundation with Express, TypeScript, and MongoDB.

Establishing the role boundary

Users can register, and users, trainers, and administrators sign in through role-matched portals. A JWT-protected session check reads the current account rather than trusting a remembered browser label. Administrators can create trainer accounts. The stored account includes a normalized email, password hash, role, and status; blocked or suspended accounts cannot sign in. Status endpoints report whether the service and database are available for development checks.

The boundary matters as much as the implemented routes. There are no server-side models for plans, payments, trainer availability, bookings, balances, or skill progress. Those screens use sample data in the client and a booking click does not create a reservation here. This is a working identity and role API for an MVP, not a complete coaching-commerce backend.

The repository README also records deployment and hardening work still needed before real customer use, including tighter validation, CORS, rate limiting, and care around the admin bootstrap settings. The value of this page is to show exactly which piece of the larger product the server currently makes real.

README.md

Calisthenics course booking MVP — server

The backend companion to the client MVP.

Express · TypeScript · MongoDB/Mongoose · JWT

This service persists user, trainer, and admin accounts. It supports user registration, role-specific sign-in, session checks, admin-created trainer accounts, and service/database/environment status. Booking, plan purchases, payments, coach schedules, and skill progress are not API features yet; the client currently demonstrates those with sample data.

Run locally

  1. Install Node.js and npm (this snapshot was compiled with Node.js 24) and provide a reachable MongoDB instance.

  2. In server/, install dependencies:

    npm ci
    
  3. Create server/.env with your own values:

    PORT=5000
    MONGO_URI=mongodb://127.0.0.1:27017
    JWT_SECRET=replace-with-a-long-random-secret
    JWT_EXPIRES_IN=7d
    # Optional admin bootstrap:
    # ADMIN_EMAIL=admin@example.com
    # ADMIN_PASSWORD=replace-with-a-unique-password
    # ADMIN_NAME=System Admin
    # ADMIN_ENFORCE_SINGLE_ADMIN=false
    
  4. Start the API:

    npm run dev
    

The process connects to MongoDB before listening. The root route is http://localhost:5000/; an aggregate status response is at http://localhost:5000/api/status/all. The database name is currently fixed to Untitle in src/config/db.ts, even if the connection URI contains another database name.

The admin bootstrap runs at startup when both ADMIN_EMAIL and ADMIN_PASSWORD are set. It creates an admin if missing, or synchronizes that account's name, role, and password. Setting ADMIN_ENFORCE_SINGLE_ADMIN=true also demotes other admins to users. Use these variables deliberately against a database that may already contain accounts.

API routes

All responses are JSON. Authenticated routes require Authorization: Bearer <JWT>.

MethodPathPurposeAccess
GET/Basic hello responsePublic
POST/api/auth/registerCreate a user account and return user + tokenPublic
POST/api/auth/loginSign in through user, trainer, or admin portalPublic
GET/api/auth/meValidate a token; return fresh user + tokenSigned in
POST/api/auth/admin/create-trainerCreate a trainer accountAdmin
GET/api/status/Runtime, uptime, and memoryPublic
GET/api/status/databaseMongoDB connection statePublic
GET/api/status/envPresence of required environment variablesPublic
GET/api/status/allCombined server, database, and environment checkPublic

Example user registration:

curl -X POST http://localhost:5000/api/auth/register \
  -H "Content-Type: application/json" \
  -d '{"name":"Demo User","email":"demo@example.com","password":"choose-a-password"}'

Example role-specific login:

curl -X POST http://localhost:5000/api/auth/login \
  -H "Content-Type: application/json" \
  -d '{"email":"demo@example.com","password":"choose-a-password","portal":"user"}'

The login portal must match the account role. register always creates a user; trainers come from the admin route. A user has name, lowercase unique email, hashed password, role (user, trainer, admin), and status (active, blocked, suspended). Suspended or blocked accounts cannot sign in. JWT expiry defaults to 7d when JWT_EXPIRES_IN is omitted.

Code map

LocationResponsibility
src/app.tsExpress setup, route mounting, startup, MongoDB connection
src/config/db.tsMongoose connection and fixed database name
src/models/user.model.tsUser schema and bcrypt password hashing
src/controllers/auth.controller.tsRegister, login, me, trainer creation
src/middlewares/auth.middleware.tsJWT and role guards
src/controllers/status.controller.tsRuntime and connection checks
src/utils/bootstrap-admin.tsOptional environment-driven admin sync

Repository hierarchy

server/
├── src/
│   ├── config/               # MongoDB connection
│   ├── controllers/          # Auth and status request handlers
│   ├── middlewares/          # JWT, role, and error middleware
│   ├── models/               # Mongoose user model
│   ├── routes/               # Express route definitions
│   ├── types/                # Shared request types
│   ├── utils/                # Admin account bootstrap
│   └── app.ts                # App setup and startup
├── AGENTS.md                 # Guidance for future coding agents
├── README.md                 # Setup, API contract, and MVP boundaries
├── nodemon.json              # Development reload configuration
├── package.json              # Scripts and dependencies
├── tsconfig.json             # TypeScript compiler settings
└── vercel.json               # Deployment configuration to verify
npm run dev    # nodemon + ts-node
npm run build  # compile TypeScript into dist/
npm start      # run compiled dist/app.js

The service currently allows CORS with the default cors() configuration, exposes status details publicly, and does not have booking or payment persistence. Input validation, rate limiting, restricted CORS, production error handling, and a serverless-compatible deployment path should be addressed before using this API for real customers. A vercel.json file exists, but the current startup path opens a listener after MongoDB connection, so deployment behavior needs separate verification.

License

Original code and documentation authored by Jakkarin Promsee are licensed under the MIT License. Third-party code, assets, datasets, and other materials are not covered by this license; their original terms apply.