# oliviern-dev/ffmkai architecture

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

- Interactive diagram: https://gitdiagram.com/oliviern-dev/ffmkai
- Repository: https://github.com/oliviern-dev/ffmkai

## Overview

Clarity is a Flask-based AI chat application. Users register or sign in, configure a provider and private API key, then create chats whose messages can be streamed, edited, searched, and managed; SQLite persists account, settings, conversation, and message data. The graph follows documented capabilities while limiting connections to relationships visible in excerpts or the README. Front-end assets and profile/settings features are included; unsampled route internals are represented only at their documented subsystem paths.

Main entry points: [`app/routes/api_routes.py`](https://github.com/oliviern-dev/ffmkai/blob/main/app/routes/api_routes.py) (Chat API and SSE), [`app/__init__.py`](https://github.com/oliviern-dev/ffmkai/blob/main/app/__init__.py) (Flask app setup), [`app/db.py`](https://github.com/oliviern-dev/ffmkai/blob/main/app/db.py) (SQLite data access), [`app/routes/auth_routes.py`](https://github.com/oliviern-dev/ffmkai/blob/main/app/routes/auth_routes.py) (Registration and login)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_web["Web interface"]
  node_app["Flask app setup<br/>[__init__.py]"]
  node_chat_pages["Chat pages<br/>[chat_routes.py]"]
  node_settings_ui["Settings interface<br/>[settings.js]"]
  node_app_ui["Shared UI behavior<br/>[app.js]"]
  node_config["Runtime configuration<br/>[config.py]"]
end

subgraph group_identity["Accounts and profile"]
  node_auth["Registration and login<br/>[auth_routes.py]"]
  node_security["Sessions and passwords<br/>[security.py]"]
  node_profile["Profile management<br/>[api_routes.py]"]
  node_profile_ui["Profile interface<br/>[profile.js]"]
end

subgraph group_chat["Chat and history"]
  node_chat_api["Chat API and SSE<br/>[api_routes.py]"]
  node_chat_ui["Chat interaction<br/>[chat.js]"]
  node_sidebar["History and search<br/>[sidebar.js]"]
end

subgraph group_ai["AI providers"]
  node_ai_service["Provider integration<br/>[ai.py]"]
  node_key_store["Private API keys<br/>[keystore.py]"]
end

subgraph group_data["Persistence"]
  node_db_layer["SQLite data access<br/>[db.py]"]
  node_sqlite[("Application database")]
end

node_user(("User"))
node_external_ai{{"AI provider APIs"}}

node_user -->|"uses"| node_app
node_app -->|"loads"| node_config
node_app -->|"initializes"| node_db_layer
node_app -->|"loads user"| node_security
node_app -->|"registers routes"| node_auth
node_app -->|"registers routes"| node_chat_pages
node_app -->|"registers routes"| node_chat_api
node_auth -->|"authenticates"| node_security
node_auth -->|"reads and writes"| node_db_layer
node_chat_pages -->|"reads chats"| node_db_layer
node_chat_pages -->|"loads settings"| node_security
node_chat_api -->|"reads and writes"| node_db_layer
node_chat_api -->|"requires login"| node_security
node_chat_api -->|"requests replies"| node_ai_service
node_ai_service -->|"gets key"| node_key_store
node_ai_service -->|"calls provider"| node_external_ai
node_key_store -.->|"uses environment keys"| node_external_ai
node_db_layer -->|"reads and writes"| node_sqlite
node_chat_ui -->|"uses API"| node_chat_api
node_sidebar -->|"uses API"| node_chat_api
node_settings_ui -->|"uses API"| node_chat_api
node_profile_ui -->|"uses API"| node_chat_api
node_user -->|"registers or signs in"| node_auth
node_user -->|"chats"| node_chat_ui
node_user -->|"configures"| node_settings_ui
node_user -->|"manages profile"| node_profile_ui
node_user -->|"uploads avatar"| node_profile
node_chat_api -.->|"serves profile endpoints"| node_profile
node_app_ui -.->|"presents interface"| node_user

click node_app "https://github.com/oliviern-dev/ffmkai/blob/main/app/__init__.py"
click node_chat_pages "https://github.com/oliviern-dev/ffmkai/blob/main/app/routes/chat_routes.py"
click node_auth "https://github.com/oliviern-dev/ffmkai/blob/main/app/routes/auth_routes.py"
click node_security "https://github.com/oliviern-dev/ffmkai/blob/main/app/security.py"
click node_profile "https://github.com/oliviern-dev/ffmkai/blob/main/app/routes/api_routes.py"
click node_chat_api "https://github.com/oliviern-dev/ffmkai/blob/main/app/routes/api_routes.py"
click node_chat_ui "https://github.com/oliviern-dev/ffmkai/blob/main/static/js/chat.js"
click node_sidebar "https://github.com/oliviern-dev/ffmkai/blob/main/static/js/sidebar.js"
click node_settings_ui "https://github.com/oliviern-dev/ffmkai/blob/main/static/js/settings.js"
click node_app_ui "https://github.com/oliviern-dev/ffmkai/blob/main/static/js/app.js"
click node_profile_ui "https://github.com/oliviern-dev/ffmkai/blob/main/static/js/profile.js"
click node_ai_service "https://github.com/oliviern-dev/ffmkai/blob/main/app/services/ai.py"
click node_key_store "https://github.com/oliviern-dev/ffmkai/blob/main/app/keystore.py"
click node_db_layer "https://github.com/oliviern-dev/ffmkai/blob/main/app/db.py"
click node_config "https://github.com/oliviern-dev/ffmkai/blob/main/config.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_app,node_chat_pages,node_settings_ui,node_app_ui,node_config,node_user toneBlue
class node_auth,node_security,node_profile,node_profile_ui toneAmber
class node_chat_api,node_chat_ui,node_sidebar,node_external_ai toneMint
class node_ai_service,node_key_store toneRose
class node_db_layer,node_sqlite toneIndigo
```

## Components

### Web interface

- [Flask app setup](https://github.com/oliviern-dev/ffmkai/blob/main/app/__init__.py): `app/__init__.py`
- [Chat pages](https://github.com/oliviern-dev/ffmkai/blob/main/app/routes/chat_routes.py): `app/routes/chat_routes.py`
- [Settings interface](https://github.com/oliviern-dev/ffmkai/blob/main/static/js/settings.js): `static/js/settings.js`
- [Shared UI behavior](https://github.com/oliviern-dev/ffmkai/blob/main/static/js/app.js): `static/js/app.js`
- [Runtime configuration](https://github.com/oliviern-dev/ffmkai/blob/main/config.py): `config.py`

### Accounts and profile

- [Registration and login](https://github.com/oliviern-dev/ffmkai/blob/main/app/routes/auth_routes.py): `app/routes/auth_routes.py`
- [Sessions and passwords](https://github.com/oliviern-dev/ffmkai/blob/main/app/security.py): `app/security.py`
- [Profile management](https://github.com/oliviern-dev/ffmkai/blob/main/app/routes/api_routes.py): `app/routes/api_routes.py`
- [Profile interface](https://github.com/oliviern-dev/ffmkai/blob/main/static/js/profile.js): `static/js/profile.js`

### Chat and history

- [Chat API and SSE](https://github.com/oliviern-dev/ffmkai/blob/main/app/routes/api_routes.py): `app/routes/api_routes.py`
- [Chat interaction](https://github.com/oliviern-dev/ffmkai/blob/main/static/js/chat.js): `static/js/chat.js`
- [History and search](https://github.com/oliviern-dev/ffmkai/blob/main/static/js/sidebar.js): `static/js/sidebar.js`

### AI providers

- [Provider integration](https://github.com/oliviern-dev/ffmkai/blob/main/app/services/ai.py): `app/services/ai.py`
- [Private API keys](https://github.com/oliviern-dev/ffmkai/blob/main/app/keystore.py): `app/keystore.py`

### Persistence

- [SQLite data access](https://github.com/oliviern-dev/ffmkai/blob/main/app/db.py): `app/db.py`
- **Application database**

### Other components

- **User**
- **AI provider APIs**

## Connections

- User → Flask app setup: uses (evidence: `README.md`)
- Flask app setup → Runtime configuration: loads (evidence: `app/__init__.py`)
- Flask app setup → SQLite data access: initializes (evidence: `app/__init__.py`)
- Flask app setup → Sessions and passwords: loads user (evidence: `app/__init__.py`)
- Flask app setup → Registration and login: registers routes
- Flask app setup → Chat pages: registers routes
- Flask app setup → Chat API and SSE: registers routes
- Registration and login → Sessions and passwords: authenticates (evidence: `app/routes/auth_routes.py`)
- Registration and login → SQLite data access: reads and writes (evidence: `app/routes/auth_routes.py`)
- Chat pages → SQLite data access: reads chats (evidence: `app/routes/chat_routes.py`)
- Chat pages → Sessions and passwords: loads settings (evidence: `app/routes/chat_routes.py`)
- Chat API and SSE → SQLite data access: reads and writes (evidence: `app/routes/api_routes.py`)
- Chat API and SSE → Sessions and passwords: requires login (evidence: `app/routes/api_routes.py`)
- Chat API and SSE → Provider integration: requests replies (evidence: `app/routes/api_routes.py`)
- Provider integration → Private API keys: gets key (evidence: `app/services/ai.py`)
- Provider integration → AI provider APIs: calls provider (evidence: `app/services/ai.py`)
- Private API keys → AI provider APIs: uses environment keys (evidence: `README.md`)
- SQLite data access → Application database: reads and writes (evidence: `app/db.py`)
- Chat interaction → Chat API and SSE: uses API (evidence: `README.md`)
- History and search → Chat API and SSE: uses API (evidence: `README.md`)
- Settings interface → Chat API and SSE: uses API (evidence: `README.md`)
- Profile interface → Chat API and SSE: uses API (evidence: `README.md`)
- User → Registration and login: registers or signs in (evidence: `README.md`)
- User → Chat interaction: chats (evidence: `README.md`)
- User → Settings interface: configures (evidence: `README.md`)
- User → Profile interface: manages profile (evidence: `README.md`)
- User → Profile management: uploads avatar (evidence: `README.md`)
- Chat API and SSE → Profile management: serves profile endpoints (evidence: `app/routes/api_routes.py`)
- Shared UI behavior → User: presents interface
