# muhammedrafzan/sentra-flow architecture

> Architecture diagram of the GitHub repository muhammedrafzan/sentra-flow, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-04-12). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/muhammedrafzan/sentra-flow
- Repository: https://github.com/muhammedrafzan/sentra-flow

## Overview

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: [`frontend/src/App.tsx`](https://github.com/muhammedrafzan/sentra-flow/blob/main/frontend/src/App.tsx) (App shell), [`backend/core/database.py`](https://github.com/muhammedrafzan/sentra-flow/blob/main/backend/core/database.py) (Database core), [`backend/routers/chat.py`](https://github.com/muhammedrafzan/sentra-flow/blob/main/backend/routers/chat.py) (Chat router), [`backend/main.py`](https://github.com/muhammedrafzan/sentra-flow/blob/main/backend/main.py) (API app)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["Frontend"]
  node_frontend_app["App shell<br/>Vite React SPA<br/>[App.tsx]"]
  node_frontend_auth["Auth<br/>UI module<br/>[Auth.tsx]"]
  node_frontend_chatbot["Chatbot<br/>UI module<br/>[Chatbot.tsx]"]
  node_frontend_conversations["Conversations<br/>UI module<br/>[Conversations.tsx]"]
  node_frontend_dashboard["Dashboard<br/>UI module<br/>[Dashboard.tsx]"]
  node_frontend_analytics["Analytics<br/>UI module<br/>[Analytics.tsx]"]
  node_frontend_insights["Insights<br/>UI module<br/>[Insights.tsx]"]
  node_frontend_crm["CRM<br/>UI module<br/>[CRM.tsx]"]
  node_frontend_purchases["Purchases<br/>UI module<br/>[Purchases.tsx]"]
  node_frontend_settings["Settings<br/>UI module<br/>[Settings.tsx]"]
  node_frontend_nav["Shell nav<br/>UI chrome<br/>[Sidebar.tsx]"]
end

subgraph group_backend["Backend"]
  node_backend_main["API app<br/>FastAPI entrypoint<br/>[main.py]"]
  node_backend_auth_router["Auth router<br/>API router<br/>[auth.py]"]
  node_backend_chat_router["Chat router<br/>API router<br/>[chat.py]"]
  node_backend_sentiment_router["Sentiment router<br/>API router<br/>[sentiment.py]"]
  node_backend_analytics_router["Analytics router<br/>API router<br/>[analytics.py]"]
  node_backend_auth_service["Auth service<br/>Domain service<br/>[auth_service.py]"]
  node_backend_ai_service["AI service<br/>LLM adapter<br/>[ai_service.py]"]
  node_backend_sentiment_engine["Sentiment engine<br/>NLP service"]
  node_backend_database[("Database core<br/>DB access layer<br/>[database.py]")]
  node_backend_models_auth["Auth model<br/>Data model<br/>[auth.py]"]
  node_backend_models_chat["Chat model<br/>Data model<br/>[chat.py]"]
end

subgraph group_data["Data Store"]
  node_db_schema_user["Users<br/>SQL schema<br/>[user.sql]"]
  node_db_schema_business["Businesses<br/>SQL schema<br/>[business.sql]"]
  node_db_schema_profiles["Profiles<br/>SQL schema"]
  node_db_schema_customers["Customers<br/>SQL schema<br/>[customers.sql]"]
  node_db_schema_messages["Messages<br/>SQL schema<br/>[messages.sql]"]
  node_db_schema_events["Events<br/>SQL schema"]
end

node_frontend_app -->|"uses shell"| node_frontend_nav
node_frontend_app -->|"renders"| node_frontend_auth
node_frontend_app -->|"renders"| node_frontend_chatbot
node_frontend_app -->|"renders"| node_frontend_conversations
node_frontend_app -->|"renders"| node_frontend_dashboard
node_frontend_app -->|"renders"| node_frontend_analytics
node_frontend_app -->|"renders"| node_frontend_insights
node_frontend_app -->|"renders"| node_frontend_crm
node_frontend_app -->|"renders"| node_frontend_purchases
node_frontend_app -->|"renders"| node_frontend_settings
node_backend_main -->|"mounts"| node_backend_auth_router
node_backend_main -->|"mounts"| node_backend_chat_router
node_backend_main -->|"mounts"| node_backend_sentiment_router
node_backend_main -->|"mounts"| node_backend_analytics_router
node_backend_auth_router -->|"uses"| node_backend_auth_service
node_backend_auth_service -->|"maps"| node_backend_models_auth
node_backend_models_auth -->|"persists to"| node_db_schema_user
node_backend_chat_router -->|"uses"| node_backend_models_chat
node_backend_chat_router -->|"reads/writes"| node_backend_database
node_backend_models_chat -->|"persists to"| node_db_schema_messages
node_backend_sentiment_router -->|"invokes"| node_backend_sentiment_engine
node_backend_sentiment_engine -->|"depends on"| node_backend_ai_service
node_backend_ai_service -->|"reads context"| node_backend_database
node_backend_analytics_router -->|"aggregates"| node_backend_database
node_backend_database -->|"queries"| node_db_schema_business
node_backend_database -->|"queries"| node_db_schema_profiles
node_backend_database -->|"queries"| node_db_schema_customers
node_backend_database -->|"queries"| node_db_schema_messages
node_backend_database -->|"queries"| node_db_schema_events
node_frontend_dashboard -->|"fetches"| node_backend_analytics_router
node_frontend_analytics -->|"fetches"| node_backend_analytics_router
node_frontend_insights -->|"fetches"| node_backend_sentiment_router
node_frontend_crm -->|"fetches"| node_backend_chat_router
node_frontend_conversations -->|"fetches"| node_backend_chat_router
node_frontend_auth -->|"authenticates"| node_backend_auth_router
node_frontend_chatbot -->|"sends messages"| node_backend_chat_router

click node_frontend_app "https://github.com/muhammedrafzan/sentra-flow/blob/main/frontend/src/App.tsx"
click node_frontend_auth "https://github.com/muhammedrafzan/sentra-flow/blob/main/frontend/src/components/Auth.tsx"
click node_frontend_chatbot "https://github.com/muhammedrafzan/sentra-flow/blob/main/frontend/src/components/Chatbot.tsx"
click node_frontend_conversations "https://github.com/muhammedrafzan/sentra-flow/blob/main/frontend/src/components/Conversations.tsx"
click node_frontend_dashboard "https://github.com/muhammedrafzan/sentra-flow/blob/main/frontend/src/components/Dashboard.tsx"
click node_frontend_analytics "https://github.com/muhammedrafzan/sentra-flow/blob/main/frontend/src/components/Analytics.tsx"
click node_frontend_insights "https://github.com/muhammedrafzan/sentra-flow/blob/main/frontend/src/components/Insights.tsx"
click node_frontend_crm "https://github.com/muhammedrafzan/sentra-flow/blob/main/frontend/src/components/CRM.tsx"
click node_frontend_purchases "https://github.com/muhammedrafzan/sentra-flow/blob/main/frontend/src/components/Purchases.tsx"
click node_frontend_settings "https://github.com/muhammedrafzan/sentra-flow/blob/main/frontend/src/components/Settings.tsx"
click node_frontend_nav "https://github.com/muhammedrafzan/sentra-flow/blob/main/frontend/src/components/Sidebar.tsx"
click node_backend_main "https://github.com/muhammedrafzan/sentra-flow/blob/main/backend/main.py"
click node_backend_auth_router "https://github.com/muhammedrafzan/sentra-flow/blob/main/backend/routers/auth.py"
click node_backend_chat_router "https://github.com/muhammedrafzan/sentra-flow/blob/main/backend/routers/chat.py"
click node_backend_sentiment_router "https://github.com/muhammedrafzan/sentra-flow/blob/main/backend/routers/sentiment.py"
click node_backend_analytics_router "https://github.com/muhammedrafzan/sentra-flow/blob/main/backend/routers/analytics.py"
click node_backend_auth_service "https://github.com/muhammedrafzan/sentra-flow/blob/main/backend/services/auth_service.py"
click node_backend_ai_service "https://github.com/muhammedrafzan/sentra-flow/blob/main/backend/services/ai_service.py"
click node_backend_sentiment_engine "https://github.com/muhammedrafzan/sentra-flow/blob/main/backend/services/sentiment_engine.py"
click node_backend_database "https://github.com/muhammedrafzan/sentra-flow/blob/main/backend/core/database.py"
click node_backend_models_auth "https://github.com/muhammedrafzan/sentra-flow/blob/main/backend/models/auth.py"
click node_backend_models_chat "https://github.com/muhammedrafzan/sentra-flow/blob/main/backend/models/chat.py"
click node_db_schema_user "https://github.com/muhammedrafzan/sentra-flow/blob/main/database/user.sql"
click node_db_schema_business "https://github.com/muhammedrafzan/sentra-flow/blob/main/database/business.sql"
click node_db_schema_profiles "https://github.com/muhammedrafzan/sentra-flow/blob/main/database/business_profiles.sql"
click node_db_schema_customers "https://github.com/muhammedrafzan/sentra-flow/blob/main/database/customers.sql"
click node_db_schema_messages "https://github.com/muhammedrafzan/sentra-flow/blob/main/database/messages.sql"
click node_db_schema_events "https://github.com/muhammedrafzan/sentra-flow/blob/main/database/omniflow_events.sql"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_frontend_app,node_frontend_auth,node_frontend_chatbot,node_frontend_conversations,node_frontend_dashboard,node_frontend_analytics,node_frontend_insights,node_frontend_crm,node_frontend_purchases,node_frontend_settings,node_frontend_nav toneBlue
class node_backend_main,node_backend_auth_router,node_backend_chat_router,node_backend_sentiment_router,node_backend_analytics_router,node_backend_auth_service,node_backend_ai_service,node_backend_sentiment_engine,node_backend_database,node_backend_models_auth,node_backend_models_chat toneAmber
class node_db_schema_user,node_db_schema_business,node_db_schema_profiles,node_db_schema_customers,node_db_schema_messages,node_db_schema_events toneMint
```

## Components

### Frontend

React SPA for operators and analysts

- [App shell](https://github.com/muhammedrafzan/sentra-flow/blob/main/frontend/src/App.tsx): Vite React SPA · Client entry and top-level application composition · `frontend/src/App.tsx`
- [Auth](https://github.com/muhammedrafzan/sentra-flow/blob/main/frontend/src/components/Auth.tsx): UI module · Login and session screens · `frontend/src/components/Auth.tsx`
- [Chatbot](https://github.com/muhammedrafzan/sentra-flow/blob/main/frontend/src/components/Chatbot.tsx): UI module · Chat interaction surface · `frontend/src/components/Chatbot.tsx`
- [Conversations](https://github.com/muhammedrafzan/sentra-flow/blob/main/frontend/src/components/Conversations.tsx): UI module · Conversation history and message browsing · `frontend/src/components/Conversations.tsx`
- [Dashboard](https://github.com/muhammedrafzan/sentra-flow/blob/main/frontend/src/components/Dashboard.tsx): UI module · Operator overview and summary panels · `frontend/src/components/Dashboard.tsx`
- [Analytics](https://github.com/muhammedrafzan/sentra-flow/blob/main/frontend/src/components/Analytics.tsx): UI module · Metrics and trend views · `frontend/src/components/Analytics.tsx`
- [Insights](https://github.com/muhammedrafzan/sentra-flow/blob/main/frontend/src/components/Insights.tsx): UI module · Derived recommendations and alerts · `frontend/src/components/Insights.tsx`
- [CRM](https://github.com/muhammedrafzan/sentra-flow/blob/main/frontend/src/components/CRM.tsx): UI module · Customer and business records · `frontend/src/components/CRM.tsx`
- [Purchases](https://github.com/muhammedrafzan/sentra-flow/blob/main/frontend/src/components/Purchases.tsx): UI module · Purchase-oriented business views · `frontend/src/components/Purchases.tsx`
- [Settings](https://github.com/muhammedrafzan/sentra-flow/blob/main/frontend/src/components/Settings.tsx): UI module · App and account configuration · `frontend/src/components/Settings.tsx`
- [Shell nav](https://github.com/muhammedrafzan/sentra-flow/blob/main/frontend/src/components/Sidebar.tsx): UI chrome · Shared sidebar and top navigation · `frontend/src/components/Sidebar.tsx`

### Backend

FastAPI application and domain logic

- [API app](https://github.com/muhammedrafzan/sentra-flow/blob/main/backend/main.py): FastAPI entrypoint · Application startup, middleware, and router wiring · `backend/main.py`
- [Auth router](https://github.com/muhammedrafzan/sentra-flow/blob/main/backend/routers/auth.py): API router · Authentication endpoints · `backend/routers/auth.py`
- [Chat router](https://github.com/muhammedrafzan/sentra-flow/blob/main/backend/routers/chat.py): API router · Conversation and message endpoints · `backend/routers/chat.py`
- [Sentiment router](https://github.com/muhammedrafzan/sentra-flow/blob/main/backend/routers/sentiment.py): API router · Sentiment and intent endpoints · `backend/routers/sentiment.py`
- [Analytics router](https://github.com/muhammedrafzan/sentra-flow/blob/main/backend/routers/analytics.py): API router · Aggregated metrics endpoints · `backend/routers/analytics.py`
- [Auth service](https://github.com/muhammedrafzan/sentra-flow/blob/main/backend/services/auth_service.py): Domain service · Role and session handling · `backend/services/auth_service.py`
- [AI service](https://github.com/muhammedrafzan/sentra-flow/blob/main/backend/services/ai_service.py): LLM adapter · Provider abstraction for model calls · `backend/services/ai_service.py`
- [Sentiment engine](https://github.com/muhammedrafzan/sentra-flow/blob/main/backend/services/sentiment_engine.py): NLP service · Classification for mood, intent, and escalation · `backend/services/sentiment_engine.py`
- [Database core](https://github.com/muhammedrafzan/sentra-flow/blob/main/backend/core/database.py): DB access layer · Shared database connection and query helpers · `backend/core/database.py`
- [Auth model](https://github.com/muhammedrafzan/sentra-flow/blob/main/backend/models/auth.py): Data model · User and access schemas · `backend/models/auth.py`
- [Chat model](https://github.com/muhammedrafzan/sentra-flow/blob/main/backend/models/chat.py): Data model · Conversation and message schemas · `backend/models/chat.py`

### Data Store

SQL schemas and persistent records

- [Users](https://github.com/muhammedrafzan/sentra-flow/blob/main/database/user.sql): SQL schema · Platform accounts and roles · `database/user.sql`
- [Businesses](https://github.com/muhammedrafzan/sentra-flow/blob/main/database/business.sql): SQL schema · Tenant and business records · `database/business.sql`
- [Profiles](https://github.com/muhammedrafzan/sentra-flow/blob/main/database/business_profiles.sql): SQL schema · Business profile data · `database/business_profiles.sql`
- [Customers](https://github.com/muhammedrafzan/sentra-flow/blob/main/database/customers.sql): SQL schema · Tracked customer records · `database/customers.sql`
- [Messages](https://github.com/muhammedrafzan/sentra-flow/blob/main/database/messages.sql): SQL schema · Conversation history storage · `database/messages.sql`
- [Events](https://github.com/muhammedrafzan/sentra-flow/blob/main/database/omniflow_events.sql): SQL schema · Derived engagement and omniflow events · `database/omniflow_events.sql`

## Connections

- 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
