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.
- 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
- 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
- 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
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)
git clone https://github.com/NhanPhamThanh-IT/Event-Booking-GraphQL-MERN.git
cd Event-Booking-GraphQL-MERN
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
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
{
fullName: String (required)
email: String (required, unique)
password: String (required, hashed)
createdEvents: [ObjectId] (references to Event)
}
{
title: String (required)
description: String (required)
price: Number (required)
date: Date (required)
creator: ObjectId (reference to User)
}
{
event: ObjectId (reference to Event)
user: ObjectId (reference to User)
createdAt: Date (auto-generated)
updatedAt: Date (auto-generated)
}
events
: Get all eventsbookings
: Get user's bookings (requires authentication)
createUser(userInput)
: Register a new userlogin(email, password)
: Authenticate usercreateEvent(eventInput)
: Create a new event (requires authentication)bookEvent(eventId)
: Book an event (requires authentication)cancelBooking(bookingId)
: Cancel a booking (requires authentication)
query {
events {
_id
title
description
price
date
creator {
_id
fullName
email
}
}
}
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
}
}
- 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
- 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
- useLazyLoading: Hook for implementing lazy loading with Intersection Observer
- useUserAuth: Authentication state management and route protection
- useLogout: Secure logout functionality with cleanup
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')}
/>
import { useLazyLoading } from "../hooks/useLazyLoading";
const LazyComponent = () => {
const [elementRef, isInView] = useLazyLoading(0.1, "50px");
return (
<div ref={elementRef}>
{isInView ? <ExpensiveComponent /> : <div>Loading...</div>}
</div>
);
};
- User registers with full name, email, and password
- Password is hashed using bcryptjs before storing
- User logs in with email and password
- JWT token is generated and sent to client
- Token is stored in localStorage and sent with each authenticated request
- Middleware validates token and adds user context to GraphQL resolvers
- Set up MongoDB Atlas or ensure MongoDB is accessible
- Configure environment variables for production
- Deploy to platforms like Heroku, Vercel, or DigitalOcean
- Build the production bundle:
npm run build
- Deploy to platforms like Netlify, Vercel, or GitHub Pages
- Update VITE_GRAPHQL_URL to point to production backend
- Fork the repository
- Create a feature branch:
git checkout -b feature-name
- Commit changes:
git commit -m 'Add feature'
- Push to branch:
git push origin feature-name
- Submit a pull request
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
- None currently reported
This project is licensed under the ISC License.
Nhan Pham Thanh
- GitHub: @NhanPhamThanh-IT
- Repository: Event-Booking-GraphQL-MERN
- 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
- 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
-
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
If you encounter any issues or have questions:
- Check the Issues page
- Create a new issue with detailed description
- Contact the maintainer directly
If this project helped you, please consider:
- โญ Starring the repository
- ๐ด Forking and contributing
- ๐ข Sharing with your network
- ๐ Reporting bugs and issues
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:
- 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
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
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