How stackoverflowed512/customised_flyer works
1. What this repo is
- OmniAgent is a single Python service that combines a browser UI, a REST API, an LLM-backed agent, and a local persistence layer to deliver domain-specific chat assistants.
- The architecture is centered on one FastAPI application rather than separate frontend/backend deployments.
2. Core runtime boundary
- app/main.py is the entrypoint and FastAPI host.
- It serves both the API routes and the static web assets from static/, so the web UI and backend live in the same runtime/process boundary.
3. API layer
- The main external contract is the REST API documented in README_API.md and API_DOCUMENTATION.md.
- Key endpoints include chat, preset discovery, brochure upload/configuration, and analytics retrieval.
- This layer is the boundary for both the built-in UI and third-party integrations shown in examples/.
4. Agent and reasoning layer
- app/services/agent.py appears to be the central orchestration layer for prompt construction, persona selection, and LLM interaction.
- The README indicates Mistral AI is the external model provider, so the agent layer is where user input, domain preset, and uploaded knowledge are combined before the model call.
- app/services/tools.py likely contains helper capabilities used by the agent, such as retrieval, formatting, or domain-specific operations.
5. Domain configuration and presets
- data/domain_presets.json is a key configuration artifact: it provides the industry templates/personalities that shape the assistant’s behavior.
- This makes the assistant multi-domain without code changes; selecting a preset changes the agent’s tone, scope, and response framing.
6. Knowledge ingestion pipeline
- Uploaded brochures are stored under data/uploads/ and the repo also contains sample brochures in data/test_knowledge_base/ and static/flyers/.
- The system is designed to extract text from PDF/Text inputs and use that content as grounding for chat responses.
- scripts/generate_test_pdfs.py suggests the repo includes tooling to create or refresh test knowledge documents for the ingestion flow.
7. Persistence and state
- app/models.py defines the database schema, with SQLite as the default local store via data/chat_agent.db.
- The README also supports PostgreSQL through DATABASE_URL, so the persistence boundary is abstracted through SQLAlchemy rather than hard-coded to SQLite.
- This database likely holds sessions, messages, analytics, and configuration state used by the dashboard.
8. Frontend surfaces
- static/index.html, static/style.css, and static/app.js implement the main browser UI.
- static/chatbot-widget.js provides an embeddable chat component for integrating OmniAgent into external sites.
- The examples/ directory shows multiple integration surfaces: plain HTML, a custom UI, a React example, and a test API client.
9. Analytics and administration
- The README describes a dashboard for session duration, engagement, and topic tracking, which implies a separate read path over the same operational data stored in the database.
- This is an internal/admin-facing view, but it is not a separate service; it is another presentation layer over the backend state.
10. Operational dependencies and deployment shape
- Environment is configured through .env using at least MISTRAL_API_KEY and DATABASE_URL.
- The repo is built to run under Uvicorn, with FastAPI handling the HTTP server role.
- requirements.txt, DEPLOYMENT_GUIDE.md, DEPLOYMENT_CHECKLIST.txt, and GETTING_STARTED.md indicate the deployment model is intentionally lightweight and self-contained, with no mandatory external infrastructure beyond the LLM API and chosen database.
11. How data moves through the system
- Chat flow: user message enters the API/UI → backend assembles preset + history + uploaded knowledge → agent calls Mistral → response is returned and likely recorded for analytics.
- Upload flow: brochure enters upload endpoint → document text is extracted and stored/associated with the agent context → later chat requests use that content as grounding.
- Analytics flow: interaction metadata is captured during chat and read back through the analytics endpoint/dashboard.
12. Important architectural boundaries to diagram
- UI vs backend: the static frontend is served by the same FastAPI app, but it is still a separate presentation layer from the API/agent logic.
- Orchestration vs model provider: agent.py owns logic; Mistral is an external service.
- Configuration vs runtime state: preset JSON and .env provide startup configuration, while SQLite/PostgreSQL holds dynamic sessions and analytics.
Main entry points: main.py App host · agent.py Agent core · chatbot-widget.js Widget · index.html Web UI
Components 17
Runtime
Single FastAPI process serving UI and API
- App host · Starts the web app, mounts API routes, and serves static assets.
app/main.py
Backend
Application orchestration, API, and persistence
- Config · Loads runtime settings such as API keys and database URL.
app/core/config.py - DB models · Defines persistent chat, analytics, and app state structures.
app/models.py - Agent core · Builds prompts, selects presets, and coordinates model calls.
app/services/agent.py - Tools · Supporting capabilities used during retrieval and response assembly.
app/services/tools.py
Frontend
Browser UI and embeddable widget
- Web UI · Main browser interface served from the FastAPI process.
static/index.html - UI logic · Browser-side application logic for chat and dashboard interactions.
static/app.js - Styles · Presentation layer for the built-in web interface.
static/style.css - Widget · Reusable chatbot component for external sites.
static/chatbot-widget.js
Data
Local configuration, knowledge, and database
- Presets · Domain personas and behavior templates that shape assistant responses.
data/domain_presets.json - Knowledge base · Local reference content used to ground brochure-aware responses.
data/knowledge_base.txt - Uploads · Incoming brochure PDFs and text assets associated with chats.
data/uploads - Chat DB · Operational store for sessions, messages, analytics, and configuration state.
data/chat_agent.db - PDF generator · Creates sample brochure PDFs for the ingestion flow.
scripts/generate_test_pdfs.py
Integrations
External examples and client surfaces
- Examples · Sample integrations showing HTML, React, and API client usage.
examples - React demo · React-based chatbot example showing external embedding.
examples/react-chatbot/Chatbot.jsx - API client · Simple test client for exercising the REST API.
examples/test_api.py
Connections 20
- App host → Config: loads · Bootstraps runtime settings before serving requests.
- App host → DB models: uses · Initializes persistence and data access.
- App host → Agent core: routes to · Hands chat and domain requests to the orchestration layer.
- App host → Web UI: serves · Hosts the browser UI from the same process.
- App host → Widget: serves · Exposes the embeddable widget as static asset.
- Agent core → Presets: selects · Applies domain persona and response framing.
- Agent core → Tools: calls · Uses helper operations during prompt assembly and retrieval.
- Agent core → Knowledge base: grounds on · Includes reference content when building responses.
- Agent core → Uploads: consumes · Uses uploaded brochures as contextual knowledge.
- Agent core → Chat DB: records · Stores sessions, messages, and analytics.
- DB models → Chat DB: maps to · Defines the persistent schema over the local database.
- Web UI → UI logic: loads · HTML shell is driven by browser-side app logic.
- Web UI → Styles: styles · Presentation is provided by the stylesheet.
- UI logic → App host: calls API · Browser UI talks to the FastAPI endpoints.
- Widget → App host: calls API · Embedded widget uses the same backend contract.
- Examples → App host: demonstrates · Integration samples target the REST API and widget.
- Examples → Widget: embeds · Some examples show widget usage in external pages.
- React demo → Widget: uses · React demo integrates the chatbot component.
- API client → App host: exercises · Client script validates the API boundary.
- PDF generator → Uploads: generates · Produces sample brochure documents for ingestion testing.