graph TD
A[Next.js Frontend] -->|API Requests| B[Ruby on Rails Backend]
B -->|LLM API Call| C[LLM API Service]
C -->|Live Conversation| D[Hugging Face Model]
C -->|Transcription| E[Groq Transcription]
C -->|Documentation Lookup| F[Documentation Model]
C -->|Function Execution| G[Function Exec Model]
B -->|Store/Retrieve Data| H[(Database)]
B -->|OAuth & Calendar Integration| I[Google API]
E -->|Transcribed Text| B
Considerations
-
Security and Data Management:
- It’s generally more secure to handle sensitive data and API interactions on the server-side (Ruby on Rails in this case).
- OAuth tokens and user data should be stored securely on the backend.
-
LLM API Interaction:
- While it’s possible for Next.js to directly call the LLM API, having Ruby on Rails handle this maintains a single point of control for all external API interactions.
- This approach also allows for easier implementation of rate limiting, logging, and error handling.
-
Database Models:
- Ruby on Rails should handle all database interactions for consistency and to leverage its robust ORM (Active Record).
-
Next.js Role:
- Next.js should focus on rendering the UI and handling client-side state.
- It can make API calls to Ruby on Rails, which then orchestrates further actions (database queries, LLM API calls, etc.).
Components and responsibilities
-
Next.js Frontend:
- Handles UI rendering and client-side state management
- Makes API calls to Ruby on Rails for all data and action requests
- Manages user interactions and displays results
-
Ruby on Rails Backend:
- Serves as the central API for the frontend
- Handles authentication (OAuth with Google)
- Manages database interactions (storing user data, client lists, call logs)
- Orchestrates LLM API calls and processes results
- Integrates with Google Calendar API
- Implements business logic (filtering clients, scheduling calls)
-
Database (managed by Ruby on Rails):
- Users table (including OAuth tokens)
- Clients table (with insurance policy information)
- Call logs table
- Cached calendar events table
-
LLM API Service:
- Handles conversation flow
- Performs transcription
- Manages documentation lookup and function execution
This architecture allows you to:
- Keep sensitive data and operations server-side
- Centralize API interactions through Ruby on Rails
- Leverage Next.js for a responsive and interactive frontend
- Maintain clear separation of concerns
To implement this:
-
Start with setting up the Ruby on Rails backend:
- Implement user authentication with Google OAuth
- Create database models for users, clients, and call logs
- Set up API endpoints for frontend interactions
- Implement Calendar API integration
-
Develop the Next.js frontend:
- Create UI components for user interactions
- Implement API calls to Ruby on Rails backend
- Handle state management (e.g., with React hooks or a state management library)
-
Integrate LLM API:
- Implement API calls from Ruby on Rails to the LLM service
- Set up conversation handling and transcription processing
-
Implement call scheduling and management logic in Ruby on Rails
-
Develop caching mechanism for calendar events in Ruby on Rails
This approach allows you to focus on building a secure, scalable application while keeping the architecture clean and maintainable. You can start by implementing core features in the Next.js frontend and Ruby on Rails backend, then gradually integrate the LLM capabilities as you progress.