Git Product home page Git Product logo

njm-server's Introduction

NJM Server

Node.js GraphQL backend for Next.js Masters course. Provides mock e-commerce data for demo record store.

Features

Apollo GraphQL API with Express middleware. Automated GraphQL workflow with Codegen. Postgresql via Prisma ORM. Recombee AI recommender API integration.

Running in development

  • Start DB container & admin panel: docker-compose -f docker-compose-dev.yaml up adminer db.
  • DB admin panel @ localhost:8080, user: admin, pass: password.
  • Start Node server in hot reload (Nodemon): npm run dev.

Codegen for GraphQL

Based on @graphql-codegen/cli package with https://www.npmjs.com/package/@eddeee888/gcg-typescript-resolver-files plugin for more opinionated setup.

  • pnpm codegen to create/update GraphQL resolvers based on schema changes.

Database management

Update & apply migrations locally: DATABASE_URL=postgresql://admin:password@localhost:5432/njm pnpm exec prisma migrate dev.

Refresh Prisma client: pnpm exec prisma generate.

Mock data management: Run seed script: DATABASE_URL=postgresql://admin:password@localhost:5432/njm pnpm exec ts-node prisma/seed.ts.

Available options:

  • --drop - clean all.
  • --seed - seed products.
  • --seed-collections - generate collections for existing products.
  • --seed-users - generate some registered users.
  • --seed-reviews - generate random lorem ipsum reviews.

Data for app testing is provided by Spotify API - store items are bulk generated by Spotify recommendation engine based on list of arbitrarily selected genres.

See prisma/mockdata/ folder for implementation details.

Deployment & GitOps

Production server is running on RKE2 Kubernetes. Deployment is automatic on push/merge to main branch - GitOps process runs via GitHub actions and ArgoCD.

Auto deployment workflow:

  • Developer PR / push / merge to main.
  • GitHub actions CICD pipeline:
    • Automatic build of new Docker image (commit SHA based versioning).
    • Push to GitHub container registry.
    • Automatic update of image tag in Kubernetes manifest - auto-commit to main branch & skip CI option to avoid pipeline loop.
  • On main branch update - ArgoCD webhook triggers cluster update.

All production secrets are encrypted using sealed secrets controller - https://github.com/bitnami-labs/sealed-secrets.

CICD & architecture diagram

image

Configuration

Required settings must be provided in Kubernetes configmaps / secrets.

# database
POSTGRES_USER
POSTGRES_PASSWORD

# app
DATABASE_USER
DATABASE_PASS
DATABASE_HOST # as "host:port" e.g. db:5432
DATABASE_NAME
NODE_ENV # development || production
NODE_PORT # graphql & rest server port, default 8000

# recommender
RECOMBEE_DB_NAME
RECOMBEE_API_KEY
RECOMBEE_DEFAULT_REGION

Recommender engine

# configure database definitions
npx ts-node src/recommender/init.ts

njm-server's People

Contributors

piotrswiecik avatar actions-user avatar

Stargazers

Rafał Wojciech Rolski avatar

Watchers

 avatar

njm-server's Issues

orderitems cascading

currently order items are orphaned on order delete, check same with user delete

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.