Expert guidance for developing a Next.js 15 restaurant management system with Prisma, NextAuth, MUI, and PM2 deployment. Handles single-user-per-restaurant architecture with comprehensive menu, table, order, and payment management.
Expert guidance for working with a Next.js 15 restaurant management application featuring single-user-per-restaurant architecture, comprehensive menu/table/order management, and PM2 deployment.
Use this skill when working with:
**Development & Build:**
**Database Management:**
**Core Principle**: Each user owns and manages exactly one restaurant. The User model includes restaurant information (merged User + Restaurant concept).
**Key Implications**:
**Authentication & Core:**
**Operations:**
**Customer-Facing Routes:**
**Staff Management Routes:**
**Admin Routes:**
**Authentication Routes (Public):**
**Post-Auth Behavior**: All authenticated users redirect to `/restaurant`
**Configuration**: `lib/auth.ts` contains NextAuth.js setup with:
**Middleware Protection**: `middleware.ts` protects authenticated routes
**Usage Pattern**:
```typescript
import { getServerSession } from "next-auth";
import { authOptions } from "@/lib/auth";
// In API routes or server components
const session = await getServerSession(authOptions);
const userId = session?.user?.id;
```
**Always scope queries to the authenticated user**:
```typescript
// ✅ Correct - automatically scoped to user
const menuItems = await prisma.menuItem.findMany({
where: { userId: session.user.id }
});
// ❌ Wrong - fetches all data across users
const menuItems = await prisma.menuItem.findMany();
```
**Error Handling Pattern**:
```typescript
try {
// Database operation
} catch (error) {
console.error("Operation failed:", error);
return NextResponse.json(
{ error: "Operation failed" },
{ status: 500 }
);
}
```
**Key Reusable Components** (`lib/components/`):
**Custom Hooks**: Located in `lib/hooks/`
**Utilities**: `lib/utils/imageUrl.ts` for image URL handling
**Provider Setup**: `app/providers.tsx` wraps app with:
**Follow MUI Conventions**:
**Database:**
**Authentication:**
**Environments**:
**1. Prepare Environment**
```bash
```
**2. Run Migrations**
```bash
npx prisma migrate deploy
```
**3. Deploy Application**
```bash
npm run deploy
```
This command automatically:
**Configuration**: `ecosystem.config.js`
**PM2 Commands**:
```bash
pm2 list # View app status
pm2 logs mefood-app # Stream logs
pm2 restart mefood-app # Restart app
pm2 stop mefood-app # Stop app
pm2 delete mefood-app # Remove from PM2
```
**Manual Deployment** (without PM2):
```bash
npm run build
npm run start
```
1. **API Routes**: Follow RESTful patterns, always validate sessions
2. **Server Components**: Use for data fetching when possible
3. **Client Components**: Mark with `"use client"` only when needed
4. **Error Boundaries**: Implement proper error handling at route level
1. **Always authenticate**: Check session in API routes and protected pages
2. **Scope data**: Filter all queries by `userId` from session
3. **Validate inputs**: Sanitize user inputs before database operations
4. **Secure secrets**: Never commit `.env` files, use environment variables
1. **Database indexes**: Ensure Prisma schema has appropriate indexes
2. **Image optimization**: Use Next.js Image component for menu images
3. **Caching**: Leverage Next.js caching strategies for static content
4. **PM2 clustering**: Consider cluster mode for high-traffic scenarios
1. **Migrations**: Always test in development before production
2. **Backups**: Regular database backups before schema changes
3. **Monitoring**: Use PM2 logs and consider error tracking services
4. **Updates**: Keep dependencies updated, test thoroughly
**Common Issues:**
1. **Feature Development**:
- Create feature branch
- Run `npm run dev` for local testing
- Test with `npx prisma studio` for data inspection
- Run `npm run lint` before committing
2. **Schema Changes**:
- Update `prisma/schema.prisma`
- Run `npx prisma migrate dev --name descriptive_name`
- Generate client: `npx prisma generate`
- Test migrations on development database
- Deploy to production: `npx prisma migrate deploy`
3. **Deployment**:
- Merge to main branch
- SSH to production server
- Pull latest changes
- Run `npm run deploy`
- Verify with `pm2 list` and `pm2 logs`
Leave a review
No reviews yet. Be the first to review this skill!
# Download SKILL.md from killerskills.ai/api/skills/nextjs-restaurant-management-system/raw