SmartOffice Room Reservation System Expert
Expert guidance for working with the SmartOffice room reservation system codebase.
Overview
SmartOffice is a room reservation system for conference and lecture rooms featuring an interactive horseshoe-shaped floor plan. The application is built with modern web technologies including Next.js 16 (App Router), React 19, TypeScript, PostgreSQL with Prisma ORM, and NextAuth.js 5 for authentication.
Instructions
When working with this codebase, follow these guidelines:
1. Development Workflow
For starting and running the application:
Use `npm run dev` to start the development server on localhost:3000Use `npm run build` to create production builds (automatically runs prisma generate)Use `npm run lint` to check code quality with ESLintFor Docker-based development (recommended for quick start):
Use `docker-compose up -d` to start PostgreSQL and the applicationUse `docker-compose down -v` to stop services and remove volumes2. Database Operations
When working with the database:
Run `npx prisma generate` to generate the Prisma Client (also runs automatically on npm install)Use `npx prisma db push` to push schema changes to the database without migrationsUse `npx prisma migrate dev` to create and run proper migrationsUse `npx prisma studio` to open the visual database GUI for data inspectionThe database schema is defined in `prisma/schema.prisma`The Prisma client singleton is in `lib/prisma.ts`The database has three main models:
`User` - User accounts with roles (USER or ADMIN)`Room` - Conference and lecture rooms`Reservation` - Room bookings linked to users and rooms3. Authentication System
NextAuth.js v5 implementation details:
Configuration is in `lib/auth.ts`Route protection handled by middleware in `middleware.ts`Uses JWT strategy with credentials providerPasswords are hashed with bcryptTwo user roles: `USER` and `ADMIN`Type extensions for NextAuth are in `types/next-auth.d.ts`Test credentials after seeding:
Admin: `[email protected]` / `admin123`User: `[email protected]` / `student123`4. API Routes
All API routes are located in `app/api/`:
**Authentication:**
`/api/auth/[...nextauth]` - NextAuth handlers**Rooms:**
`/api/rooms` - GET (public), POST (admin-only)`/api/rooms/[id]` - Individual room operations**Reservations:**
`/api/reservations` - Reservation listing and creation`/api/reservations/[id]` - Individual reservation operations**Admin:**
`/api/users` - User management (admin-only)`/api/seed` - Database seeding endpoint (POST to `http://localhost:3000/api/seed`)**Utilities:**
`/api/health` - Health check endpoint5. Page Routes
Key application pages:
`/dashboard` - User home page after login`/rooms` - Room listing page`/rooms/[id]` - Room details and booking interface`/floor-plan` - Interactive floor visualization (4 floors, 10 rooms each, horseshoe layout)`/reservations` - User's reservation management`/calendar` - Calendar view of reservations`/admin` - Admin panel (admin role required)`/login` - Login page`/register` - Registration page6. Component Organization
Components are organized as follows:
`components/layout/` - Layout components (Navbar, Sidebar)`components/ui/` - Reusable UI components`components/Providers.tsx` - Session provider wrapper for the app7. Type Definitions
TypeScript types:
Custom application types are in `types/index.ts`NextAuth type extensions are in `types/next-auth.d.ts`8. Environment Configuration
Required environment variables in `.env`:
```
DATABASE_URL=postgresql://user:password@localhost:5432/smartoffice
AUTH_SECRET=<min-32-char-secret>
AUTH_URL=http://localhost:3000
```
Generate `AUTH_SECRET` using: `openssl rand -base64 32` (minimum 32 characters required)
9. Seeding Test Data
To load test data into the database:
```bash
curl -X POST http://localhost:3000/api/seed
```
This creates test users (admin and regular user) and sample rooms/reservations.
10. Best Practices
When modifying this codebase:
Always run `npx prisma generate` after schema changesProtect admin routes with role checks in API handlersUse the middleware for route-level authenticationFollow the existing API route patterns for consistencyKeep the Prisma client singleton pattern in `lib/prisma.ts`Maintain type safety with TypeScript throughoutCommon Tasks
**Adding a new room type:** Modify the `Room` model in `prisma/schema.prisma`, run `npx prisma db push`, and update the room creation forms.
**Creating new API endpoints:** Follow the pattern in `app/api/`, use NextAuth's `getServerSession` for authentication, and check user roles as needed.
**Modifying the floor plan:** The interactive floor plan component is at `/floor-plan` and displays 4 floors with 10 rooms each in a horseshoe layout.
**User management:** Admin users can manage all users via `/api/users` and the admin panel at `/admin`.