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.