Backend
Setup
- Navigate to backend directory:
cd backend
- Install dependencies:
npm install
- 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
- Start PostgreSQL:
npm run db:start
# or from project root:
docker-compose up -d database
- 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
| Command | Description |
|---|---|
npm run dev | Start dev server with hot reload |
npm run build | Compile TypeScript to dist/ |
npm start | Run compiled code from dist/ |
npm run lint | Run ESLint |
npm test | Run tests with Jest |
npm run test:watch | Run tests in watch mode |
npm run db:start | Start PostgreSQL container |
npm run db:reset | Reset database (delete and recreate) |
API Routes
The backend exposes these main routes:
| Route | Description |
|---|---|
/api/auth/* | Authentication (register, login, refresh) |
/api/children | Children CRUD |
/api/visits | Medical visits |
/api/illnesses | Illness tracking |
/api/measurements | Growth measurements |
/api/medical-events | Medical events (vaccines, etc.) |
/api/users | User management |
/api/families | Family management |
/api/invites | Family 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.