Logo

Sharing Excess

Food Rescue Platform
For DevelopersServices

Server Service (apps/server)

Hono API running on Bun. Serves JSON APIs, OpenAPI JSON and interactive reference, and static DB schema assets.

Entrypoint (src/index.ts)

  • Initializes Sentry, compression, CORS, logging
  • Serves static assets: /schema, /schema.dbml, /schema.svg
  • Exposes OpenAPI JSON at /openapi/json and interactive reference at /openapi
  • Registers all routes from src/routes/**
  • Starts Bun server on ENV.SERVER_PORT (default parsed from string, default '8080')
  • Initializes an all-time impact cache cron on non-development environments

Routes

  • Root and feature routes under src/routes/** with clear segmentation: partners, locations, rescues, transfers, users, impact, ai
  • Each feature also has service-layer logic under src/services/**

Environment (src/utils/env.ts)

  • Validated by Zod. Required:
    • ENV_NAME in ['development','staging','production']
    • NODE_ENV in ['development','production','test']
    • SERVER_PORT, SENTRY_DSN_API, DATABASE_URL, DATABASE_READ_REPLICA_URL
    • CLERK_PUBLISHABLE_KEY, CLERK_SECRET_KEY
    • S3_ACCESS_KEY_ID, S3_SECRET_ACCESS_KEY, S3_REGION, S3_BUCKET, S3_ENDPOINT, RESEND_API_KEY, ANTHROPIC_API_KEY

CORS (src/utils/cors.ts)

  • Per-environment allowed origins; credentials enabled; standard methods/headers

OpenAPI helpers (src/utils/openapi.ts)

  • defaultErrorResponses and messageResponseSchema for consistent route responses

Docker image (apps/server/Dockerfile)

  • Multi-stage: builder compiles server for linting; production installs only prod deps filtered for server/types/db
  • Generates DB schema assets by running packages/db generator
  • Runs as non-root, exposes 8080, starts with bun start

Railway (apps/server/railway.json)

  • Builder: DOCKERFILE (path apps/server/Dockerfile)
  • Healthcheck: /, timeout 180s
  • Production default: 3 replicas, generous CPU/memory, multi-region
  • Staging sleeps

Local dev

  • bun dev at root (Turbo starts server first)
  • Or cd apps/server && bun run dev