PERN Stack Backend Application with GraphQL and Apollo

github repo

A backend application built using the PERN stack (PostgreSQL, Express, React, Node.js) enhanced with GraphQL and Apollo Server for API management. This project serves as a foundation for building a React client to interact with a knowledge graph backend.


Features

  • User authentication and authorization with JWT tokens
  • GraphQL API powered by Apollo Server
  • Sequelize ORM for PostgreSQL database interactions
  • Real-time updates with GraphQL subscriptions
  • DataLoader integration for optimized batch loading
  • Logging with Winston and request logging with Morgan
  • Environment-based configuration for development, testing, and production

Tech Stack

  • Node.js
  • Express
  • PostgreSQL
  • Sequelize
  • GraphQL
  • Apollo Server
  • JWT (jsonwebtoken)
  • DataLoader
  • bcrypt (password hashing)
  • Winston (logging)
  • Mocha & Chai (testing)

Getting Started

Prerequisites

  • Node.js (v10.11.0 or higher)
  • PostgreSQL
  • npm or yarn

Installation

git clone https://github.com/justin-napolitano/sup-court-pern-stack.git
cd sup-court-pern-stack
npm install

Environment Setup

Create a .env file in the project root with the following variables:

DATABASE_URL=postgres://username:password@localhost:5432/supreme_court
SECRET=your_jwt_secret_key
PORT=8000
NODE_ENV=development

Running the Application

npm start

The server will start on http://localhost:8000/graphql with GraphQL Playground enabled.

Running Tests

npm run test:execute-test

Project Structure

β”œβ”€β”€ LICENSE
β”œβ”€β”€ README.md
β”œβ”€β”€ package.json
β”œβ”€β”€ package-lock.json
β”œβ”€β”€ src
β”‚   β”œβ”€β”€ config
β”‚   β”‚   β”œβ”€β”€ db.js           # Database configuration
β”‚   β”‚   β”œβ”€β”€ index.js        # Environment config
β”‚   β”‚   └── logger.js       # Winston logger setup
β”‚   β”œβ”€β”€ loaders
β”‚   β”‚   └── user.js         # DataLoader batch functions
β”‚   β”œβ”€β”€ models
β”‚   β”‚   β”œβ”€β”€ index.js        # Sequelize initialization
β”‚   β”‚   β”œβ”€β”€ user.js         # User model
β”‚   β”‚   └── message.js      # Message model
β”‚   β”œβ”€β”€ resolvers
β”‚   β”‚   β”œβ”€β”€ index.js        # Combined resolvers
β”‚   β”‚   β”œβ”€β”€ user.js         # User resolvers
β”‚   β”‚   β”œβ”€β”€ message.js      # Message resolvers
β”‚   β”‚   └── authorization.js# Authorization middleware
β”‚   β”œβ”€β”€ schema
β”‚   β”‚   β”œβ”€β”€ index.js        # Schema aggregation
β”‚   β”‚   β”œβ”€β”€ user.js         # User GraphQL schema
β”‚   β”‚   └── message.js      # Message GraphQL schema
β”‚   β”œβ”€β”€ subscription
β”‚   β”‚   β”œβ”€β”€ index.js        # PubSub setup
β”‚   β”‚   └── message.js      # Subscription events
β”‚   β”œβ”€β”€ tests
β”‚   β”‚   β”œβ”€β”€ api.js          # API test utilities
β”‚   β”‚   └── user.spec.js    # User tests
β”‚   β”œβ”€β”€ utils
β”‚   β”‚   └── auth.js         # JWT token helpers
β”‚   β”œβ”€β”€ index.js            # Entry point
β”‚   β”œβ”€β”€ server.js           # Express and Apollo server setup
β”‚   └── first_start.js      # (Possibly legacy or initial server start)

Future Work / Roadmap

  • Add frontend React client to consume the GraphQL API
  • Expand test coverage and add integration tests
  • Implement role-based access control with more granular permissions
  • Add support for pagination and filtering on more queries
  • Enhance subscription support for real-time features
  • Improve error handling and validation
  • Containerize the application with Docker for easier deployment
  • Add CI/CD pipeline for automated testing and deployment

Note: This project currently focuses on backend setup and API development. Frontend integration and deployment strategies are planned for future iterations.

hjkl / arrows Β· / search Β· :family Β· :tag Β· :datefrom Β· :dateto Β· ~/entries/slug Β· Ctrl+N/Ctrl+P for suggestions Β· Ctrl+C/Ctrl+G to cancel
entries 201/201 Β· entry -/-
:readyentries 201/201 Β· entry -/-