How akshatsinghnayal/sih-project-2025 works
1. Repository shape
- This is a two-part monorepo: a React/TypeScript frontend in SIH-Chat-Bot/ and an optional Node/Express backend in server/.
- The frontend can talk to Gemini directly in dev mode, or route through the backend for production-style streaming.
2. Primary product boundary
- The app is a student mental-wellness chatbot: anonymous chat, supportive AI responses, and no heavy user profile system.
- The architecture is intentionally simple around a single core loop: user message in, Gemini response out, with optional persistence.
3. Frontend application shell
- SIH-Chat-Bot/App.tsx, index.tsx, and index.html form the app entry path.
- App.tsx likely decides between authentication and chat experience, while global styling is handled by index.css plus Tailwind CDN usage noted in the README.
- vite.config.ts and tsconfig.json indicate a Vite-built SPA.
4. UI composition
- The chat UI is split into focused components:
- components/Auth.tsx for login/signup
- components/ChatView.tsx for the main conversation area
- components/ChatWindow.tsx for message rendering and input handling
- components/Sidebar.tsx for session/history/navigation controls
- components/icons/ holds local SVG-style UI assets, suggesting the app avoids a separate icon library.
5. State and auth boundary
- context/AuthContext.tsx and hooks/useAuth.ts define the app’s auth layer.
- The README says auth is mocked with localStorage, so authentication is a client-side state boundary rather than a real identity service.
- This makes auth lightweight and keeps the mental-wellness experience anonymous.
6. Chat data flow in the frontend
- The chat experience is centered on stateful UI components feeding message data through service calls and rendering responses back into the conversation pane.
- types.ts and constants.ts likely define shared message/session shapes and prompt/UI constants, keeping chat logic consistent across components.
7. AI integration layer
- services/geminiService.ts is the direct integration point for Google Gemini.
- services/apiService.ts likely abstracts whether requests go to the local Gemini client path or the backend API, based on environment flags such as VITE_USE_REMOTE_API.
- This creates a clean split between UI logic and model-provider communication.
8. Streaming response architecture
- The README highlights Server-Sent Events (SSE) and real-time streaming.
- In browser-only mode, streaming may be handled directly from the client SDK; in backend mode, the Express server acts as the streaming relay so the frontend can progressively render token/character updates.
- This is the key interactive boundary in the system: input is immediate, output is incremental.
9. Backend responsibilities
- server/index.js is the Express entry point, with server/db.js for MongoDB connection and server/models.js for persistence schemas.
- The backend is described as optional, so it is not the single source of truth for the product; it mainly supports production-safe streaming and optional chat persistence.
- server/.env.example suggests the backend is configured around GEMINI_API_KEY and optionally MONGODB_URI.
10. Persistence layer
- MongoDB is explicitly optional, which means chat history storage is not required for core operation.
- If enabled, the data boundary sits entirely in the backend via Mongoose models, keeping the frontend anonymous and lightweight.
11. Deployment/runtime boundaries
- render.yaml and DEPLOY-RENDER.md indicate the project is designed for deployment on Render.
- SIH-Chat-Bot/public/_redirects suggests SPA routing support for static hosting.
- The repo therefore supports two runtime topologies: static frontend only, or frontend plus backend API service.
12. Implementation themes that matter architecturally
- The app is built to be privacy-preserving, responsive, and emotionally safe rather than feature-heavy.
- Markdown rendering and the calming UI are presentation concerns; the meaningful architectural concerns are the split between client/UI, Gemini integration, streaming transport, and optional persistence.
Main entry points: index.js Express API · App.tsx App shell · ChatWindow.tsx Chat window · ChatView.tsx Chat view
Components 18
Frontend app
React/Vite client for chat, auth, and streaming UI.
- App shell · Top-level client bootstrap and route selection.
SIH-Chat-Bot/App.tsx - Boot files · HTML and TS entrypoints that start the Vite app.
SIH-Chat-Bot/index.tsx - Global styles · Shared visual styling for the client shell.
SIH-Chat-Bot/index.css - Auth screen · Login/signup experience for the lightweight client-side auth flow.
SIH-Chat-Bot/components/Auth.tsx - Chat view · Main chat page composition and layout.
SIH-Chat-Bot/components/ChatView.tsx - Chat window · Renders messages and handles sending user input.
SIH-Chat-Bot/components/ChatWindow.tsx - Sidebar · History, session, and navigation controls.
SIH-Chat-Bot/components/Sidebar.tsx - Auth context · Client-side authentication state boundary backed by local storage.
SIH-Chat-Bot/context/AuthContext.tsx - useAuth · Hook for consuming auth state in components.
SIH-Chat-Bot/hooks/useAuth.ts - API service · Chooses local Gemini access or remote backend API.
SIH-Chat-Bot/services/apiService.ts - Gemini client · Direct integration with Google Gemini from the browser path.
SIH-Chat-Bot/services/geminiService.ts - Chat types · Message and session shapes shared across the client.
SIH-Chat-Bot/types.ts - Constants · Prompt, UI, and chat behavior constants.
SIH-Chat-Bot/constants.ts
Backend service
Optional Express API for streaming relay and persistence.
- Express API · Optional backend entry point for streaming and API handling.
server/index.js - MongoDB · Optional persistence connection used by the backend.
server/db.js - Mongoose models · Backend schemas for stored chat data.
server/models.js
Deployment
Static hosting and Render deployment configuration.
- Render config · Deployment definition for the service split.
render.yaml - SPA redirects · Client-side routing support for static hosting.
SIH-Chat-Bot/public/_redirects
Connections 19
- Boot files → App shell: loads · Vite entry bootstraps the React app shell.
- Global styles → App shell: styles · Global CSS supports the app shell and views.
- App shell → Auth screen: shows · App shell can route into the auth experience.
- App shell → Chat view: shows · App shell can route into the main chat experience.
- Auth screen → Auth context: uses · Auth UI reads and updates client auth state.
- Auth context → useAuth: exposes · Context is consumed through a dedicated hook.
- Chat view → Chat window: contains · Conversation layout centers on the chat window.
- Chat view → Sidebar: contains · Sidebar provides session and navigation controls.
- Chat window → Chat types: shapes · Message rendering and input use shared data types.
- Chat window → Constants: configures · UI and prompt behavior are driven by constants.
- Chat window → API service: sends · User messages are sent through the service layer.
- API service → Gemini client: directs · Service adapter can call Gemini directly in client mode.
- API service → Express API: routes to · Service adapter can call the backend in remote mode.
- Express API → MongoDB: connects · Backend can open a MongoDB connection when enabled.
- Express API → Mongoose models: uses · Optional persistence goes through backend schemas.
- Express API → Gemini client: relays · Backend can forward streaming model requests.
- Render config → Express API: deploys · Render config describes the backend runtime.
- Render config → App shell: deploys · Render config also supports the frontend runtime.
- SPA redirects → Boot files: supports · Static hosting redirects enable SPA navigation.