A Next.js application for booking medical appointments, built with TypeScript and Prisma.
- Node.js 18.x or higher
- Docker and Docker Compose
- npm or yarn
- PostgreSQL 16 (via Docker)
- Frontend: Next.js 15.3.1 (App Router)
- Backend: Next.js API Routes
- Database: PostgreSQL 16
- ORM: Prisma 6.6.0
- Authentication: NextAuth.js 5.0
- API Documentation: Swagger/OpenAPI
- Styling: TailwindCSS 4.x
git clone <repository-url>
cd medbook
Create a .env
file in the root directory:
# Database
DATABASE_URL="postgresql://postgres:postgres@localhost:5432/hospital_booking"
# NextAuth
NEXTAUTH_SECRET="your-secret-key"
NEXTAUTH_URL="http://localhost:3000"
# Install dependencies
npm install
# Start the database
docker-compose up -d
# Run database migrations
npx prisma migrate dev
# Seed the database
npx prisma db seed
# Start the development server
npm run dev
The application will be available at http://localhost:3000
The seed script (prisma/seed.ts
) creates initial data including:
-
Demo user account:
- Email: demo@example.com
- Password: password123
-
Three hospitals:
- General Hospital
- City Medical Center
- Community Hospital
-
Services for each hospital:
- General Check-up (30 min, $100)
- Blood Test (15 min, $75)
- X-Ray (20 min, $150)
-
Time slots:
- Generated for the next 7 days
- Available from 9 AM to 5 PM
- 70% chance of being available
-
Sample bookings:
- Creates 3 confirmed bookings for the demo user
To reseed the database:
# Drop all tables and reseed
npx prisma migrate reset
# Keep tables but clear and reseed data
npx prisma db seed
We use ESLint and Prettier for code formatting. Configuration files are included in the repository.
# Run linter
npm run lint
# Format code
npm run format
- Create a feature branch:
git checkout -b feature/your-feature-name
- Make your changes and commit using conventional commits:
git commit -m "feat: add booking confirmation"
git commit -m "fix: resolve date picker issue"
- Push and create a pull request:
git push origin feature/your-feature-name
The API documentation is available at http://localhost:3000/api-docs when running in development mode. It provides:
- Interactive API testing interface
- Detailed request/response schemas
- Authentication requirements
- Example requests and responses
To update the API documentation:
- Add JSDoc comments to your API routes:
/**
* @swagger
* /api/your-endpoint:
* get:
* summary: Your endpoint description
* ...
*/
- Update schema definitions in
src/lib/swagger.ts
if needed - Restart the development server to see changes
POST /api/auth/[...nextauth]
: User authentication (signin/signout)POST /api/auth/register
: User registration
GET /api/appointments
: List user's appointmentsPOST /api/appointments
: Create new appointment
GET /api/hospitals
: List available hospitalsGET /api/hospitals/:id/services
: Get hospital servicesGET /api/hospitals/:id/services/:serviceId/time-slots
: Get available time slots
src/
├── app/ # Next.js App Router pages and API routes
│ ├── (main)/ # Main layout group
│ │ ├── layout.tsx # Root layout with SessionProvider
│ │ └── page.tsx # Home page
│ ├── (swagger)/ # Swagger documentation group
│ │ ├── api-docs/ # API documentation pages
│ │ │ ├── layout.tsx # Swagger UI layout
│ │ │ └── page.tsx # Swagger UI page
│ ├── api/ # API endpoints
│ │ ├── auth/ # Authentication endpoints
│ │ │ ├── register/ # User registration
│ │ │ └── [...]/ # Other auth endpoints
│ │ └── docs/ # Swagger documentation endpoint
├── components/ # Reusable React components
├── lib/ # Shared utilities and configurations
│ ├── prisma.ts # Prisma client instance
│ ├── swagger.ts # Swagger configuration
│ └── validations/ # Zod schemas for validation
├── middleware.ts # Next.js middleware (auth protection)
└── types/ # TypeScript type definitions
└── swagger.d.ts # Swagger type definitions
prisma/
├── schema.prisma # Database schema
└── seed.ts # Database seeding script
public/ # Static assets
└── medical-logo.svg # Site logo
config/
└── next.config.ts # Next.js configuration
Key entities and their relationships:
Hospital
: Medical facilitiesService
: Medical services offered by hospitalsBooking
: Appointment bookingsUser
: System users (patients)
For testing purposes, use:
- Email: demo@example.com
- Password: password123
# Start services
docker-compose up -d
# Stop services
docker-compose down
# View logs
docker-compose logs -f
# Reset database
docker-compose down -v
docker-compose up -d
-
Database Connection Issues
- Ensure Docker is running
- Check if PostgreSQL container is healthy
- Verify DATABASE_URL in .env
-
Authentication Errors
- Confirm NEXTAUTH_SECRET is set
- Verify NEXTAUTH_URL matches your development URL
- Fork the repository
- Create your feature branch
- Commit your changes
- Push to the branch
- Create a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.