A robust and scalable multi-tenant scheduling application built with Next.js 14. This platform allows users to create organizations, manage staff availability, define appointment types, and handle bookings efficiently. It features a secure authentication system, role-based access control, and a modern user interface.
- 🏢 Multi-Tenancy: Create and manage multiple organizations, each with its own profile, settings, and members.
- 📅 Advanced Scheduling:
- Define custom Appointment Types (duration, description, color).
- Set Weekly Availability schedules per organization.
- Manage Unavailable Dates (holidays, closures).
- 👥 Role-Based Access Control (RBAC):
- Admin: System-wide control.
- Manager: Organization owner/admin capabilities.
- User: Standard user for booking appointments.
- 🔐 Secure Authentication:
- Powered by NextAuth.js v5.
- Supports Google OAuth and Credentials (Email/Password).
- Includes Email Verification and Password Reset flows via Resend.
- 🔔 Notifications: System for tracking appointment updates (Created, Cancelled, Confirmed).
- 🎨 Modern UI: Responsive design built with Tailwind CSS and ShadCN UI.
- Framework: Next.js 14 (App Router)
- Database: PostgreSQL (via Supabase)
- ORM: Prisma
- Authentication: NextAuth.js
- Styling: Tailwind CSS & ShadCN
- Email: Resend
Detailed documentation for specific modules and actions can be found in the following README files:
- Data Access Layer: Documentation for the data access layer, including user, token, and notification management.
- Appointment Actions: Server actions for creating, updating, and managing appointments.
- Auth Actions: Server actions for authentication processes like login, register, and password reset.
- Notification Actions: Server actions for handling user notifications.
- Organization Actions: Server actions for organization management, including availability and scheduling.
-
Database Schema (Prisma): Defines the database models for Users, Organizations, Appointments, and more.
-
Auth Configuration: Configures NextAuth providers (Google, Credentials) and authorization logic.
-
Auth Initialization: Initializes NextAuth with Prisma adapter and session callbacks.
-
Middleware: Handles route protection, authentication checks, and role-based redirects.
-
Route Definitions: Defines public, auth, and protected routes, along with role-based access control rules.
The application uses PostgreSQL with Prisma ORM. The schema (src/prisma/schema.prisma) defines the following core models:
- User: The central user entity. Stores name, email, password (hashed), role (
ADMIN,MANAGER,USER), and profile image. - Account: Handles OAuth connections (e.g., Google) for users.
- VerificationToken: Stores tokens for email verification.
- PasswordResetToken: Stores tokens for password reset requests.
- Organization: Represents a tenant/business. Contains details like name, slug (for URLs), contact info, and location.
- OrganizationMember: Links users to organizations. Currently, a user can create organizations (becoming the owner/manager).
- WeeklyAvailability: Defines the recurring operating hours for an organization (e.g., Mon-Fri, 9:00-17:00).
- UnavailableDate: Specifies specific dates when the organization is closed (e.g., holidays).
- Appointment: Represents a booking. Links a
User(client) to anOrganization. Includes status (PENDING,CONFIRMED,CANCELLED,COMPLETED), time slot, and optional notes. - AppointmentType: Defines the services an organization offers (e.g., "General Checkup", "Consultation"). Includes duration and color coding.
- Notification: Stores system notifications for users (e.g., "Appointment Confirmed").
- Node.js (v18+ recommended)
- PostgreSQL Database (e.g., Supabase)
-
Clone the repository:
git clone <repository-url> cd <project-directory>
-
Install dependencies:
npm install
-
Set up environment variables: Create a
.envfile in the root directory and add the following variables:# Database (Supabase Transaction & Session Connection Poolers) SUPABASE_DATABASE_URL="postgres://..." SUPABASE_DIRECT_URL="postgres://..." # NextAuth AUTH_SECRET="your-secret-key" # OAuth Providers GOOGLE_CLIENT_ID="your-google-client-id" GOOGLE_CLIENT_SECRET="your-google-client-secret" # Email Service RESEND_API_KEY="re_..." # App URL NEXT_PUBLIC_APP_URL="http://localhost:3000"
-
Run Database Migrations:
npx prisma migrate dev
-
Start the development server:
npm run dev
The application should now be running at http://localhost:3000.