How ganjeliyajay/voice-assistant-in-mern works
1. This repository is split into two deployed boundaries: Client/ is a React SPA built with Vite, and Server/ is an Express + Node API. The frontend talks to the backend over HTTP, and the backend talks to MongoDB and an external AI service.
2. The frontend entry point is Client/src/main.jsx, which mounts App.jsx and the global styles. The UI is organized into Pages/ for route-level screens and Components/ for reusable pieces like Hero.jsx.
3. The main user-facing flows are authentication and assistant interaction. The page set includes Login, Register, Logout, Home, plus AddAssistantName and UpdateAssistantName, which suggests a user-specific assistant profile or personalization setting.
4. Client state management is centralized in Redux. Redux/Store.jsx wires the store, while UserSlice/UserThunk handle auth or profile data and GeminiSlice/GeminiThunk handle assistant/AI request state. This is the main client-side boundary between UI and backend I/O.
5. The app’s voice features are browser-side and depend on the Web Speech API, as noted in the README. Speech recognition captures user input, and text-to-speech likely reads assistant responses back to the user. Chrome is called out because speech support is more reliable there.
6. The backend entry point is Server/index.js, which likely initializes Express, middleware, routes, and DB connection. Configs/db.js handles MongoDB connectivity, while Configs/isAuth.js and Configs/token.js provide authentication middleware and JWT/token helpers.
7. Authentication is a dedicated backend subsystem. Routes/AuthRoutes.js connects to Controllers/AuthControllers.js, and Modules/UserModule.js represents the user data model. This suggests registration, login, logout, and protected profile/assistant-name operations are all handled server-side.
8. The assistant/AI subsystem is separate from auth. Controllers/GeminiController.js and Gemini.js imply integration with an external Gemini API or SDK, with the backend acting as a proxy/adapter so the frontend never calls the AI service directly.
9. The primary data flow is: user speaks in the browser → frontend converts speech to text → Redux thunk sends the request to the backend → backend authenticates if needed and forwards to Gemini or reads/writes MongoDB → response returns to the client → UI updates and may speak the answer aloud.
10. Persistence appears to be centered on MongoDB for user records and assistant-related settings, not on local client storage. The presence of assistant-name pages implies the backend stores that preference with the user record or a related user document.
11. Cross-origin deployment is an important boundary. The README shows a Netlify frontend and Render backend, so cors and cookie/JWT settings matter. CLIENT_URL, VITE_API_URL, MONGO_URI, and JWT_SECRET are the key environment variables shaping runtime behavior.
12. For an architecture diagram, the core boxes are: Browser UI, Redux state layer, Express API, MongoDB, and Gemini external service. The main arrows are speech input/output in the browser, authenticated API calls from Redux thunks, DB reads/writes for users, and backend-to-Gemini AI requests.
Main entry points: index.js Express API · App.jsx App shell · AuthControllers.js Auth controller · Store.jsx Redux store
Components 19
Client
React SPA built with Vite; browser UI, Redux state, and speech features
- Browser UI · Mounted React app with route-level screens and reusable UI
Client/src/main.jsx - App shell · Top-level client composition and global styling
Client/src/App.jsx - Pages · Login, register, home, logout, and assistant-name screens
Client/src/Pages - Components · Reusable presentation components such as Hero
Client/src/Components - Redux store · Central client state wiring for auth and assistant flows
Client/src/Redux/Store.jsx - User state · Auth and profile state for the current user
Client/src/Redux/Slice/UserSlice.jsx - User thunk · Client-side async actions for user login and profile updates
Client/src/Redux/Thunk/UserThunk.jsx - Assistant state · Assistant request and response state
Client/src/Redux/Slice/GeminiSlice.jsx - AI thunk · Client-side async actions that call the backend for assistant responses
Client/src/Redux/Thunk/GeminiThunk.jsx - Speech API · Browser speech recognition and text-to-speech integration
Server
Express API, authentication, AI proxy, and MongoDB persistence
- Express API · Server entry point that wires routes, middleware, and services
Server/index.js - Auth routes · HTTP endpoints for registration, login, logout, and profile actions
Server/Routes/AuthRoutes.js - Auth controller · Request handlers for user authentication and assistant-name updates
Server/Controllers/AuthControllers.js - User model · User document shape and persistence boundary
Server/Modules/UserModule.js - Auth helpers · Token creation and protected-route checks
Server/Configs/token.js - DB config · MongoDB connection setup
Server/Configs/db.js - AI controller · Backend adapter for assistant requests to the external AI service
Server/Controllers/GeminiController.js - Gemini service · External Gemini API or SDK integration
Server/Gemini.js - MongoDB · Persistent store for users and assistant settings
Connections 22
- Browser UI → App shell: mounts · The entry point mounts the root app
- App shell → Pages: renders · App composes route-level screens
- App shell → Components: uses · App and pages reuse shared UI pieces
- App shell → Redux store: wraps · The client is connected to the Redux provider
- Pages → Redux store: reads/writes · Screens consume centralized state
- Redux store → User state: includes · Store registers user state
- Redux store → Assistant state: includes · Store registers assistant state
- User state → User thunk: uses · User state is driven by async auth actions
- Assistant state → AI thunk: uses · Assistant state is driven by async AI actions
- Speech API → Pages: feeds input · Voice capture and playback happen in the browser UI
- User thunk → Express API: http · Auth and profile requests go to the backend
- AI thunk → Express API: http · Assistant requests are sent through the API
- Express API → Auth routes: routes · Server exposes authentication endpoints
- Auth routes → Auth controller: dispatches · Routes delegate to auth handlers
- Auth controller → Auth helpers: verifies · Protected flows use token and auth middleware
- Auth controller → User model: persists · Auth and assistant-name data are stored on user records
- User model → MongoDB: stores · User documents live in MongoDB
- Express API → DB config: connects · Server initializes the database connection
- Express API → AI controller: routes · AI requests are handled by a dedicated controller
- AI controller → Gemini service: calls · Backend proxies requests to the external Gemini service
- AI controller → Express API: responds · Assistant results return to the HTTP layer
- Auth controller → Express API: responds · Auth results return to the HTTP layer