This guide will help you set up the complete backend infrastructure for the Varuni Backoffice restaurant management system using GraphQL and MongoDB.
The backend consists of:
- GraphQL API - Apollo Server v5 (latest stable) integrated with Next.js 15 App Router
- MongoDB Database - NoSQL database with Mongoose ODM (latest stable)
- Authentication - JWT-based authentication (to be implemented)
- Real-time Features - GraphQL subscriptions (to be implemented)
- Node.js 18+ installed
- MongoDB running locally or MongoDB Atlas account
- Git for version control
npm installCreate a .env.local file in the root directory:
# Database Configuration
MONGODB_URI=mongodb://localhost:27017/varuni-backoffice
# For production, use MongoDB Atlas
# MONGODB_URI=mongodb+srv://username:password@cluster.mongodb.net/varuni-backoffice
# Authentication (for future implementation)
JWT_SECRET=your-super-secret-jwt-key-here
JWT_EXPIRES_IN=7d
# Application Configuration
NODE_ENV=development
NEXT_PUBLIC_GRAPHQL_URL=http://localhost:3000/api/graphql- Install MongoDB locally
- Start MongoDB service
- The database will be created automatically
- Create a MongoDB Atlas account
- Create a new cluster
- Get your connection string
- Update
MONGODB_URIin.env.local
npm run seedThis will create sample data including:
- Admin user
- Team members
- Inventory items
- Shifts
- Invoices
- Analytics data
npm run devThe GraphQL API will be available at: http://localhost:3000/api/graphql
- User - System users and authentication
- TeamMember - Staff management with performance tracking
- Shift - Scheduling and shift management
- InventoryItem - Stock management with status tracking
- Invoice - Financial management and billing
- Analytics - Reporting and insights
- Indexed Queries - Optimized for performance
- Data Validation - Mongoose schemas with validation
- Relationships - Proper references between models
- Audit Trail - Timestamps and user tracking
- Development:
http://localhost:3000/api/graphql - Production:
https://your-domain.com/api/graphql
teamMembers- Get all team membersshifts- Get shifts with date filteringinventoryItems- Get inventory with statusinvoices- Get financial dataanalytics- Get reporting data
createTeamMember- Add new staffupdateStock- Update inventory levelscreateShift- Schedule shiftscreateInvoice- Generate invoicessyncFromToast- Sync with Toast POS
- Real-time updates for shifts, inventory, and invoices
- Create model in
src/lib/models/ - Add to GraphQL schema in
src/lib/graphql/schema.ts - Implement resolvers in
src/lib/graphql/resolvers.ts - Update seed data if needed
Use the GraphQL Playground at http://localhost:3000/api/graphql:
# Example: Get all team members
query {
teamMembers {
id
name
role
department
performance {
rating
completedShifts
}
}
}
# Example: Create a new team member
mutation {
createTeamMember(input: {
name: "John Doe"
email: "john@example.com"
role: "Server"
department: "Front of House"
hourlyRate: 18.50
availability: "Part-time"
skills: ["Customer Service", "POS Systems"]
}) {
id
name
email
}
}# Seed database
npm run seed
# Reset database (clear all data)
# Manually delete collections or drop database
# View database (using MongoDB Compass or CLI)
mongosh varuni-backoffice- Basic error handling
- Input validation via Mongoose schemas
- Environment variable configuration
- JWT authentication
- Role-based access control
- Rate limiting
- Input sanitization
- CORS configuration
NODE_ENV=production
MONGODB_URI=mongodb+srv://username:password@cluster.mongodb.net/varuni-backoffice
JWT_SECRET=your-production-jwt-secret- Use MongoDB Atlas or managed MongoDB service
- Enable database backups
- Set up monitoring and alerts
- Deploy to Vercel, Netlify, or your preferred platform
- Set up CI/CD pipeline
- Configure domain and SSL
- Set up error tracking (Sentry, etc.)
- Database performance monitoring
- API usage analytics
-
MongoDB Connection Failed
- Check if MongoDB is running
- Verify connection string
- Check network connectivity
-
GraphQL Schema Errors
- Ensure all resolvers are implemented
- Check for circular dependencies
- Validate schema syntax
-
TypeScript Errors
- Run
npm run lintto check for issues - Ensure all dependencies are installed
- Check type definitions
- Run
Add to .env.local:
DEBUG=apollo-server:*- Follow the existing code structure
- Add proper TypeScript types
- Include error handling
- Update documentation
- Test thoroughly
For issues or questions:
- Check the troubleshooting section
- Review GraphQL playground for API testing
- Check MongoDB logs for database issues
- Create an issue in the repository
Happy coding! 🚀