Skip to content
프로젝트

watscho/express-graphql-mongodb-boilerplate

GitHub에서 보기

소개

A boilerplate for Node.js apps / GraphQL-API / Authentication from scratch - express, graphql - (graphql compose), mongodb (mongoose).

보안 및 개인정보 보호

이 수치를 측정하는 방법

What you can do

  • Accounts - Signup/signin/signout, profile, email/password updates, deletion, reset and verification
  • Security workflows - Bcrypt, JWT issuer/audience/version checks, hashed revocation keys and one-time email tokens
  • Consistency - Versioned account locks and MongoDB transactions covering account, tokens and queued emails
  • Media - Authenticated multipart upload, owner checks, JPEG/PNG decoding, bounded WebP avatars and cleanup

측정된 스타 증가

in 24h
0
in 7 days
0
in 15 days
0
in 1 month
기록 수집 중

서로 겹치는 기간의 순증가량이며 일별 합계가 아닙니다. 측정값이 없으면 비워 둡니다. 스타는 관심도를 나타내며 품질을 보장하지 않습니다.

README.md

Original

Express GraphQL MongoDB Boilerplate

A domain-based TypeScript GraphQL API. Version 2.0.0 replaces the JavaScript/Lerna application with the architecture and application capabilities of express-mongodb-rest-api-boilerplate, adapted to GraphQL.

Node.js 26.13.0 · TypeScript 7 · Express 5 · GraphQL 17 · GraphQL Yoga 6 · Mongoose 9 · Redis · Zod 4 · Yarn 4.

Quick start

nvm install
nvm use
node .yarn/releases/yarn-4.18.1.cjs install --immutable
cp .env.example .env
# Generate two DIFFERENT keys and put them in JWT_SECRET and MAIL_QUEUE_ENCRYPTION_KEY:
openssl rand -hex 32
openssl rand -hex 32

Configure MongoDB (replica set or Atlas), Redis and SMTP in .env. For local SMTP, a capture server such as Mailpit can receive messages on port 1025. Never point development or tests at production dependencies.

yarn db:indexes
yarn dev
# In another terminal, with the same environment:
yarn dev:mail
# In a third terminal, run periodic cleanup against the same MongoDB and upload storage:
yarn media:cleanup --watch

The API listens at http://localhost:8000/graphql. GraphiQL is available there in development. Production disables both GraphiQL and schema introspection; export the SDL for client tooling instead. Health checks remain /health/live and /health/ready.

mutation SignUp($input: CredentialsInput!) {
  signUp(input: $input) {
    accessToken
  }
}

Variables: {"input":{"email":"[email protected]","password":"a-long-unique-password"}}.

Send the returned token in Authorization: Bearer <token>. Supply Accept-Language for email language selection.

query Account {
  me {
    id
    email
    firstName
    lastName
    verified
    image
  }
}

Architecture

src/
  app/
    config/       # Validated, role-specific configuration and secret-file loading
    database/     # MongoDB transactions and Redis connection lifecycle
    graphql/      # Schema composition, generated resolver types, context, limits, errors
    http/         # Express, health, static conversions, headers, CORS and HTTP limits
    runtime/      # API/worker bootstraps, diagnostics, logging and operator commands
  domains/
    auth/         # JWTs, credentials, revocation and sensitive account workflows
      verification/
    users/        # Account persistence, public projection and profile changes
    media/        # Owned uploads, image validation, conversions and avatar attachment
    notifications/# Email catalog, rendering and translations
      delivery/   # Encrypted transactional outbox and separate worker

Each domain owns schemas.ts, inferred dto.ts, services, repositories and models, plus a graphql/ adapter with SDL and generated-type-checked resolvers. Cross-domain business calls use public index.ts facades. No generated Mongoose CRUD is exposed. This is the same pragmatic domain-based design as the REST reference, without generic repository classes or a DI container.

Capabilities

Area Included
Accounts Signup/signin/signout, profile, email/password updates, deletion, reset and verification
Security workflows Bcrypt, JWT issuer/audience/version checks, hashed revocation keys and one-time email tokens
Consistency Versioned account locks and MongoDB transactions covering account, tokens and queued emails
Media Authenticated multipart upload, owner checks, JPEG/PNG decoding, bounded WebP avatars and cleanup
Email HTML/text templates, English/Georgian translations, encrypted outbox, retries, fenced leases and worker heartbeats
GraphQL Explicit SDL, generated resolver types, Zod validation, masked errors, parser/depth/field limits, per-call auth throttling
Operations Graceful shutdown, request IDs, redacted diagnostics, role-specific secrets, queue CLI, indexes and legacy migration
Delivery Multi-stage non-root Docker image, hardened production Compose, immutable install and CI quality checks

GraphQL queries use normal data/errors results. Safe business error keys and validation details live in errors[].extensions. Nullable root fields allow independent partial results. Mutation fields execute separately; a document is not one database transaction. Batch requests are disabled. Security mutations invalidate the request auth context before later mutation fields execute.

Commands

Command Purpose
yarn dev / yarn dev:mail API / mail worker with source watching
yarn build TypeScript 7 compilation, source maps, templates and SDL
yarn start / yarn start:mail Compiled API / mail worker
yarn codegen Generate resolver types from domain SDL
yarn codegen:check Fail on SDL/generated-type drift
yarn docs:export --output schema.graphql Export SDL without credentials or services
yarn typecheck / yarn lint / yarn format:check Static checks
yarn test Build and run the local test suite
yarn test:coverage Build, test and enforce 100% application coverage
yarn test:integration Build and verify disposable Docker API/worker, MongoDB, Redis and SMTP capture
yarn check Complete local quality gate, including codegen drift
yarn db:migrate:legacy / yarn db:indexes Explicit maintenance; read migration instructions first
yarn media:cleanup / yarn media:cleanup --watch One cleanup pass / periodic cleanup of expired uploads and crash leftovers
yarn mail:queue --help Queue inspection, retry and worker health

Every operator command also has a compiled :prod script for production-only installations. Tests use isolated test settings, mocks and temporary files; they do not connect to real MongoDB, Redis or SMTP. Passing local checks does not establish real provider delivery, production deployment or MongoDB concurrency acceptance.

See the documentation index, GraphQL contract, legacy migration, configuration, testing, and deployment guide.

See the local verification record for measured results and the security policies.

License

MIT · Vacho Aivazov · 2026.

관련 프로젝트 살펴보기

불러오는 중…