Skip to main content

Backend

Setup

  1. Navigate to backend directory:
cd backend
  1. Install dependencies:
npm install
  1. Create environment file:
cp .env.example .env

Edit .env:

DATABASE_URL=postgresql://trajectory_user:password@localhost:5432/trajectory
APP_PORT=5017
UPLOAD_DIR=./uploads
AVATAR_DIR=./avatars
NODE_ENV=development
JWT_SECRET=dev_secret
JWT_REFRESH_SECRET=dev_refresh_secret
  1. Start PostgreSQL:
npm run db:start
# or from project root:
docker-compose up -d database
  1. Run migrations (if needed):

Migrations run automatically on startup, but you can apply them manually:

npm run migrate

Development Server

npm run dev

This starts the API server with hot reload using tsx watch. The server runs on http://localhost:5017.

Available Scripts

CommandDescription
npm run devStart dev server with hot reload
npm run buildCompile TypeScript to dist/
npm startRun compiled code from dist/
npm run lintRun ESLint
npm testRun tests with Jest
npm run test:watchRun tests in watch mode
npm run db:startStart PostgreSQL container
npm run db:resetReset database (delete and recreate)

API Routes

The backend exposes these main routes:

RouteDescription
/api/auth/*Authentication (register, login, refresh)
/api/childrenChildren CRUD
/api/visitsMedical visits
/api/illnessesIllness tracking
/api/measurementsGrowth measurements
/api/medical-eventsMedical events (vaccines, etc.)
/api/usersUser management
/api/familiesFamily management
/api/invitesFamily invitations
/api/admin/*Admin operations

See backend/src/routers/ for detailed route definitions.

Testing

Run tests:

npm test

Run tests in watch mode:

npm run test:watch

Test coverage:

npm run test:coverage

See backend/TESTING.md for more details.