# deahesi/deahesi-os-backend architecture

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

- Interactive diagram: https://gitdiagram.com/deahesi/deahesi-os-backend
- Repository: https://github.com/deahesi/deahesi-os-backend

## Overview

This Go service exposes a text-and-file chat endpoint that validates and parses requests, prepares optional file data, calls an OpenRouter model, and streams response events to the client. Startup and dependency wiring are shown in the sampled application files. The README is empty; the graph therefore reflects the demonstrated endpoint and does not infer additional routes or tool behavior from unsampled code.

Main entry points: [`internal/ai/service.go`](https://github.com/deahesi/deahesi-os-backend/blob/main/internal/ai/service.go) (AI service), [`internal/httpapi/handlers/ai-handlers/ai.go`](https://github.com/deahesi/deahesi-os-backend/blob/main/internal/httpapi/handlers/ai-handlers/ai.go) (Chat handler), [`internal/app/application.go`](https://github.com/deahesi/deahesi-os-backend/blob/main/internal/app/application.go) (Application), [`internal/app/services.go`](https://github.com/deahesi/deahesi-os-backend/blob/main/internal/app/services.go) (Service wiring)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Startup and wiring"]
  node_entry["Process entry<br/>[server.go]"]
  node_application["Application<br/>[application.go]"]
  node_config["Configuration<br/>[config.go]"]
  node_service_wiring["Service wiring<br/>[services.go]"]
  node_app_server["HTTP lifecycle<br/>[server.go]"]
end

subgraph group_api["HTTP API"]
  node_api_server["Route server<br/>[server.go]"]
  node_handler["Chat handler<br/>[ai.go]"]
  node_request_dto["Request DTO<br/>[dto.go]"]
  node_file_parser["File parser<br/>[file.go]"]
  node_responses["Stream responses<br/>[responses.go]"]
end

subgraph group_chat["Chat and model"]
  node_ai_service["AI service<br/>[service.go]"]
  node_ai_input["AI input<br/>[input.go]"]
  node_domain_ai["AI errors<br/>[ai.go]"]
  node_chat_message["Chat message<br/>[llm.go]"]
  node_llm_service["LLM service<br/>[service.go]"]
  node_llm_tools["LLM tools<br/>[tools.go]"]
end

node_client(("Chat client"))
node_openrouter["OpenRouter"]

node_client -->|"sends request"| node_entry
node_entry -->|"starts"| node_application
node_application -->|"loads"| node_config
node_application -->|"builds services"| node_service_wiring
node_service_wiring -->|"reads settings"| node_config
node_application -->|"creates"| node_app_server
node_service_wiring -->|"constructs"| node_ai_service
node_service_wiring -->|"constructs"| node_llm_service
node_app_server -->|"serves"| node_api_server
node_api_server -->|"routes to"| node_handler
node_handler -->|"parses upload"| node_file_parser
node_handler -->|"submits message"| node_ai_service
node_handler -->|"writes stream"| node_responses
node_handler -->|"checks errors"| node_domain_ai
node_ai_service -->|"accepts input"| node_ai_input
node_ai_service -->|"builds message"| node_chat_message
node_ai_service -->|"forwards message"| node_llm_service
node_ai_service -->|"returns errors"| node_domain_ai
node_llm_service -->|"sends completion"| node_openrouter
node_llm_service -.->|"uses tools"| node_llm_tools

click node_entry "https://github.com/deahesi/deahesi-os-backend/blob/main/cmd/server/server.go"
click node_application "https://github.com/deahesi/deahesi-os-backend/blob/main/internal/app/application.go"
click node_config "https://github.com/deahesi/deahesi-os-backend/blob/main/internal/config/config.go"
click node_service_wiring "https://github.com/deahesi/deahesi-os-backend/blob/main/internal/app/services.go"
click node_app_server "https://github.com/deahesi/deahesi-os-backend/blob/main/internal/app/server.go"
click node_api_server "https://github.com/deahesi/deahesi-os-backend/blob/main/internal/httpapi/server.go"
click node_handler "https://github.com/deahesi/deahesi-os-backend/blob/main/internal/httpapi/handlers/ai-handlers/ai.go"
click node_request_dto "https://github.com/deahesi/deahesi-os-backend/blob/main/internal/httpapi/handlers/ai-handlers/dto.go"
click node_file_parser "https://github.com/deahesi/deahesi-os-backend/blob/main/internal/httpapi/parsers/file.go"
click node_responses "https://github.com/deahesi/deahesi-os-backend/blob/main/internal/httpapi/responses/responses.go"
click node_ai_service "https://github.com/deahesi/deahesi-os-backend/blob/main/internal/ai/service.go"
click node_ai_input "https://github.com/deahesi/deahesi-os-backend/blob/main/internal/ai/input.go"
click node_domain_ai "https://github.com/deahesi/deahesi-os-backend/blob/main/internal/domain/ai.go"
click node_chat_message "https://github.com/deahesi/deahesi-os-backend/blob/main/internal/domain/llm.go"
click node_llm_service "https://github.com/deahesi/deahesi-os-backend/blob/main/internal/llm/service.go"
click node_llm_tools "https://github.com/deahesi/deahesi-os-backend/blob/main/internal/llm/tools.go"

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_entry,node_application,node_config,node_service_wiring,node_app_server,node_client toneBlue
class node_api_server,node_handler,node_request_dto,node_file_parser,node_responses toneAmber
class node_ai_service,node_ai_input,node_domain_ai,node_chat_message,node_llm_service,node_llm_tools,node_openrouter toneMint
```

## Components

### Startup and wiring

- [Process entry](https://github.com/deahesi/deahesi-os-backend/blob/main/cmd/server/server.go): `cmd/server/server.go`
- [Application](https://github.com/deahesi/deahesi-os-backend/blob/main/internal/app/application.go): `internal/app/application.go`
- [Configuration](https://github.com/deahesi/deahesi-os-backend/blob/main/internal/config/config.go): `internal/config/config.go`
- [Service wiring](https://github.com/deahesi/deahesi-os-backend/blob/main/internal/app/services.go): `internal/app/services.go`
- [HTTP lifecycle](https://github.com/deahesi/deahesi-os-backend/blob/main/internal/app/server.go): `internal/app/server.go`

### HTTP API

- [Route server](https://github.com/deahesi/deahesi-os-backend/blob/main/internal/httpapi/server.go): `internal/httpapi/server.go`
- [Chat handler](https://github.com/deahesi/deahesi-os-backend/blob/main/internal/httpapi/handlers/ai-handlers/ai.go): `internal/httpapi/handlers/ai-handlers/ai.go`
- [Request DTO](https://github.com/deahesi/deahesi-os-backend/blob/main/internal/httpapi/handlers/ai-handlers/dto.go): `internal/httpapi/handlers/ai-handlers/dto.go`
- [File parser](https://github.com/deahesi/deahesi-os-backend/blob/main/internal/httpapi/parsers/file.go): `internal/httpapi/parsers/file.go`
- [Stream responses](https://github.com/deahesi/deahesi-os-backend/blob/main/internal/httpapi/responses/responses.go): `internal/httpapi/responses/responses.go`

### Chat and model

- [AI service](https://github.com/deahesi/deahesi-os-backend/blob/main/internal/ai/service.go): `internal/ai/service.go`
- [AI input](https://github.com/deahesi/deahesi-os-backend/blob/main/internal/ai/input.go): `internal/ai/input.go`
- [AI errors](https://github.com/deahesi/deahesi-os-backend/blob/main/internal/domain/ai.go): `internal/domain/ai.go`
- [Chat message](https://github.com/deahesi/deahesi-os-backend/blob/main/internal/domain/llm.go): `internal/domain/llm.go`
- [LLM service](https://github.com/deahesi/deahesi-os-backend/blob/main/internal/llm/service.go): `internal/llm/service.go`
- [LLM tools](https://github.com/deahesi/deahesi-os-backend/blob/main/internal/llm/tools.go): `internal/llm/tools.go`

### Other components

- **Chat client**
- **OpenRouter**

## Connections

- Chat client → Process entry: sends request
- Process entry → Application: starts (evidence: `cmd/server/server.go`)
- Application → Configuration: loads (evidence: `internal/app/application.go`)
- Application → Service wiring: builds services (evidence: `internal/app/application.go`)
- Service wiring → Configuration: reads settings (evidence: `internal/app/services.go`)
- Application → HTTP lifecycle: creates (evidence: `internal/app/application.go`)
- Service wiring → AI service: constructs (evidence: `internal/app/services.go`)
- Service wiring → LLM service: constructs (evidence: `internal/app/services.go`)
- HTTP lifecycle → Route server: serves (evidence: `internal/app/server.go`)
- Route server → Chat handler: routes to (evidence: `internal/httpapi/server.go`)
- Chat handler → File parser: parses upload (evidence: `internal/httpapi/handlers/ai-handlers/ai.go`)
- Chat handler → AI service: submits message (evidence: `internal/httpapi/handlers/ai-handlers/ai.go`)
- Chat handler → Stream responses: writes stream (evidence: `internal/httpapi/handlers/ai-handlers/ai.go`)
- Chat handler → AI errors: checks errors (evidence: `internal/httpapi/handlers/ai-handlers/ai.go`)
- AI service → AI input: accepts input (evidence: `internal/ai/service.go`)
- AI service → Chat message: builds message (evidence: `internal/ai/service.go`)
- AI service → LLM service: forwards message (evidence: `internal/ai/service.go`)
- AI service → AI errors: returns errors (evidence: `internal/ai/service.go`)
- LLM service → OpenRouter: sends completion (evidence: `internal/llm/service.go`)
- LLM service → LLM tools: uses tools
