# aarya695/edge-ai-offline-assistant architecture

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

- Interactive diagram: https://gitdiagram.com/aarya695/edge-ai-offline-assistant
- Repository: https://github.com/aarya695/edge-ai-offline-assistant

## Overview

#### Purpose and entry point
This repository provides a privacy-focused offline AI assistant backend. The sole application entry point is `backend.py`, served with Uvicorn as `backend:app`. It is intended to use a locally running, quantized GGUF language model rather than a hosted model API.

#### API backend
`backend.py` defines the application server and is the central integration boundary for clients. It likely owns request intake, prompt construction/control, safety enforcement, forwarding inference requests, and returning generated responses. No frontend, CLI application, or separate service modules are present in the repository.

#### Local model inference boundary
The assistant does not package or execute model inference directly. Instead, it depends on an externally built and launched `llama.cpp` `llama-server` process. `backend.py` is expected to communicate with that local inference server, separating application policy/API concerns from model execution.

Relevant repository path:
- `backend.py`

#### Model and runtime deployment
A user manually downloads a GGUF model, such as a small Qwen model, and stores it outside the repository (example: `C:\models\`). `llama.cpp` is cloned and compiled separately with CMake, then started with the selected model file. This keeps model weights, native inference binaries, and potentially hardware-specific build settings out of version control.

#### Safety and prompt-control stage
The stated product design includes safety and prompt-control layers around the local model. These controls belong at the backend-to-inference boundary: validate or constrain incoming user prompts before inference, and potentially inspect or constrain generated output before returning it. Their implementation, if present, is consolidated in:
- `backend.py`

#### Primary control flow
1. A client sends a request to the Uvicorn-hosted application.
2. `backend.py` accepts and processes the request.
3. The backend applies assistant prompt and safety policy.
4. The backend sends the resulting inference request to the local `llama-server`.
5. The local `llama.cpp` runtime loads the GGUF model and generates output.
6. `backend.py` returns the controlled response to the caller.

#### Infrastructure and external dependencies
Runtime infrastructure consists of Python/Uvicorn for the API service and a separately compiled native `llama.cpp` server for inference. External acquisition is limited to the `llama.cpp` source repository and a manually downloaded Hugging Face GGUF model; normal operation is intended to remain local/offline after setup.

Relevant paths:
- `README.md`
- `backend.py`

Main entry points: [`backend.py`](https://github.com/aarya695/edge-ai-offline-assistant/blob/main/backend.py) (Prompt & Safety Control), [`README.md`](https://github.com/aarya695/edge-ai-offline-assistant/blob/main/README.md) (Setup Documentation)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_backend["Python API Backend"]
  node_uvicorn["Uvicorn<br/>ASGI server<br/>[backend.py]"]
  node_backend_app["Assistant API<br/>FastAPI application<br/>[backend.py]"]
  node_prompt_safety["Prompt &amp; Safety Control<br/>backend policy stage<br/>[backend.py]"]
  node_inference_client["Inference Client<br/>local server integration<br/>[backend.py]"]
end

subgraph group_external["External Local Runtime"]
  node_llama_server{{"llama-server<br/>llama.cpp inference server"}}
  node_gguf_model[("GGUF Model<br/>local model weights")]
end

node_client(("Local Client"))
node_readme["Setup Documentation<br/>README<br/>[README.md]"]

node_client -->|"HTTP request"| node_uvicorn
node_uvicorn -->|"ASGI"| node_backend_app
node_backend_app -->|"process request"| node_prompt_safety
node_prompt_safety -->|"controlled prompt"| node_inference_client
node_inference_client -->|"local inference request"| node_llama_server
node_llama_server -->|"loads"| node_gguf_model
node_llama_server -->|"generated output"| node_prompt_safety
node_prompt_safety -->|"controlled response"| node_backend_app
node_readme -.->|"setup guidance"| node_llama_server
node_readme -.->|"model setup guidance"| node_gguf_model

click node_uvicorn "https://github.com/aarya695/edge-ai-offline-assistant/blob/main/backend.py"
click node_backend_app "https://github.com/aarya695/edge-ai-offline-assistant/blob/main/backend.py"
click node_prompt_safety "https://github.com/aarya695/edge-ai-offline-assistant/blob/main/backend.py"
click node_inference_client "https://github.com/aarya695/edge-ai-offline-assistant/blob/main/backend.py"
click node_readme "https://github.com/aarya695/edge-ai-offline-assistant/blob/main/README.md"

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_uvicorn,node_backend_app,node_prompt_safety,node_inference_client toneBlue
class node_llama_server,node_gguf_model toneAmber
class node_client,node_readme toneNeutral
```

## Components

### Python API Backend

Uvicorn-hosted local assistant service.

- [Uvicorn](https://github.com/aarya695/edge-ai-offline-assistant/blob/main/backend.py): ASGI server · Serves backend:app. · `backend.py`
- [Assistant API](https://github.com/aarya695/edge-ai-offline-assistant/blob/main/backend.py): FastAPI application · Central request, policy, inference, and response boundary. · `backend.py`
- [Prompt & Safety Control](https://github.com/aarya695/edge-ai-offline-assistant/blob/main/backend.py): backend policy stage · Constrains input prompts and generated output. · `backend.py`
- [Inference Client](https://github.com/aarya695/edge-ai-offline-assistant/blob/main/backend.py): local server integration · Forwards controlled inference requests. · `backend.py`

### External Local Runtime

Built and operated outside this repository.

- **llama-server**: llama.cpp inference server · Separately compiled native local inference process.
- **GGUF Model**: local model weights · Manually downloaded and stored outside the repository.

### Other components

- **Local Client**: client
- [Setup Documentation](https://github.com/aarya695/edge-ai-offline-assistant/blob/main/README.md): README · Documents local model and llama.cpp setup. · `README.md`

## Connections

- Local Client → Uvicorn: HTTP request
- Uvicorn → Assistant API: ASGI
- Assistant API → Prompt & Safety Control: process request
- Prompt & Safety Control → Inference Client: controlled prompt
- Inference Client → llama-server: local inference request
- llama-server → GGUF Model: loads
- llama-server → Prompt & Safety Control: generated output
- Prompt & Safety Control → Assistant API: controlled response
- Setup Documentation → llama-server: setup guidance
- Setup Documentation → GGUF Model: model setup guidance
