Skip to content

Latest commit

 

History

History
133 lines (94 loc) · 5.56 KB

File metadata and controls

133 lines (94 loc) · 5.56 KB

Multi-Tenant Appointment Scheduler

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.

Features

  • 🏢 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.

Tech Stack

Project Documentation

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.

Key Configuration Files

  • 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.

Database Schema

The application uses PostgreSQL with Prisma ORM. The schema (src/prisma/schema.prisma) defines the following core models:

User & Authentication

  • 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 Management

  • 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).

Appointments

  • Appointment: Represents a booking. Links a User (client) to an Organization. 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.

System

  • Notification: Stores system notifications for users (e.g., "Appointment Confirmed").

Getting Started

Prerequisites

  • Node.js (v18+ recommended)
  • PostgreSQL Database (e.g., Supabase)

Installation

  1. Clone the repository:

    git clone <repository-url>
    cd <project-directory>
  2. Install dependencies:

    npm install
  3. Set up environment variables: Create a .env file 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"
  4. Run Database Migrations:

    npx prisma migrate dev
  5. Start the development server:

    npm run dev

The application should now be running at http://localhost:3000.