How abhishek-3191/patient-scheduling-assistant works
The product is a conversational patient appointment scheduler. A patient sends multi-turn requests through the chat UI; the chat API loads patient and session context, invokes the Gemini-backed agent, persists the updated conversation, and returns structured doctor, slot, and appointment results. The agent dispatches discovery, availability, booking, cancellation, and rescheduling tools. MongoDB repositories provide patient, doctor, appointment, and conversation data. The repository also includes scenario evaluation and a baseline-versus-improved guardrail loop. Tool internals beyond the sampled booking implementation are represented only where the source index documents their dependencies.
Main entry points: agent.ts Agent orchestrator · Chat.tsx Chat interface · route.ts Chat API · evaluator.ts Scenario evaluator
Components 32
Patient experience
- Chat interface
components/Chat.tsx - Chat API
app/api/chat/route.ts - Message view
components/Message.tsx - Doctor cards
components/DoctorCard.tsx - Slot selector
components/SlotSelector.tsx - Appointment card
components/AppointmentCard.tsx
Scheduling assistant
- Agent orchestrator
agent/agent.ts - System prompt
agent/prompt.ts - Appointment state
agent/state.ts - Booking guardrails
agent/guardrails.ts - Doctor discovery
agent/tools/findDoctors.ts - Slot availability
agent/tools/checkAvailability.ts - Book appointment
agent/tools/bookAppointment.ts - Cancel appointment
agent/tools/cancelAppointment.ts - Reschedule appointment
agent/tools/rescheduleAppointment.ts
MongoDB persistence
- MongoDB connection
db/mongodb.ts - Patient repository
db/repositories/patientRepository.ts - Doctor repository
db/repositories/doctorRepository.ts - Appointment repository
db/repositories/appointmentRepository.ts - Conversation repository
db/repositories/conversationRepository.ts - Appointment model
db/models/Appointment.ts - Doctor model
db/models/Doctor.ts - Patient model
db/models/Patient.ts - Conversation model
db/models/Conversation.ts
Agent evaluation
- Evaluation API
app/api/evaluation/route.ts - Scenario evaluator
evaluation/evaluator.ts - Evaluation scenarios
evaluation/scenarios.ts - Evaluation metrics
evaluation/metrics.ts - Evaluation runner
evaluation/run.ts - Improvement loop
evaluation/selfImprovement.ts
Other components
- Patient
- Gemini API
Connections 46
- Patient → Chat interface: sends requests
components/Chat.tsx - Chat interface → Chat API: posts messages
components/Chat.tsx - Chat API → Agent orchestrator: runs agent
app/api/chat/route.ts - Chat API → Patient repository: looks up patient
app/api/chat/route.ts - Chat API → Conversation repository: loads and saves session
app/api/chat/route.ts - Chat API → MongoDB connection: connects
app/api/chat/route.ts - Chat API → Chat interface: returns structured results
components/Chat.tsx - Chat interface → Message view: renders
components/Chat.tsx - Chat interface → Doctor cards: renders
components/Chat.tsx - Chat interface → Slot selector: renders
components/Chat.tsx - Chat interface → Appointment card: renders
components/Chat.tsx - Appointment card → Patient: offers appointment PDF
components/AppointmentCard.tsx - Agent orchestrator → Gemini API: generates responses
agent/agent.ts - Agent orchestrator → System prompt: builds instructions
agent/agent.ts - Agent orchestrator → Doctor discovery: dispatches discovery
agent/agent.ts - Agent orchestrator → Slot availability: dispatches availability
agent/agent.ts - Agent orchestrator → Book appointment: dispatches booking
agent/agent.ts - Agent orchestrator → Cancel appointment: dispatches cancellation
agent/agent.ts - Agent orchestrator → Reschedule appointment: dispatches rescheduling
agent/agent.ts - Agent orchestrator → Appointment state: updates state
agent/agent.ts - Book appointment → Booking guardrails: validates booking
agent/tools/bookAppointment.ts - Book appointment → Doctor repository: gets doctor
agent/tools/bookAppointment.ts - Book appointment → Patient repository: gets patient
agent/tools/bookAppointment.ts - Book appointment → Appointment repository: checks and creates booking
agent/tools/bookAppointment.ts - Doctor discovery → Doctor repository: searches doctors
agent/tools/findDoctors.ts - Slot availability → Doctor repository: gets doctor schedule
agent/tools/checkAvailability.ts - Slot availability → Appointment repository: checks booked slots
agent/tools/checkAvailability.ts - Cancel appointment → Appointment repository: cancels booking
agent/tools/cancelAppointment.ts - Reschedule appointment → Appointment repository: updates booking
agent/tools/rescheduleAppointment.ts - Reschedule appointment → Doctor repository: checks doctor
agent/tools/rescheduleAppointment.ts - Patient repository → Patient model: queries
db/repositories/patientRepository.ts - Doctor repository → Doctor model: queries
db/repositories/doctorRepository.ts - Appointment repository → Appointment model: reads and writes
db/repositories/appointmentRepository.ts - Conversation repository → Conversation model: reads and writes
db/repositories/conversationRepository.ts - Evaluation API → MongoDB connection: connects
app/api/evaluation/route.ts - Evaluation API → Patient repository: loads evaluation patient
app/api/evaluation/route.ts - Evaluation API → Scenario evaluator: runs scenarios
app/api/evaluation/route.ts - Evaluation API → Evaluation metrics: calculates results
app/api/evaluation/route.ts - Evaluation runner → MongoDB connection: connects
evaluation/run.ts - Evaluation runner → Scenario evaluator: runs scenarios
evaluation/run.ts - Evaluation runner → Evaluation metrics: summarizes results
evaluation/run.ts - Scenario evaluator → Agent orchestrator: evaluates behavior
evaluation/evaluator.ts - Scenario evaluator → Evaluation scenarios: loads scenarios
evaluation/evaluator.ts - Scenario evaluator → Evaluation metrics: produces scenario results
evaluation/evaluator.ts - Improvement loop → Scenario evaluator: compares runs
evaluation/selfImprovement.ts - Improvement loop → Evaluation metrics: compares pass rates
evaluation/selfImprovement.ts