# tobytobyy/dacn2_aiserver architecture

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

- Interactive diagram: https://gitdiagram.com/tobytobyy/dacn2_aiserver
- Repository: https://github.com/tobytobyy/dacn2_aiserver

## Overview

DACN2 AI Server is a multimodal inference API. A client submits text and optionally an image URL; the chat route fetches the image, routes it through CLIP, analyzes it with the food classifier or health VQA pipeline, then sends the gathered context to the LLM and returns an intent, response, and suggested actions. A separate food-image endpoint exposes food classification. The graph also shows model setup, shared state, security, and readiness. Evidence is limited to the README and indexed excerpts; unsampled implementation details and links are omitted.

Main entry points: [`serve/app/api/v1/routes/inference.py`](https://github.com/tobytobyy/dacn2_aiserver/blob/main/serve/app/api/v1/routes/inference.py) (Inference routes), [`serve/app/main.py`](https://github.com/tobytobyy/dacn2_aiserver/blob/main/serve/app/main.py) (App lifecycle), [`serve/app/core/state.py`](https://github.com/tobytobyy/dacn2_aiserver/blob/main/serve/app/core/state.py) (Model state), [`serve/app/domain/food_pipeline.py`](https://github.com/tobytobyy/dacn2_aiserver/blob/main/serve/app/domain/food_pipeline.py) (Food pipeline)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["API and access"]
  node_inference["Inference routes<br/>[inference.py]"]
  node_chat_schema["Chat schemas<br/>[chat.py]"]
  node_food_schema["Food schemas<br/>[food_image.py]"]
  node_security["Token security<br/>[security.py]"]
  node_readiness["Model readiness<br/>[readiness.py]"]
  node_image_fetch["Image fetch<br/>[fetch_image.py]"]
end

subgraph group_vision["Vision analysis"]
  node_vision_router["Vision routing"]
  node_clip_model["CLIP router model<br/>[clip_router.py]"]
  node_routing_hint["Routing hints<br/>[routing_hint.py]"]
  node_food_pipeline["Food pipeline<br/>[food_pipeline.py]"]
  node_food_predictor["Food classifier<br/>[predict_food.py]"]
  node_health_pipeline["Health pipeline<br/>[health_pipeline.py]"]
  node_vqa_questions["VQA questions<br/>[vqa_questions.py]"]
  node_blip_vqa["BLIP VQA<br/>[blip_vqa.py]"]
end

subgraph group_language["Language response"]
  node_llm_engine["LLM orchestration<br/>[llm_engine.py]"]
  node_llm_intents["Allowed intents<br/>[llm_intents.py]"]
  node_ollama_client["Ollama client<br/>[llm_ollama.py]"]
  node_actions["Suggested actions<br/>[actions.py]"]
end

subgraph group_runtime["Runtime foundation"]
  node_main["App lifecycle<br/>[main.py]"]
  node_config["Configuration<br/>[config.py]"]
  node_model_state[("Model state<br/>[state.py]")]
end

node_client(("API client"))
node_image_host(("Image URL host"))
node_ollama(("Ollama service"))

node_client -->|"submits request"| node_inference
node_inference -->|"checks token"| node_security
node_inference -->|"checks readiness"| node_readiness
node_inference -->|"validates chat"| node_chat_schema
node_inference -->|"validates food request"| node_food_schema
node_inference -->|"fetches image"| node_image_fetch
node_image_fetch -.->|"downloads image"| node_image_host
node_inference -->|"routes image"| node_vision_router
node_vision_router -->|"uses model state"| node_model_state
node_main -->|"loads CLIP"| node_clip_model
node_main -->|"stores models"| node_model_state
node_vision_router -->|"reads thresholds"| node_config
node_inference -->|"maps route"| node_routing_hint
node_inference -->|"analyzes food"| node_food_pipeline
node_food_pipeline -->|"predicts labels"| node_food_predictor
node_main -->|"initializes pipeline"| node_food_pipeline
node_food_pipeline -->|"uses model state"| node_model_state
node_inference -->|"analyzes health image"| node_health_pipeline
node_health_pipeline -->|"selects questions"| node_vqa_questions
node_health_pipeline -->|"asks questions"| node_blip_vqa
node_blip_vqa -->|"uses model state"| node_model_state
node_main -->|"initializes pipeline"| node_health_pipeline
node_inference -->|"generates response"| node_llm_engine
node_llm_engine -->|"validates intent"| node_llm_intents
node_llm_engine -->|"requests generation"| node_ollama_client
node_ollama_client -->|"sends chat"| node_ollama
node_main -->|"initializes engine"| node_llm_engine
node_inference -->|"builds actions"| node_actions
node_main -->|"reads settings"| node_config
node_security -->|"reads token config"| node_config
node_readiness -->|"checks model state"| node_model_state

click node_inference "https://github.com/tobytobyy/dacn2_aiserver/blob/main/serve/app/api/v1/routes/inference.py"
click node_chat_schema "https://github.com/tobytobyy/dacn2_aiserver/blob/main/serve/app/schemas/chat.py"
click node_food_schema "https://github.com/tobytobyy/dacn2_aiserver/blob/main/serve/app/schemas/food_image.py"
click node_security "https://github.com/tobytobyy/dacn2_aiserver/blob/main/serve/app/core/security.py"
click node_readiness "https://github.com/tobytobyy/dacn2_aiserver/blob/main/serve/app/core/readiness.py"
click node_image_fetch "https://github.com/tobytobyy/dacn2_aiserver/blob/main/serve/app/core/fetch_image.py"
click node_vision_router "https://github.com/tobytobyy/dacn2_aiserver/blob/main/serve/app/domain/vision_router_service.py"
click node_clip_model "https://github.com/tobytobyy/dacn2_aiserver/blob/main/serve/app/infra/clip_router.py"
click node_routing_hint "https://github.com/tobytobyy/dacn2_aiserver/blob/main/serve/app/domain/routing_hint.py"
click node_food_pipeline "https://github.com/tobytobyy/dacn2_aiserver/blob/main/serve/app/domain/food_pipeline.py"
click node_food_predictor "https://github.com/tobytobyy/dacn2_aiserver/blob/main/serve/app/infra/predict_food.py"
click node_health_pipeline "https://github.com/tobytobyy/dacn2_aiserver/blob/main/serve/app/domain/health_pipeline.py"
click node_vqa_questions "https://github.com/tobytobyy/dacn2_aiserver/blob/main/serve/app/domain/vqa_questions.py"
click node_blip_vqa "https://github.com/tobytobyy/dacn2_aiserver/blob/main/serve/app/infra/blip_vqa.py"
click node_llm_engine "https://github.com/tobytobyy/dacn2_aiserver/blob/main/serve/app/domain/llm_engine.py"
click node_llm_intents "https://github.com/tobytobyy/dacn2_aiserver/blob/main/serve/app/domain/llm_intents.py"
click node_ollama_client "https://github.com/tobytobyy/dacn2_aiserver/blob/main/serve/app/infra/llm_ollama.py"
click node_actions "https://github.com/tobytobyy/dacn2_aiserver/blob/main/serve/app/domain/actions.py"
click node_main "https://github.com/tobytobyy/dacn2_aiserver/blob/main/serve/app/main.py"
click node_config "https://github.com/tobytobyy/dacn2_aiserver/blob/main/serve/app/core/config.py"
click node_model_state "https://github.com/tobytobyy/dacn2_aiserver/blob/main/serve/app/core/state.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_inference,node_chat_schema,node_food_schema,node_security,node_readiness,node_image_fetch,node_client toneBlue
class node_vision_router,node_clip_model,node_routing_hint,node_food_pipeline,node_food_predictor,node_health_pipeline,node_vqa_questions,node_blip_vqa toneAmber
class node_llm_engine,node_llm_intents,node_ollama_client,node_actions toneMint
class node_main,node_config,node_model_state toneRose
class node_image_host,node_ollama toneIndigo
```

## Components

### API and access

- [Inference routes](https://github.com/tobytobyy/dacn2_aiserver/blob/main/serve/app/api/v1/routes/inference.py): `serve/app/api/v1/routes/inference.py`
- [Chat schemas](https://github.com/tobytobyy/dacn2_aiserver/blob/main/serve/app/schemas/chat.py): `serve/app/schemas/chat.py`
- [Food schemas](https://github.com/tobytobyy/dacn2_aiserver/blob/main/serve/app/schemas/food_image.py): `serve/app/schemas/food_image.py`
- [Token security](https://github.com/tobytobyy/dacn2_aiserver/blob/main/serve/app/core/security.py): `serve/app/core/security.py`
- [Model readiness](https://github.com/tobytobyy/dacn2_aiserver/blob/main/serve/app/core/readiness.py): `serve/app/core/readiness.py`
- [Image fetch](https://github.com/tobytobyy/dacn2_aiserver/blob/main/serve/app/core/fetch_image.py): `serve/app/core/fetch_image.py`

### Vision analysis

- [Vision routing](https://github.com/tobytobyy/dacn2_aiserver/blob/main/serve/app/domain/vision_router_service.py): `serve/app/domain/vision_router_service.py`
- [CLIP router model](https://github.com/tobytobyy/dacn2_aiserver/blob/main/serve/app/infra/clip_router.py): `serve/app/infra/clip_router.py`
- [Routing hints](https://github.com/tobytobyy/dacn2_aiserver/blob/main/serve/app/domain/routing_hint.py): `serve/app/domain/routing_hint.py`
- [Food pipeline](https://github.com/tobytobyy/dacn2_aiserver/blob/main/serve/app/domain/food_pipeline.py): `serve/app/domain/food_pipeline.py`
- [Food classifier](https://github.com/tobytobyy/dacn2_aiserver/blob/main/serve/app/infra/predict_food.py): `serve/app/infra/predict_food.py`
- [Health pipeline](https://github.com/tobytobyy/dacn2_aiserver/blob/main/serve/app/domain/health_pipeline.py): `serve/app/domain/health_pipeline.py`
- [VQA questions](https://github.com/tobytobyy/dacn2_aiserver/blob/main/serve/app/domain/vqa_questions.py): `serve/app/domain/vqa_questions.py`
- [BLIP VQA](https://github.com/tobytobyy/dacn2_aiserver/blob/main/serve/app/infra/blip_vqa.py): `serve/app/infra/blip_vqa.py`

### Language response

- [LLM orchestration](https://github.com/tobytobyy/dacn2_aiserver/blob/main/serve/app/domain/llm_engine.py): `serve/app/domain/llm_engine.py`
- [Allowed intents](https://github.com/tobytobyy/dacn2_aiserver/blob/main/serve/app/domain/llm_intents.py): `serve/app/domain/llm_intents.py`
- [Ollama client](https://github.com/tobytobyy/dacn2_aiserver/blob/main/serve/app/infra/llm_ollama.py): `serve/app/infra/llm_ollama.py`
- [Suggested actions](https://github.com/tobytobyy/dacn2_aiserver/blob/main/serve/app/domain/actions.py): `serve/app/domain/actions.py`

### Runtime foundation

- [App lifecycle](https://github.com/tobytobyy/dacn2_aiserver/blob/main/serve/app/main.py): `serve/app/main.py`
- [Configuration](https://github.com/tobytobyy/dacn2_aiserver/blob/main/serve/app/core/config.py): `serve/app/core/config.py`
- [Model state](https://github.com/tobytobyy/dacn2_aiserver/blob/main/serve/app/core/state.py): `serve/app/core/state.py`

### Other components

- **API client**
- **Image URL host**
- **Ollama service**

## Connections

- API client → Inference routes: submits request (evidence: `README.md`)
- Inference routes → Token security: checks token (evidence: `serve/app/api/v1/routes/inference.py`)
- Inference routes → Model readiness: checks readiness (evidence: `serve/app/api/v1/routes/inference.py`)
- Inference routes → Chat schemas: validates chat (evidence: `serve/app/api/v1/routes/inference.py`)
- Inference routes → Food schemas: validates food request (evidence: `serve/app/api/v1/routes/inference.py`)
- Inference routes → Image fetch: fetches image (evidence: `serve/app/api/v1/routes/inference.py`)
- Image fetch → Image URL host: downloads image
- Inference routes → Vision routing: routes image (evidence: `serve/app/api/v1/routes/inference.py`)
- Vision routing → Model state: uses model state (evidence: `serve/app/domain/vision_router_service.py`)
- App lifecycle → CLIP router model: loads CLIP (evidence: `serve/app/main.py`)
- App lifecycle → Model state: stores models (evidence: `serve/app/main.py`)
- Vision routing → Configuration: reads thresholds (evidence: `serve/app/domain/vision_router_service.py`)
- Inference routes → Routing hints: maps route (evidence: `serve/app/api/v1/routes/inference.py`)
- Inference routes → Food pipeline: analyzes food (evidence: `serve/app/api/v1/routes/inference.py`)
- Food pipeline → Food classifier: predicts labels (evidence: `serve/app/domain/food_pipeline.py`)
- App lifecycle → Food pipeline: initializes pipeline (evidence: `serve/app/main.py`)
- Food pipeline → Model state: uses model state (evidence: `serve/app/domain/food_pipeline.py`)
- Inference routes → Health pipeline: analyzes health image (evidence: `serve/app/api/v1/routes/inference.py`)
- Health pipeline → VQA questions: selects questions (evidence: `serve/app/domain/health_pipeline.py`)
- Health pipeline → BLIP VQA: asks questions (evidence: `serve/app/domain/health_pipeline.py`)
- BLIP VQA → Model state: uses model state (evidence: `serve/app/infra/blip_vqa.py`)
- App lifecycle → Health pipeline: initializes pipeline (evidence: `serve/app/main.py`)
- Inference routes → LLM orchestration: generates response (evidence: `serve/app/api/v1/routes/inference.py`)
- LLM orchestration → Allowed intents: validates intent (evidence: `serve/app/domain/llm_engine.py`)
- LLM orchestration → Ollama client: requests generation (evidence: `serve/app/domain/llm_engine.py`)
- Ollama client → Ollama service: sends chat (evidence: `serve/app/infra/llm_ollama.py`)
- App lifecycle → LLM orchestration: initializes engine (evidence: `serve/app/main.py`)
- Inference routes → Suggested actions: builds actions (evidence: `serve/app/api/v1/routes/inference.py`)
- App lifecycle → Configuration: reads settings (evidence: `serve/app/main.py`)
- Token security → Configuration: reads token config (evidence: `serve/app/core/security.py`)
- Model readiness → Model state: checks model state (evidence: `serve/app/core/readiness.py`)
