# amsterdam-ai-team/citizen-signals-rag-chatbot-system architecture

> Architecture diagram of the GitHub repository amsterdam-ai-team/citizen-signals-rag-chatbot-system, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-03-29). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/amsterdam-ai-team/citizen-signals-rag-chatbot-system
- Repository: https://github.com/amsterdam-ai-team/citizen-signals-rag-chatbot-system

## Overview

##### Project Type and Purpose
- This project is an agentic Retrieval Augmented Generation (RAG) system aimed at automating responses for citizen reports in Amsterdam.
- Its purpose is to retrieve and combine relevant information from various data sources, enabling quick, context-aware responses to citizen reports while reducing municipal workload.

##### File Structure
- The top-level files indicate configuration (.flake8, .gitignore, requirements.txt) and licensing, demonstrating proper development discipline.
- The key directories include:
- src: Contains the core Python modules including the central agent (central_agentic_agent.py), configuration (config.py), process logic (process_melding.py), database population scripts (populate_permit_db_faiss.py, populate_policy_db_chroma.py), and a tools folder which houses individual tool scripts (for tasks such as address handling, license plate processing, etc.).
- helpers: Under src/helpers, utility functions (embedding_helpers, geo_utils, melding_helpers) support the central logic.
- static and templates: Provide the front-end components, suggesting that the system includes a web-based chatbot UI (app.py in src is used to start this interface).
- media: Contains demonstration media (demo.mov and demo-image) used in the README.
- The architecture exhibits a separation between:
- The core orchestration/logic layer (central agent).
- Supporting tool components for specialized tasks.
- Frontend/Interface (via static assets, templates, and app.py).
- Configuration and deployment scripts (e.g., pre-commit hooks, blobfuse for internal storage integration).

##### Key Components to Highlight
- Frontend/UI Component:
- app.py serves as the entry point for the web interface.
- Static assets (styles.css, scripts.js, images) and HTML template (index.html) are used for presenting the chatbot.
- Core Logic (Backend):
- The central agent (central_agentic_agent.py) orchestrates the processing by receiving citizen reports and delegating tasks to specific tools.
- The configuration module (config.py) sets up the agent’s parameters, guidelines, and instructions.
- Tools and Helper Modules:
- Various tool scripts in src/tools (e.g., address_owner_tool, license_plate_permit_tool, etc.), each designed to process different types of citizen reports.
- Helper functions (embedding_helpers, geo_utils, melding_helpers) for preprocessing data, embeddings, or geospatial calculations.
- Data Ingestion/Population:
- Scripts like populate_permit_db_faiss.py and populate_policy_db_chroma.py indicate processes for populating or interfacing with internal databases (likely for historical or contextual data).
- External Services/Integration:
- Integration with an LLM (e.g., GPT-4o or other open-source models) is a central part of the reasoning and result assembly.
- Built-in instructions for API keys (via a secrets file, API_KEYS) and potential external services like Azure ML for deployment.
- Internal Storage:
- A blobfuse script suggests that there is mounting of internal storage containers for sensitive meldingen data.

##### Relationships and Interactions
- The central agent takes input (a report or query) from the frontend and then:
- Retrieves necessary information via calls to appropriate tool components.
- Interacts with helper modules for data processing.
- Interfaces with the LLM to generate the final response.
- Data flows should indicate:
- From user entry (chat interface) → central agent.
- The agent routes to various tools (each represented as separate components) → collates results and delivers a consolidated output.

##### Architectural Patterns and Technologies
- Emphasis on decoupling (central agent vs. individual tool modules).
- Clearly separate presentation (frontend web UI) from business logic (backend central agent and tools).
- RAG (Retrieval Augmented Generation) pattern where retrieval (database lookups, tool functions) feeds into a generation module (LLM).
- Technologies and frameworks:
- Python for backend logic; templates and static assets for the frontend.
- Use of API integrations (e.g., with OpenAI and Azure ML) and configuration management.

## Diagram (Mermaid)

```mermaid
graph TD
    %% Frontend/UI Layer
    subgraph "Frontend/UI"
        APP["Web Interface (app.py)"]:::frontend
        HTML["HTML Template (index.html)"]:::frontend
        STATIC["Static Assets (styles.css, scripts.js, images)"]:::frontend
    end

    %% Core Backend Layer
    subgraph "Backend Core"
        CENTRAL["Central Agent (central_agentic_agent.py)"]:::backend
        CONFIG["Configuration (config.py)"]:::backend
        PROCESS["Report Processing (process_melding.py)"]:::backend
    end

    %% Tools & Helpers Layer
    subgraph "Tools and Helper Modules"
        ADDRESS["Address Tool (address_owner_tool.py)"]:::tools
        LICENSE["License Plate Tool (license_plate_permit_tool.py)"]:::tools
        MELDING["Meldingen Tool (meldingen_tool.py)"]:::tools
        BGT["BGT Features Tool (bgt_features_tool.py)"]:::tools
        NOISE["Noise Permits Tool (noise_permits_tool.py)"]:::tools
        POLICY["Policy Retrieval Tool (policy_retriever_tool.py)"]:::tools
        EMBEDDING["Embedding Helpers (embedding_helpers.py)"]:::helper
        GEO["Geospatial Utilities (geo_utils.py)"]:::helper
        MELDING_HELP["Melding Helpers (melding_helpers.py)"]:::helper
    end

    %% Data Ingestion/Population Layer
    subgraph "Data Ingestion/Population"
        PERMIT["Permit DB Population (populate_permit_db_faiss.py)"]:::data
        POLICY_POP["Policy DB Population (populate_policy_db_chroma.py)"]:::data
    end

    %% External Services Layer
    subgraph "External Services"
        LLM["LLM/External API"]:::external
        AZURE["Azure ML/Deployment"]:::external
    end

    %% Connections
    APP -->|"ReportSubmission"| CENTRAL
    CENTRAL -->|"Uses"| CONFIG
    CENTRAL -->|"Processes"| PROCESS
    CENTRAL -->|"DelegatesTo"| ADDRESS
    CENTRAL -->|"DelegatesTo"| LICENSE
    CENTRAL -->|"DelegatesTo"| MELDING
    CENTRAL -->|"DelegatesTo"| BGT
    CENTRAL -->|"DelegatesTo"| NOISE
    CENTRAL -->|"DelegatesTo"| POLICY
    CENTRAL -->|"Utilizes"| EMBEDDING
    CENTRAL -->|"Utilizes"| GEO
    CENTRAL -->|"Utilizes"| MELDING_HELP
    CENTRAL -->|"GeneratesResponse"| LLM
    CENTRAL -->|"DeploymentIntegration"| AZURE

    %% Data ingestion feeds into tool modules (implied data availability)
    PERMIT -->|"ProvidesData"| ADDRESS
    PERMIT -->|"ProvidesData"| LICENSE
    POLICY_POP -->|"ProvidesData"| POLICY

    %% Styles
    classDef frontend fill:#ffebcd,stroke:#333,stroke-width:2px;
    classDef backend fill:#add8e6,stroke:#333,stroke-width:2px;
    classDef tools fill:#98fb98,stroke:#333,stroke-width:2px;
    classDef helper fill:#ffb6c1,stroke:#333,stroke-width:2px;
    classDef data fill:#fffacd,stroke:#333,stroke-width:2px;
    classDef external fill:#e0ffff,stroke:#333,stroke-width:2px;

    %% Click Events
    click APP "https://github.com/amsterdam-ai-team/citizen-signals-rag-chatbot-system/blob/main/src/app.py"
    click HTML "https://github.com/amsterdam-ai-team/citizen-signals-rag-chatbot-system/blob/main/templates/index.html"
    click STATIC "https://github.com/amsterdam-ai-team/citizen-signals-rag-chatbot-system/blob/main/static/styles.css"
    click CENTRAL "https://github.com/amsterdam-ai-team/citizen-signals-rag-chatbot-system/blob/main/src/central_agentic_agent.py"
    click CONFIG "https://github.com/amsterdam-ai-team/citizen-signals-rag-chatbot-system/blob/main/src/config.py"
    click PROCESS "https://github.com/amsterdam-ai-team/citizen-signals-rag-chatbot-system/blob/main/src/process_melding.py"
    click ADDRESS "https://github.com/amsterdam-ai-team/citizen-signals-rag-chatbot-system/blob/main/src/tools/address_owner_tool.py"
    click LICENSE "https://github.com/amsterdam-ai-team/citizen-signals-rag-chatbot-system/blob/main/src/tools/license_plate_permit_tool.py"
    click MELDING "https://github.com/amsterdam-ai-team/citizen-signals-rag-chatbot-system/blob/main/src/tools/meldingen_tool.py"
    click BGT "https://github.com/amsterdam-ai-team/citizen-signals-rag-chatbot-system/blob/main/src/tools/bgt_features_tool.py"
    click NOISE "https://github.com/amsterdam-ai-team/citizen-signals-rag-chatbot-system/blob/main/src/tools/noise_permits_tool.py"
    click POLICY "https://github.com/amsterdam-ai-team/citizen-signals-rag-chatbot-system/blob/main/src/tools/policy_retriever_tool.py"
    click EMBEDDING "https://github.com/amsterdam-ai-team/citizen-signals-rag-chatbot-system/blob/main/src/helpers/embedding_helpers.py"
    click GEO "https://github.com/amsterdam-ai-team/citizen-signals-rag-chatbot-system/blob/main/src/helpers/geo_utils.py"
    click MELDING_HELP "https://github.com/amsterdam-ai-team/citizen-signals-rag-chatbot-system/blob/main/src/helpers/melding_helpers.py"
    click PERMIT "https://github.com/amsterdam-ai-team/citizen-signals-rag-chatbot-system/blob/main/src/populate_permit_db_faiss.py"
    click POLICY_POP "https://github.com/amsterdam-ai-team/citizen-signals-rag-chatbot-system/blob/main/src/populate_policy_db_chroma.py"
```
