Backend — def-exsport-backend
The GraphQL + REST API behind both frontends and the three third parties. All the business logic lives here.
How this page was verified
Read on 2026-09-15 from package.json, src/main.ts, src/app.module.ts, the module tree and the DB config. Local checkout: /Volumes/xpro/erisristemena/nestjs/def-exsport-backend.
Stack
| Framework | NestJS 10, TypeScript 5 |
| API | Apollo GraphQL (@nestjs/graphql 12, @apollo/server 4), code-first; plus REST (Express) |
| ORM | TypeORM 0.3, pg 8, Postgres |
| Auth | @nestjs/jwt, @nestjs/passport, passport-jwt, passport-google-oauth20, bcrypt |
| Also | aws-sdk (S3), @nestjs/schedule (cron), @nestjs/event-emitter, nodemailer + EJS, exceljs, moment-timezone, nanoid |
No queue/bull, no Sentry, no engines pin.
Run
Scripts: start:dev = nest start --watch, start:prod = node dist/main, build = nest build. No port in the script — src/main.ts listens on APP_PORT (3014 locally, default 3000) and sets a global prefix from APP_PREFIX (be-api local, gapi prod).
Layout
Each area is src/<domain>/ with <domain>.module.ts, resolvers/, services/, models/ (entities), dto/, and often controllers/. Business modules: catalogs, users, orders, payments, deliveries, promotions, journals, admins. Support: public, storages, smtp, health, events, database, utils. See the codebase tour for what each owns, and Features for end-to-end traces.
Three structural facts
- Code-first GraphQL, no
schema.gql. The schema is generated at boot. Only admins, catalogs, users, orders, promotions, journals are in the GraphQLinclude; deliveries, payments, public, health, storages are REST-only. synchronize: true, no migrations, no seeds. The schema is the entity files; "seeding" is a few REST endpoints. See Database.- Two JWT realms, per-resolver guards. Admin resolvers stack
JwtAuthGuard, LastActivityGuard, RoleAbilityGuard; members useJwtMemberAuthGuard. See API and auth.
Cron and events
- One cron:
OrdersCronService.handleOrderPaymentExpiryruns every minute, re-checks DOKU forpending_paymentorders past their expiry, and cancels the expired ones (also cancels the WMS order and Biteship draft). - Domain events via
@nestjs/event-emitter:order.completedandmember.recalculate_favoritesare handled inusers/services/members.service.tsto update member stats. Note a second, customAppEventEmitteralso exists.
Third-party clients
DeliveriesService (Biteship), PaymentsService (DOKU) and WmsService (PowerBiz) — all @nestjs/axios, base URLs from env, pointed at the simulator in dev. Inbound callbacks land on REST routes under webhooks/*.
Branch model
Environment branches: main, staging, development on origin (plus old feature branches like vouchers, members — never base on those). Auto-deploys on push. See Environments.