# bhv1122/generative-ai- architecture

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

- Interactive diagram: https://gitdiagram.com/bhv1122/generative-ai-
- Repository: https://github.com/bhv1122/generative-ai-

## Overview

This Flask web app provides authenticated, stateful AI chat, with account settings and conversation history. The main workflow is: a user signs in, submits a nonblank message, the app stores it and loads recent history, then sends the prompt and context to Gemini and returns a reply. MongoDB holds user and session records; the persistence layer also exposes bounded history retrieval. The excerpts confirm OAuth providers and theme syncing. Chat UI wiring and some route implementations were not sampled, so their internal links are omitted where uncertain.

Main entry points: [`app.py`](https://github.com/bhv1122/generative-ai-/blob/main/app.py) (Flask routes), [`templates/chat.html`](https://github.com/bhv1122/generative-ai-/blob/main/templates/chat.html) (Browser UI), [`database.py`](https://github.com/bhv1122/generative-ai-/blob/main/database.py) (Persistence helpers), [`static/js/main.js`](https://github.com/bhv1122/generative-ai-/blob/main/static/js/main.js) (Theme client)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_web["Web interface"]
  node_browser["Browser UI<br/>[chat.html]"]
  node_auth_views["Sign-in and account views<br/>[login.html]"]
  node_account_view["Account view<br/>[account.html]"]
  node_theme_client["Theme client<br/>[main.js]"]
end

subgraph group_app["Flask application"]
  node_flask["Flask routes<br/>[app.py]"]
end

subgraph group_state["Persistence"]
  node_data_api["Persistence helpers<br/>[database.py]"]
  node_mongo[("MongoDB or mock store<br/>[database.py]")]
end

subgraph group_integrations["External services"]
  node_gemini{{"Gemini API"}}
  node_google_oauth{{"Google OAuth"}}
  node_github_oauth{{"GitHub OAuth"}}
end

node_person(("User"))

node_person -->|"uses"| node_browser
node_browser -->|"sends requests"| node_flask
node_flask -->|"renders"| node_auth_views
node_flask -->|"renders"| node_account_view
node_flask -->|"returns responses"| node_browser
node_theme_client -->|"syncs theme"| node_flask
node_flask -->|"calls persistence"| node_data_api
node_data_api -->|"reads and writes"| node_mongo
node_flask -->|"sends chat prompt"| node_gemini
node_flask -.->|"authorizes sign-in"| node_google_oauth
node_flask -.->|"authorizes sign-in"| node_github_oauth

click node_browser "https://github.com/bhv1122/generative-ai-/blob/main/templates/chat.html"
click node_auth_views "https://github.com/bhv1122/generative-ai-/blob/main/templates/login.html"
click node_account_view "https://github.com/bhv1122/generative-ai-/blob/main/templates/account.html"
click node_theme_client "https://github.com/bhv1122/generative-ai-/blob/main/static/js/main.js"
click node_flask "https://github.com/bhv1122/generative-ai-/blob/main/app.py"
click node_data_api "https://github.com/bhv1122/generative-ai-/blob/main/database.py"
click node_mongo "https://github.com/bhv1122/generative-ai-/blob/main/database.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_browser,node_auth_views,node_account_view,node_theme_client,node_person toneBlue
class node_flask toneAmber
class node_data_api,node_mongo toneMint
class node_gemini,node_google_oauth,node_github_oauth toneRose
```

## Components

### Web interface

- [Browser UI](https://github.com/bhv1122/generative-ai-/blob/main/templates/chat.html): `templates/chat.html`
- [Sign-in and account views](https://github.com/bhv1122/generative-ai-/blob/main/templates/login.html): `templates/login.html`
- [Account view](https://github.com/bhv1122/generative-ai-/blob/main/templates/account.html): `templates/account.html`
- [Theme client](https://github.com/bhv1122/generative-ai-/blob/main/static/js/main.js): `static/js/main.js`

### Flask application

- [Flask routes](https://github.com/bhv1122/generative-ai-/blob/main/app.py): `app.py`

### Persistence

- [Persistence helpers](https://github.com/bhv1122/generative-ai-/blob/main/database.py): `database.py`
- [MongoDB or mock store](https://github.com/bhv1122/generative-ai-/blob/main/database.py): `database.py`

### External services

- **Gemini API**
- **Google OAuth**
- **GitHub OAuth**

### Other components

- **User**

## Connections

- User → Browser UI: uses
- Browser UI → Flask routes: sends requests
- Flask routes → Sign-in and account views: renders
- Flask routes → Account view: renders
- Flask routes → Browser UI: returns responses
- Theme client → Flask routes: syncs theme
- Flask routes → Persistence helpers: calls persistence
- Persistence helpers → MongoDB or mock store: reads and writes
- Flask routes → Gemini API: sends chat prompt
- Flask routes → Google OAuth: authorizes sign-in
- Flask routes → GitHub OAuth: authorizes sign-in
