A modern, full-stack Customer Relationship Management application with AI-powered natural language scheduling, real-time analytics, and comprehensive appointment management.
This CRM system combines traditional appointment scheduling with modern AI technology to streamline office and clinic operations. Built with FastAPI and React, it enables natural language booking, real-time analytics, and intelligent conflict detection.
- Natural language appointment booking via Google Gemini API
- Voice interface with browser-based speech recognition
- Automatic conflict detection and validation
- Context-aware responses with conversation history
- Interactive calendar with month and day views
- Multi-provider support with individual schedules
- Blocked time management (recurring and one-time)
- Appointment status tracking (scheduled, confirmed, completed, cancelled, no-show)
- Visual status indicators (cancelled appointments marked in red)
- Overview metrics: total appointments, completion rate, average duration, no-show rate
- Live updates with 60-second auto-refresh
- Current and next appointment tracking with countdowns
- Provider occupancy rate monitoring
- Data visualizations: trend charts, provider distribution, status breakdown
- Revenue tracking and service performance metrics
- Provider-based filtering and custom date ranges
- Comprehensive client profiles with appointment history
- Provider profiles with specialty and availability tracking
- Advanced search and filtering
- Soft delete for data preservation
- Service catalog with pricing and duration
- Revenue tracking by service type
- Performance analytics for services
- FastAPI (Python 3.11+)
- PostgreSQL with SQLAlchemy ORM
- Google Gemini API integration
- Service layer architecture with dependency injection
- pytest for testing
- React 19 with Vite
- FullCalendar for scheduling
- Recharts for data visualization
- CSS Modules for styling
- Vitest with React Testing Library
- Docker and Docker Compose
- pgAdmin 4 for database administration
- Centralized environment configuration
- Docker and Docker Compose
- Google Gemini API key (obtain from https://aistudio.google.com/app/apikey)
- Clone the repository:
git clone https://github.com/yarimal/ai-crm.git
cd ai-crm- Configure environment variables:
cp .env.example .envEdit .env:
GEMINI_API_KEY=your_actual_api_key_here
DATABASE_URL=postgresql://crm_user:crm_password@localhost:5432/crm_database
CORS_ORIGINS=http://localhost:5173,http://localhost:3000
VITE_API_BASE_URL=http://localhost:8000/api- Start the application:
docker-compose up- Access the application:
- Frontend: http://localhost:5173
- Backend API: http://localhost:8000
- API Documentation: http://localhost:8000/docs
- Database Admin: http://localhost:5050
cd backend
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
pip install -r requirements.txt
uvicorn app.main:app --reloadcd frontend
npm install
npm run devcd backend
pytest # Run all tests
pytest -v # Verbose output
pytest --cov=app # With coveragecd frontend
npm test # Run all tests
npm run test:ui # Interactive UI
npm run test:coverage # Coverage reportInteractive API documentation available at http://localhost:8000/docs
Providers
POST /api/providers- Create providerGET /api/providers- List providersPUT /api/providers/{id}- Update providerDELETE /api/providers/{id}- Soft delete provider
Clients
POST /api/clients- Create clientGET /api/clients- List clientsPUT /api/clients/{id}- Update clientDELETE /api/clients/{id}- Soft delete client
Appointments
POST /api/appointments- Create appointmentGET /api/appointments- List appointmentsPUT /api/appointments/{id}- Update appointmentDELETE /api/appointments/{id}- Delete appointment
Services
POST /api/services- Create serviceGET /api/services- List servicesPUT /api/services/{id}- Update serviceDELETE /api/services/{id}- Delete service
Analytics
GET /api/analytics/overview- Overview statisticsGET /api/analytics/appointments-over-time- Trend dataGET /api/analytics/appointments-by-provider- Provider distributionGET /api/analytics/appointments-by-status- Status breakdownGET /api/analytics/realtime- Live metricsGET /api/analytics/revenue- Revenue statisticsGET /api/analytics/service-performance- Service metrics
AI Assistant
POST /api/ai/chat- Send message to AIGET /api/chats- List chat sessionsGET /api/chats/{id}- Get chat history
Business logic separated from routing handlers:
ai_functions.py- AI function implementationsai_context.py- Context building for AI promptsanalytics_service.py- Analytics calculations with filtering
Modular dashboard components:
DashboardHeader.jsx- Filters and controlsOverviewCards.jsx- Summary metricsLiveMetrics.jsx- Real-time updatesChartsSection.jsx- Data visualizations
- Timezone-aware datetime handling with UTC
- Automatic exclusion of cancelled appointments from analytics
- Real-time updates with 60-second refresh intervals
- Centralized configuration via .env file
- Test isolation with in-memory databases
| Variable | Description | Default |
|---|---|---|
GEMINI_API_KEY |
Google Gemini API key | Required |
DATABASE_URL |
PostgreSQL connection string | postgresql://crm_user:crm_password@localhost:5432/crm_database |
CORS_ORIGINS |
Comma-separated allowed origins | http://localhost:5173,http://localhost:3000 |
VITE_API_BASE_URL |
Frontend API base URL | http://localhost:8000/api |
Backend won't start
- Verify PostgreSQL is running:
docker-compose ps - Check
.envfile exists and contains valid values - Review logs:
docker-compose logs backend
Frontend can't connect to API
- Verify
VITE_API_BASE_URLmatches backend address - Check CORS origins include frontend URL
- Ensure backend is running at http://localhost:8000
AI features not working
- Verify
GEMINI_API_KEYis set correctly - Check API key validity at Google AI Studio
- Review backend logs for API errors
Database connection errors
- Check PostgreSQL container:
docker ps - Verify
DATABASE_URLin.env - Restart containers:
docker-compose restart
- Fork the repository
- Create a feature branch
- Make your changes with tests
- Submit a pull request
MIT License - See LICENSE file for details
- Google Gemini AI for natural language processing
- FullCalendar for calendar components
- FastAPI framework and community
- React and Vite development teams
- Recharts for data visualizations