# tejas-2232/gemchat-rs architecture

> Architecture diagram of the GitHub repository tejas-2232/gemchat-rs, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-11-22). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/tejas-2232/gemchat-rs
- Repository: https://github.com/tejas-2232/gemchat-rs

## Overview

##### Project type and purpose
- This is a Rust-based, standalone microservice (using Axum async framework) that exposes a REST API and an embeddable JS widget.
- Its purpose is to serve as a cybersecurity-focused chatbot powered by Google Gemini AI. It can either be called directly via HTTP POST (/api/chat) or loaded in any web page as a drop-in widget (widget.js).

##### File structure
- Top-level files:
- Cargo.toml – Rust dependencies and metadata
- Dockerfile/docker-compose.yml – containerization and multi-container orchestration
- env.example/.env – environment variable template (GEMINI_API_KEY, PORT, RUST_LOG)
- README.md/troubleshooting.md – docs
- src/ directory:
- main.rs – HTTP server setup, route definitions (/health, /api/chat, /widget.js, static/*)
- gemini.rs – logic for calling Google Gemini API and building the system prompt
- models.rs – request/response structs for serialization (serde)
- static/:
- widget.js – client-side script that bootstraps the widget, fetches /api/chat, injects HTML/CSS into host page
- widget-test.html – example of widget integration
- No database directory/files: state is ephemeral per request, logs shipped via tracing.

##### README for additional insights
- “Two Integration Methods” (REST vs widget) implies two client-facing entry points.
- Highlights CORS-enabled, structured logging (tracing), Docker-ready.
- Mentions environment-driven config, reverse-proxy recommendation (nginx/Traefik), scaling behind LB.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Client Tier"
        direction TB
        WebApp["Web App (React/Any JS)"]:::client
        WidgetIntegration["Example HTML Demo"]:::client
    end

    subgraph "Microservice Tier"
        direction TB
        Router["HTTP Server & Route Definitions"]:::service
        Models["Request/Response Data Models"]:::service
        GeminiClient["Google Gemini AI Client Module"]:::service
        StaticAssets["Embeddable JavaScript Widget"]:::static
        Telemetry["Telemetry & Logging (tracing)"]:::service
        Metrics["Metrics Endpoint"]:::service
    end

    subgraph "Infrastructure"
        direction TB
        ReverseProxy["Reverse Proxy / Load Balancer"]:::infra
        DockerHost["Docker Container"]:::infra
        EnvStore["Environment Variables"]:::infra
        LoggingMetrics["Logging & Monitoring Backend"]:::external
    end

    GoogleGemini["Google Gemini AI API"]:::external

    %% Client to Service
    WebApp -->|POST /api/chat| Router
    WidgetIntegration -->|loads widget.js| StaticAssets
    WidgetIntegration -->|POST /api/chat| Router

    %% Service internals
    Router -->|uses models| Models
    Router -->|calls AI client| GeminiClient
    Router -->|serves static| StaticAssets
    Router -->|logs events| Telemetry
    Router -->|exposes metrics| Metrics
    GeminiClient -->|HTTPS call| GoogleGemini
    GeminiClient -->|uses models| Models

    %% Infrastructure interactions
    ReverseProxy -->|routes traffic| DockerHost
    DockerHost -->|runs service| Router
    DockerHost -->|provides env| EnvStore
    DockerHost -->|ships logs/metrics| LoggingMetrics
    DockerHost -->|exports metrics| LoggingMetrics

    %% Click events
    click Router "https://github.com/tejas-2232/gemchat-rs/blob/main/src/main.rs"
    click Models "https://github.com/tejas-2232/gemchat-rs/blob/main/src/models.rs"
    click GeminiClient "https://github.com/tejas-2232/gemchat-rs/blob/main/src/gemini.rs"
    click StaticAssets "https://github.com/tejas-2232/gemchat-rs/blob/main/static/widget.js"
    click Cargo "https://github.com/tejas-2232/gemchat-rs/blob/main/Cargo.toml"
    click Dockerfile "https://github.com/tejas-2232/gemchat-rs/tree/main/Dockerfile"
    click Compose "https://github.com/tejas-2232/gemchat-rs/blob/main/docker-compose.yml"
    click EnvStore "https://github.com/tejas-2232/gemchat-rs/blob/main/env.example"
    click README "https://github.com/tejas-2232/gemchat-rs/blob/main/README.md"
    click Troubleshoot "https://github.com/tejas-2232/gemchat-rs/blob/main/troubleshooting.md"
    click WidgetIntegration "https://github.com/tejas-2232/gemchat-rs/blob/main/widget-test.html"

    %% Documentation nodes
    Cargo["Rust Project Configuration & Dependencies"]:::infra
    Dockerfile["Dockerfile"]:::infra
    Compose["docker-compose.yml"]:::infra
    EnvFile["Env Template"]:::infra
    README["README.md"]:::infra
    Troubleshoot["troubleshooting.md"]:::infra

    %% Connections to documentation
    DockerHost --> Cargo
    DockerHost --> Dockerfile
    DockerHost --> Compose
    DockerHost --> EnvStore
    DockerHost --> README
    DockerHost --> Troubleshoot

    classDef client fill:#ADD8E6,stroke:#333,stroke-width:1px
    classDef service fill:#90EE90,stroke:#333,stroke-width:1px
    classDef static fill:#FFD700,stroke:#333,stroke-width:1px
    classDef infra fill:#87CEFA,stroke:#333,stroke-width:1px
    classDef external fill:#F08080,stroke:#333,stroke-width:1px
```
