Skip to content
This repository was archived by the owner on Aug 9, 2025. It is now read-only.

๐ŸŽŠ Modern Event Booking System powered by GraphQL and MERN Stack. Features efficient data fetching with GraphQL queries/mutations, JWT authentication, real-time updates, and advanced lazy loading. Built with React 18, Node.js, MongoDB, and Vite. Includes DataLoader optimization, Intersection Observer API, and responsive Tailwind UI.

License

Notifications You must be signed in to change notification settings

NhanPhamThanh-IT/Event-Booking-GraphQL-MERN

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

89 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

Event Booking System - GraphQL MERN Stack

License Node.js React GraphQL MongoDB Express.js Vite TailwindCSS

A modern, full-stack event booking application built with MongoDB, Express.js, React, and Node.js (MERN), featuring GraphQL API for efficient data fetching and real-time user interactions.

๐ŸŒŸ Features

  • User Authentication: Secure JWT-based authentication with bcrypt password hashing
  • Event Management: Create, view, and manage events with detailed information
  • Event Booking: Book and cancel event reservations
  • Advanced Lazy Loading: Intersection Observer API for optimized image and content loading
  • Performance Optimization: Smart loading with configurable thresholds and smooth animations
  • Real-time Updates: GraphQL subscriptions for live data updates
  • Responsive Design: Modern UI built with React 18 and Tailwind CSS
  • Data Optimization: DataLoader for efficient database queries and N+1 problem prevention
  • GraphQL Playground: Interactive API exploration with Ruru GraphQL IDE
  • Modern Development: TypeScript support, ESLint integration, and Yarn package management

๐Ÿš€ Tech Stack

Backend

  • Node.js - Runtime environment
  • Express.js - Web framework
  • GraphQL - Query language and API
  • MongoDB - NoSQL database
  • Mongoose - ODM for MongoDB
  • JWT - Authentication tokens
  • bcryptjs - Password hashing
  • DataLoader - Batch and cache database requests

Frontend

  • React 18.3.1 - UI library with modern hooks and concurrent features
  • Vite 5.4.2 - Lightning-fast build tool and development server
  • Tailwind CSS 3.4.1 - Utility-first CSS framework
  • React Router DOM 7.8.0 - Declarative client-side routing
  • Axios 1.11.0 - Promise-based HTTP client for API requests
  • Lucide React 0.344.0 - Beautiful and consistent icon library
  • TypeScript 5.5.3 - Type checking and development tooling
  • ESLint 9.9.1 - Code linting and quality enforcement
  • Yarn - Fast and reliable package manager

๐Ÿ“‹ Prerequisites

Before running this application, make sure you have the following installed:

  • Node.js (v18.0.0 or higher)
  • npm or yarn
  • MongoDB (local installation or MongoDB Atlas)

๐Ÿ› ๏ธ Installation & Setup

1. Clone the Repository

git clone https://github.com/NhanPhamThanh-IT/Event-Booking-GraphQL-MERN.git
cd Event-Booking-GraphQL-MERN

2. Backend Setup

cd backend
npm install

Create a .env file in the backend directory:

MONGODB_URI=mongodb://localhost:27017/event-booking
JWT_SECRET=your-super-secret-jwt-key
PORT=5000

Start the backend server:

npm run dev

The GraphQL server will be running on http://localhost:5000/graphql GraphQL Playground UI: http://localhost:5000/ui

3. Frontend Setup

cd frontend
# Install dependencies using npm or yarn
npm install
# OR
yarn install

Create a .env file in the frontend directory:

VITE_GRAPHQL_URL=http://localhost:5000/graphql

Start the frontend development server:

# Using npm
npm run dev

# OR using yarn
yarn dev

The React app will be running on http://localhost:5173

๐Ÿ“Š Database Schema

User Model

{
  fullName: String (required)
  email: String (required, unique)
  password: String (required, hashed)
  createdEvents: [ObjectId] (references to Event)
}

Event Model

{
  title: String (required)
  description: String (required)
  price: Number (required)
  date: Date (required)
  creator: ObjectId (reference to User)
}

Booking Model

{
  event: ObjectId (reference to Event)
  user: ObjectId (reference to User)
  createdAt: Date (auto-generated)
  updatedAt: Date (auto-generated)
}

๐Ÿ”ง GraphQL API

Queries

  • events: Get all events
  • bookings: Get user's bookings (requires authentication)

Mutations

  • createUser(userInput): Register a new user
  • login(email, password): Authenticate user
  • createEvent(eventInput): Create a new event (requires authentication)
  • bookEvent(eventId): Book an event (requires authentication)
  • cancelBooking(bookingId): Cancel a booking (requires authentication)

Example GraphQL Queries

Get All Events

query {
  events {
    _id
    title
    description
    price
    date
    creator {
      _id
      fullName
      email
    }
  }
}

Create Event

mutation {
  createEvent(
    eventInput: {
      title: "Tech Conference 2024"
      description: "Annual technology conference"
      price: 99.99
      date: "2024-12-15T09:00:00.000Z"
    }
  ) {
    _id
    title
    price
    date
  }
}

๐ŸŽจ Frontend Features

Pages

  • Login/Register: User authentication with form validation
  • Events Dashboard: View all available events with lazy loading
  • Event Creation: Create new events (authenticated users)
  • Booking Management: View and manage bookings

Components

  • EventList: Display events in a responsive grid
  • EventItem: Individual event card with booking functionality
  • LazyLoading: Advanced lazy loading component with Intersection Observer API
    • LazyImage for optimized image loading
    • Configurable thresholds and root margins
    • Fade-in animations and blur placeholders
    • Error handling and loading states
  • Modal: Reusable modal component for forms
  • Backdrop: Modal overlay component
  • Spinner: Loading indicator
  • Input: Styled form input component

Custom Hooks

  • useLazyLoading: Hook for implementing lazy loading with Intersection Observer
  • useUserAuth: Authentication state management and route protection
  • useLogout: Secure logout functionality with cleanup

๐Ÿ–ผ๏ธ Lazy Loading Usage Examples

Using the LazyImage Component

import { LazyImage } from './components/LazyLoading';

// Basic usage
<LazyImage
  src="/path/to/image.jpg"
  alt="Event image"
  className="w-full h-48 object-cover rounded-lg"
/>

// Advanced usage with custom settings
<LazyImage
  src="/path/to/image.jpg"
  alt="Event image"
  className="w-full h-48 object-cover rounded-lg"
  blurPlaceholder={true}
  fadeIn={true}
  threshold={0.2}
  rootMargin="100px"
  onLoad={() => console.log('Image loaded')}
  onError={() => console.log('Image failed to load')}
/>

Using the useLazyLoading Hook

import { useLazyLoading } from "../hooks/useLazyLoading";

const LazyComponent = () => {
  const [elementRef, isInView] = useLazyLoading(0.1, "50px");

  return (
    <div ref={elementRef}>
      {isInView ? <ExpensiveComponent /> : <div>Loading...</div>}
    </div>
  );
};

๐Ÿ” Authentication Flow

  1. User registers with full name, email, and password
  2. Password is hashed using bcryptjs before storing
  3. User logs in with email and password
  4. JWT token is generated and sent to client
  5. Token is stored in localStorage and sent with each authenticated request
  6. Middleware validates token and adds user context to GraphQL resolvers

๐Ÿš€ Deployment

Backend Deployment (Node.js)

  1. Set up MongoDB Atlas or ensure MongoDB is accessible
  2. Configure environment variables for production
  3. Deploy to platforms like Heroku, Vercel, or DigitalOcean

Frontend Deployment (React)

  1. Build the production bundle: npm run build
  2. Deploy to platforms like Netlify, Vercel, or GitHub Pages
  3. Update VITE_GRAPHQL_URL to point to production backend

๐Ÿค Contributing

  1. Fork the repository
  2. Create a feature branch: git checkout -b feature-name
  3. Commit changes: git commit -m 'Add feature'
  4. Push to branch: git push origin feature-name
  5. Submit a pull request

๐Ÿ“ Project Structure

Event-Booking-GraphQL-MERN/
โ”œโ”€โ”€ backend/                 # Node.js + GraphQL backend
โ”‚   โ”œโ”€โ”€ src/
โ”‚   โ”‚   โ”œโ”€โ”€ config/         # Database configuration
โ”‚   โ”‚   โ”œโ”€โ”€ graphql/        # GraphQL schema and resolvers
โ”‚   โ”‚   โ”œโ”€โ”€ middleware/     # Authentication middleware
โ”‚   โ”‚   โ”œโ”€โ”€ models/         # MongoDB models
โ”‚   โ”‚   โ””โ”€โ”€ utils/          # Utility functions
โ”‚   โ””โ”€โ”€ package.json
โ”œโ”€โ”€ frontend/               # React frontend
โ”‚   โ”œโ”€โ”€ public/
โ”‚   โ”‚   โ””โ”€โ”€ vite.svg             # Vite logo
โ”‚   โ”œโ”€โ”€ src/
โ”‚   โ”‚   โ”œโ”€โ”€ assets/
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ react.svg        # React logo
โ”‚   โ”‚   โ”œโ”€โ”€ components/          # Reusable UI components
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ Input.jsx        # Styled input component
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ LazyLoading.jsx  # Lazy loading component with Intersection Observer
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ Backdrop/
โ”‚   โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ Backdrop.jsx # Modal backdrop
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ Events/
โ”‚   โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ EventItem.jsx    # Individual event card
โ”‚   โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ EventList.jsx    # Events grid container
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ Modal/
โ”‚   โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ Modal.jsx    # Reusable modal component
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ Spinner/
โ”‚   โ”‚   โ”‚       โ””โ”€โ”€ Spinner.jsx  # Loading spinner
โ”‚   โ”‚   โ”œโ”€โ”€ context/
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ UserContext.jsx  # User authentication context
โ”‚   โ”‚   โ”œโ”€โ”€ hooks/               # Custom React hooks
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ useLazyLoading.js    # Lazy loading with Intersection Observer hook
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ useLogout.jsx        # Logout functionality hook
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ useUserAuth.jsx      # Authentication hook
โ”‚   โ”‚   โ”œโ”€โ”€ pages/               # Page components
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ Auth/
โ”‚   โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ Login.jsx    # Login page
โ”‚   โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ SignUp.jsx   # Registration page
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ Main/
โ”‚   โ”‚   โ”‚       โ”œโ”€โ”€ Events.jsx   # Main events dashboard
โ”‚   โ”‚   โ”‚       โ””โ”€โ”€ Home.jsx     # Home page
โ”‚   โ”‚   โ”œโ”€โ”€ services/            # API service functions
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ authQuery.js     # Authentication GraphQL queries
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ eventQuery.js    # Event GraphQL queries
โ”‚   โ”‚   โ”œโ”€โ”€ utils/               # Helper utilities
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ apiPaths.js      # API endpoint constants
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ axiosInstance.js # Configured axios instance
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ helper.js        # Utility functions
โ”‚   โ”‚   โ”œโ”€โ”€ App.jsx              # Main app component
โ”‚   โ”‚   โ”œโ”€โ”€ index.css            # Global styles with Tailwind
โ”‚   โ”‚   โ””โ”€โ”€ main.jsx             # App entry point
โ”‚   โ”œโ”€โ”€ .gitignore               # Git ignore file
โ”‚   โ”œโ”€โ”€ eslint.config.js         # ESLint configuration
โ”‚   โ”œโ”€โ”€ index.html               # HTML template
โ”‚   โ”œโ”€โ”€ package.json             # Dependencies and scripts
โ”‚   โ”œโ”€โ”€ postcss.config.js        # PostCSS configuration
โ”‚   โ”œโ”€โ”€ tailwind.config.js       # Tailwind CSS configuration
โ”‚   โ”œโ”€โ”€ vite.config.js           # Vite configuration
โ”‚   โ””โ”€โ”€ yarn.lock                # Yarn lockfile
โ””โ”€โ”€ README.md

๐Ÿ› Known Issues

  • None currently reported

๐Ÿ“„ License

This project is licensed under the ISC License.

๐Ÿ‘จโ€๐Ÿ’ป Author

Nhan Pham Thanh

๐Ÿ™ Acknowledgments

  • GraphQL community for excellent documentation
  • React team for the amazing framework
  • MongoDB team for the flexible database solution
  • Open source community for inspiration and tools

๐Ÿ“ˆ Performance Features

  • DataLoader Implementation: Prevents N+1 query problems with efficient batch loading
  • GraphQL Query Optimization: Single endpoint with precise data fetching
  • Advanced Lazy Loading:
    • Intersection Observer API for efficient image and content loading
    • Configurable thresholds and root margins for optimal loading timing
    • Fade-in animations and blur placeholders for smooth user experience
    • Error handling and fallback mechanisms
  • Optimized Bundle Size: Vite's tree-shaking reduces bundle size
  • Caching: GraphQL results cached on the client side
  • Fast Development: Yarn package manager for faster dependency installation
  • Modern Build Tools: Vite for lightning-fast development and optimized production builds

๐Ÿ”ฎ Future Enhancements

  • Advanced lazy loading with Intersection Observer โœ… Completed
  • Add email notifications for event bookings
  • Implement event categories and filtering
  • Add payment integration (Stripe/PayPal)
  • Create mobile app with React Native
  • Add event reviews and ratings system
  • Implement real-time chat for events
  • Add calendar integration
  • Include event capacity management
  • Add advanced search functionality
  • Implement social media sharing
  • Add Progressive Web App (PWA) features
  • Implement server-side rendering (SSR) with Next.js

๐Ÿ“ž Support

If you encounter any issues or have questions:

  1. Check the Issues page
  2. Create a new issue with detailed description
  3. Contact the maintainer directly

โญ Show Your Support

If this project helped you, please consider:

  • โญ Starring the repository
  • ๐Ÿด Forking and contributing
  • ๐Ÿ“ข Sharing with your network
  • ๐Ÿ› Reporting bugs and issues

๐ŸŽฏ Conclusion

The Event Booking System represents a modern approach to full-stack web development, showcasing the power of the MERN stack combined with GraphQL's efficient data fetching capabilities. This project demonstrates:

Key Achievements

  • Scalable Architecture: Modular design with clear separation of concerns
  • Modern Tech Stack: Utilizes cutting-edge technologies for optimal performance
  • Security First: Implements JWT authentication and password hashing best practices
  • Developer Experience: Enhanced with hot reloading, GraphQL playground, and comprehensive documentation
  • Production Ready: Configured for easy deployment with environment-based configurations

Learning Outcomes

This project serves as an excellent learning resource for developers interested in:

  • GraphQL Integration: Understanding how to implement GraphQL in a full-stack application
  • React Hooks: Modern React development patterns with functional components
  • Authentication Flows: Secure user management with JWT tokens
  • Database Design: MongoDB schema design and relationships
  • Modern Tooling: Vite, Tailwind CSS, and other modern development tools

Impact & Value

Whether you're a beginner looking to understand full-stack development or an experienced developer seeking to implement GraphQL in your projects, this Event Booking System provides:

  • Real-world Application: Practical implementation of common business requirements
  • Best Practices: Industry-standard coding patterns and project structure
  • Extensibility: Solid foundation for adding advanced features
  • Performance Optimization: Efficient data loading and caching strategies

The project stands as a testament to modern web development practices, combining powerful technologies to create a seamless user experience while maintaining clean, maintainable code architecture.


Happy Coding! ๐Ÿš€

Built with โค๏ธ by Nhan Pham Thanh

About

๐ŸŽŠ Modern Event Booking System powered by GraphQL and MERN Stack. Features efficient data fetching with GraphQL queries/mutations, JWT authentication, real-time updates, and advanced lazy loading. Built with React 18, Node.js, MongoDB, and Vite. Includes DataLoader optimization, Intersection Observer API, and responsive Tailwind UI.

Topics

Resources

License

Stars

Watchers

Forks

Languages