How muhammedrafzan/sentra-flow works
1. High-level shape
- SentraFlow is a two-tier application: a React frontend and a FastAPI backend, with PostgreSQL/Supabase-style persistent storage represented by SQL schema files and backend database helpers.
- The backend acts as the system of record and processing layer; the frontend is a dashboard/UI layer for operators to view chats, analytics, CRM data, and auth screens.
2. Frontend boundary
- The frontend is a Vite-based React + TypeScript SPA by file layout (src/main.tsx, vite.config.ts, multiple .tsx components).
- Main UI surfaces are split into feature components: Auth, Chatbot, Conversations, Dashboard, Analytics, Insights, CRM, Purchases, Settings, plus shared chrome like Sidebar and TopNav.
- This suggests the frontend is organized as a modular dashboard app that consumes backend APIs rather than owning business logic.
3. Backend boundary
- The backend is a FastAPI monolith with modular routing.
- backend/main.py likely wires application startup, middleware, and route registration.
- API surface is separated into routers for auth, chat, sentiment, and analytics, which is a strong signal of domain-based boundaries inside one service.
4. Core domain flow
- The main business flow is: customer conversation arrives → backend stores/processes it → sentiment/intent is inferred → analytics and CRM views are updated.
- The readme indicates messages may originate from external chat platforms such as WhatsApp via Happilee, so the backend likely serves as the ingestion and normalization layer for third-party chat events.
5. AI and NLP subsystem
- AI concerns are isolated in backend/services/ai_service.py and backend/services/sentiment_engine.py.
- This subsystem likely wraps the model provider and implements sentiment classification and intent detection for categories such as buying, complaint, and query.
- The README mentions Groq (LLaMA 3) / OpenAI, so the AI layer is probably provider-agnostic with fallback behavior.
6. Authentication subsystem
- backend/models/auth.py, backend/services/auth_service.py, and backend/routers/auth.py show a dedicated auth path.
- The system supports role-based access implied by the README: Admin / Shopkeeper / User.
- Auth appears to be a backend-owned concern, with the frontend presenting login/session UI and the backend enforcing access.
7. Chat and conversation subsystem
- backend/models/chat.py and backend/routers/chat.py represent the conversation pipeline.
- This likely handles incoming/outgoing messages, conversation state, and persistence of chat records.
- The frontend components Chatbot and Conversations map to this domain and likely render live or historical message streams.
8. Analytics and dashboard subsystem
- backend/routers/analytics.py and backend/routers/sentiment.py feed the dashboard with derived metrics.
- Frontend components like Analytics, Dashboard, Insights, and possibly Purchases are consumers of aggregated business metrics, not raw chat data.
- The architecture therefore separates operational data (messages, customers) from derived data (sentiment trends, conversion metrics, alerts).
9. Persistence and schema
- backend/core/database.py is the backend database access layer, while database/*.sql contains schema/data assets.
- The SQL files indicate entities such as users, businesses, customers, messages, omniflow_events, and likely supporting records for conversions/feedback.
- backend/migrate_schema.py suggests schema bootstrap or migration logic is handled separately from request handling.
10. Data model boundary
- The project is clearly centered around business entities rather than generic chat text:
- Users for platform access
- Businesses for tenant/context
- Customers for people being tracked
- Messages for conversation history
- Events/feedback/conversions for derived engagement data
- This structure supports a CRM-style analytics product rather than a simple chatbot UI.
11. Real-time and operational concerns
- backend/middleware/logging_middleware.py indicates request observability at the API boundary.
- The README references WebSockets and real-time updates, so live conversation or alert delivery is likely an important path, especially for distressed-customer detection.
- This means the backend is not only CRUD-oriented; it also streams or pushes updates for live dashboard panels.
12. Integration boundaries
- External dependencies include messaging platform webhooks (Happilee/WhatsApp) and LLM providers (Groq/OpenAI).
- For local development, the README mentions ngrok for exposing webhook endpoints.
- These integrations sit outside the core app boundary and connect into the backend via ingestion and AI service layers.
13. Testing and sandbox artifacts
- Files like backend/test_bot.py, backend/test_groq2.py, backend/test_insert.py, backend/test_req.py, backend/test_send.py, and backend/test_v2.py indicate the backend was developed with several focused experiment/test scripts.
- That suggests the AI/integration layer was validated independently of the main API flow.
14. Important repo-specific note
- The README describes the frontend as Next.js/Tailwind/Tremor, but the actual file tree shows a Vite React + TypeScript frontend structure. For architecture diagrams, the tree is the stronger signal: this repo is best represented as a React SPA + FastAPI API + PostgreSQL-backed AI analytics platform.
Main entry points: App.tsx App shell · database.py Database core · chat.py Chat router · main.py API app
Components 28
Frontend
React SPA for operators and analysts
- App shell · Client entry and top-level application composition
frontend/src/App.tsx - Auth · Login and session screens
frontend/src/components/Auth.tsx - Chatbot · Chat interaction surface
frontend/src/components/Chatbot.tsx - Conversations · Conversation history and message browsing
frontend/src/components/Conversations.tsx - Dashboard · Operator overview and summary panels
frontend/src/components/Dashboard.tsx - Analytics · Metrics and trend views
frontend/src/components/Analytics.tsx - Insights · Derived recommendations and alerts
frontend/src/components/Insights.tsx - CRM · Customer and business records
frontend/src/components/CRM.tsx - Purchases · Purchase-oriented business views
frontend/src/components/Purchases.tsx - Settings · App and account configuration
frontend/src/components/Settings.tsx - Shell nav · Shared sidebar and top navigation
frontend/src/components/Sidebar.tsx
Backend
FastAPI application and domain logic
- API app · Application startup, middleware, and router wiring
backend/main.py - Auth router · Authentication endpoints
backend/routers/auth.py - Chat router · Conversation and message endpoints
backend/routers/chat.py - Sentiment router · Sentiment and intent endpoints
backend/routers/sentiment.py - Analytics router · Aggregated metrics endpoints
backend/routers/analytics.py - Auth service · Role and session handling
backend/services/auth_service.py - AI service · Provider abstraction for model calls
backend/services/ai_service.py - Sentiment engine · Classification for mood, intent, and escalation
backend/services/sentiment_engine.py - Database core · Shared database connection and query helpers
backend/core/database.py - Auth model · User and access schemas
backend/models/auth.py - Chat model · Conversation and message schemas
backend/models/chat.py
Data Store
SQL schemas and persistent records
- Users · Platform accounts and roles
database/user.sql - Businesses · Tenant and business records
database/business.sql - Profiles · Business profile data
database/business_profiles.sql - Customers · Tracked customer records
database/customers.sql - Messages · Conversation history storage
database/messages.sql - Events · Derived engagement and omniflow events
database/omniflow_events.sql
Connections 36
- App shell → Shell nav: uses shell · Application frame and shared navigation
- App shell → Auth: renders · Login and access flow
- App shell → Chatbot: renders · Chat experience
- App shell → Conversations: renders · Conversation browsing
- App shell → Dashboard: renders · Overview dashboard
- App shell → Analytics: renders · Analytics views
- App shell → Insights: renders · Derived insights
- App shell → CRM: renders · Customer and business views
- App shell → Purchases: renders · Purchase-related panels
- App shell → Settings: renders · Configuration screens
- API app → Auth router: mounts · Registers auth routes
- API app → Chat router: mounts · Registers chat routes
- API app → Sentiment router: mounts · Registers sentiment routes
- API app → Analytics router: mounts · Registers analytics routes
- Auth router → Auth service: uses · Delegates authentication logic
- Auth service → Auth model: maps · Validates and shapes auth data
- Auth model → Users: persists to · User and role records
- Chat router → Chat model: uses · Conversation payloads and state
- Chat router → Database core: reads/writes · Stores and retrieves messages
- Chat model → Messages: persists to · Chat history storage
- Sentiment router → Sentiment engine: invokes · Runs analysis on conversation text
- Sentiment engine → AI service: depends on · Model/provider access
- AI service → Database core: reads context · May use stored business and customer context
- Analytics router → Database core: aggregates · Builds dashboard metrics from stored data
- Database core → Businesses: queries · Business context
- Database core → Profiles: queries · Business profile data
- Database core → Customers: queries · Customer records
- Database core → Messages: queries · Conversation data
- Database core → Events: queries · Derived events and analytics data
- Dashboard → Analytics router: fetches · Summary metrics for the dashboard
- Analytics → Analytics router: fetches · Charts and reporting data
- Insights → Sentiment router: fetches · Sentiment and alert signals
- CRM → Chat router: fetches · Customer and conversation records
- Conversations → Chat router: fetches · Conversation timeline data
- Auth → Auth router: authenticates · Login and session flow
- Chatbot → Chat router: sends messages · Chat submission and retrieval