# stackoverflowed512/customised_flyer architecture

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

- Interactive diagram: https://gitdiagram.com/stackoverflowed512/customised_flyer
- Repository: https://github.com/stackoverflowed512/customised_flyer

## Overview

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: [`app/main.py`](https://github.com/stackoverflowed512/customised_flyer/blob/main/app/main.py) (App host), [`app/services/agent.py`](https://github.com/stackoverflowed512/customised_flyer/blob/main/app/services/agent.py) (Agent core), [`static/chatbot-widget.js`](https://github.com/stackoverflowed512/customised_flyer/blob/main/static/chatbot-widget.js) (Widget), [`static/index.html`](https://github.com/stackoverflowed512/customised_flyer/blob/main/static/index.html) (Web UI)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Runtime"]
  node_main["App host<br/>FastAPI entrypoint<br/>[main.py]"]
end

subgraph group_backend["Backend"]
  node_config["Config<br/>Settings loader<br/>[config.py]"]
  node_models[("DB models<br/>SQLAlchemy schema<br/>[models.py]")]
  node_agent{{"Agent core<br/>LLM orchestration<br/>[agent.py]"}}
  node_tools["Tools<br/>Agent helpers<br/>[tools.py]"]
end

subgraph group_frontend["Frontend"]
  node_ui["Web UI<br/>Static SPA<br/>[index.html]"]
  node_ui_js["UI logic<br/>Client script<br/>[app.js]"]
  node_styles["Styles<br/>CSS<br/>[style.css]"]
  node_widget["Widget<br/>Embeddable chat<br/>[chatbot-widget.js]"]
end

subgraph group_data["Data"]
  node_presets["Presets<br/>Domain config"]
  node_kb["Knowledge base<br/>Grounding text<br/>[knowledge_base.txt]"]
  node_uploads["Uploads<br/>User brochures"]
  node_db[("Chat DB<br/>SQLite/Postgres<br/>[chat_agent.db]")]
  node_pdf_gen["PDF generator<br/>Test tooling"]
end

subgraph group_integrations["Integrations"]
  node_examples["Examples<br/>Integration demos"]
  node_react["React demo<br/>Example frontend<br/>[Chatbot.jsx]"]
  node_api_test["API client<br/>Example script<br/>[test_api.py]"]
end

node_main -->|"loads"| node_config
node_main -->|"uses"| node_models
node_main -->|"routes to"| node_agent
node_main -->|"serves"| node_ui
node_main -->|"serves"| node_widget
node_agent -->|"selects"| node_presets
node_agent -->|"calls"| node_tools
node_agent -->|"grounds on"| node_kb
node_agent -->|"consumes"| node_uploads
node_agent -->|"records"| node_db
node_models -->|"maps to"| node_db
node_ui -->|"loads"| node_ui_js
node_ui -->|"styles"| node_styles
node_ui_js -->|"calls API"| node_main
node_widget -->|"calls API"| node_main
node_examples -.->|"demonstrates"| node_main
node_examples -.->|"embeds"| node_widget
node_react -.->|"uses"| node_widget
node_api_test -.->|"exercises"| node_main
node_pdf_gen -.->|"generates"| node_uploads

click node_main "https://github.com/stackoverflowed512/customised_flyer/blob/main/app/main.py"
click node_config "https://github.com/stackoverflowed512/customised_flyer/blob/main/app/core/config.py"
click node_models "https://github.com/stackoverflowed512/customised_flyer/blob/main/app/models.py"
click node_agent "https://github.com/stackoverflowed512/customised_flyer/blob/main/app/services/agent.py"
click node_tools "https://github.com/stackoverflowed512/customised_flyer/blob/main/app/services/tools.py"
click node_presets "https://github.com/stackoverflowed512/customised_flyer/blob/main/data/domain_presets.json"
click node_kb "https://github.com/stackoverflowed512/customised_flyer/blob/main/data/knowledge_base.txt"
click node_uploads "https://github.com/stackoverflowed512/customised_flyer/tree/main/data/uploads"
click node_db "https://github.com/stackoverflowed512/customised_flyer/blob/main/data/chat_agent.db"
click node_ui "https://github.com/stackoverflowed512/customised_flyer/blob/main/static/index.html"
click node_ui_js "https://github.com/stackoverflowed512/customised_flyer/blob/main/static/app.js"
click node_styles "https://github.com/stackoverflowed512/customised_flyer/blob/main/static/style.css"
click node_widget "https://github.com/stackoverflowed512/customised_flyer/blob/main/static/chatbot-widget.js"
click node_examples "https://github.com/stackoverflowed512/customised_flyer/tree/main/examples"
click node_react "https://github.com/stackoverflowed512/customised_flyer/blob/main/examples/react-chatbot/Chatbot.jsx"
click node_api_test "https://github.com/stackoverflowed512/customised_flyer/blob/main/examples/test_api.py"
click node_pdf_gen "https://github.com/stackoverflowed512/customised_flyer/blob/main/scripts/generate_test_pdfs.py"

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_main toneBlue
class node_config,node_models,node_agent,node_tools toneAmber
class node_ui,node_ui_js,node_styles,node_widget toneMint
class node_presets,node_kb,node_uploads,node_db,node_pdf_gen toneRose
class node_examples,node_react,node_api_test toneIndigo
```

## Components

### Runtime

Single FastAPI process serving UI and API

- [App host](https://github.com/stackoverflowed512/customised_flyer/blob/main/app/main.py): FastAPI entrypoint · Starts the web app, mounts API routes, and serves static assets. · `app/main.py`

### Backend

Application orchestration, API, and persistence

- [Config](https://github.com/stackoverflowed512/customised_flyer/blob/main/app/core/config.py): Settings loader · Loads runtime settings such as API keys and database URL. · `app/core/config.py`
- [DB models](https://github.com/stackoverflowed512/customised_flyer/blob/main/app/models.py): SQLAlchemy schema · Defines persistent chat, analytics, and app state structures. · `app/models.py`
- [Agent core](https://github.com/stackoverflowed512/customised_flyer/blob/main/app/services/agent.py): LLM orchestration · Builds prompts, selects presets, and coordinates model calls. · `app/services/agent.py`
- [Tools](https://github.com/stackoverflowed512/customised_flyer/blob/main/app/services/tools.py): Agent helpers · Supporting capabilities used during retrieval and response assembly. · `app/services/tools.py`

### Frontend

Browser UI and embeddable widget

- [Web UI](https://github.com/stackoverflowed512/customised_flyer/blob/main/static/index.html): Static SPA · Main browser interface served from the FastAPI process. · `static/index.html`
- [UI logic](https://github.com/stackoverflowed512/customised_flyer/blob/main/static/app.js): Client script · Browser-side application logic for chat and dashboard interactions. · `static/app.js`
- [Styles](https://github.com/stackoverflowed512/customised_flyer/blob/main/static/style.css): CSS · Presentation layer for the built-in web interface. · `static/style.css`
- [Widget](https://github.com/stackoverflowed512/customised_flyer/blob/main/static/chatbot-widget.js): Embeddable chat · Reusable chatbot component for external sites. · `static/chatbot-widget.js`

### Data

Local configuration, knowledge, and database

- [Presets](https://github.com/stackoverflowed512/customised_flyer/blob/main/data/domain_presets.json): Domain config · Domain personas and behavior templates that shape assistant responses. · `data/domain_presets.json`
- [Knowledge base](https://github.com/stackoverflowed512/customised_flyer/blob/main/data/knowledge_base.txt): Grounding text · Local reference content used to ground brochure-aware responses. · `data/knowledge_base.txt`
- [Uploads](https://github.com/stackoverflowed512/customised_flyer/tree/main/data/uploads): User brochures · Incoming brochure PDFs and text assets associated with chats. · `data/uploads`
- [Chat DB](https://github.com/stackoverflowed512/customised_flyer/blob/main/data/chat_agent.db): SQLite/Postgres · Operational store for sessions, messages, analytics, and configuration state. · `data/chat_agent.db`
- [PDF generator](https://github.com/stackoverflowed512/customised_flyer/blob/main/scripts/generate_test_pdfs.py): Test tooling · Creates sample brochure PDFs for the ingestion flow. · `scripts/generate_test_pdfs.py`

### Integrations

External examples and client surfaces

- [Examples](https://github.com/stackoverflowed512/customised_flyer/tree/main/examples): Integration demos · Sample integrations showing HTML, React, and API client usage. · `examples`
- [React demo](https://github.com/stackoverflowed512/customised_flyer/blob/main/examples/react-chatbot/Chatbot.jsx): Example frontend · React-based chatbot example showing external embedding. · `examples/react-chatbot/Chatbot.jsx`
- [API client](https://github.com/stackoverflowed512/customised_flyer/blob/main/examples/test_api.py): Example script · Simple test client for exercising the REST API. · `examples/test_api.py`

## Connections

- 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.
