# ivaldev/agentop architecture

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

- Interactive diagram: https://gitdiagram.com/ivaldev/agentop
- Repository: https://github.com/ivaldev/agentop

## Overview

admin-agent is a local-first, tenant-isolated administrative AI API. An authenticated user submits a chat request; the agent consults document retrieval, asks a configured model for a response or typed tool call, and routes sensitive actions through human approval. Document ingestion and citation-backed search, identity/RBAC, built-in tools, approvals, and append-only audit are distinct product capabilities. The map follows documented and indexed wiring; unsampled worker and integration details are not inferred.

Main entry points: [`app/main.py`](https://github.com/ivaldev/agentop/blob/feat/admin-agent-core/app/main.py) (FastAPI application), [`app/modules/agent/service.py`](https://github.com/ivaldev/agentop/blob/feat/admin-agent-core/app/modules/agent/service.py) (Agent orchestration), [`app/modules/identity`](https://github.com/ivaldev/agentop/tree/feat/admin-agent-core/app/modules/identity) (Identity and RBAC), [`app/modules/documents/service.py`](https://github.com/ivaldev/agentop/blob/feat/admin-agent-core/app/modules/documents/service.py) (Document ingestion)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["API and identity"]
  node_app["FastAPI application<br/>[main.py]"]
  node_identity["Identity and RBAC"]
  node_contracts["API contracts<br/>[schemas.py]"]
end

subgraph group_knowledge["Document knowledge"]
  node_documents["Document ingestion<br/>[service.py]"]
  node_doc_api["Document API<br/>[router.py]"]
  node_blob[("Document blob storage<br/>[storage.py]")]
  node_retrieval["Search and retrieval<br/>[service.py]"]
  node_embedding["Embedding providers<br/>[embeddings.py]"]
end

subgraph group_agent["Agent and tools"]
  node_agent_api["Chat API<br/>[router.py]"]
  node_agent["Agent orchestration<br/>[service.py]"]
  node_prompt["Prompt construction<br/>[prompt.py]"]
  node_llm["Chat model adapters<br/>[llm.py]"]
  node_registry["Typed tool registry<br/>[registry.py]"]
  node_builtin["Built-in tools<br/>[builtin.py]"]
  node_executor["Tool execution<br/>[executor.py]"]
end

subgraph group_governance["Approvals and audit"]
  node_approval_api["Approval API<br/>[router.py]"]
  node_approvals["Approval workflow<br/>[service.py]"]
  node_audit_api["Audit API<br/>[router.py]"]
  node_audit[("Audit trail<br/>[service.py]")]
end

subgraph group_runtime["Runtime infrastructure"]
  node_db[("Database sessions<br/>[db.py]")]
  node_settings["Application settings<br/>[config.py]"]
end

node_user(("Tenant user"))
node_ollama{{"Ollama inference"}}
node_external_llm{{"Compatible model API"}}

node_user -->|"uses API"| node_app
node_app -->|"registers routes"| node_agent_api
node_app -->|"registers routes"| node_doc_api
node_app -->|"registers routes"| node_approval_api
node_app -->|"registers routes"| node_audit_api
node_app -->|"registers routes"| node_identity
node_app -->|"initializes"| node_db
node_user -->|"authenticates"| node_identity
node_agent_api -->|"checks user"| node_identity
node_doc_api -->|"checks user"| node_identity
node_approval_api -->|"checks user"| node_identity
node_audit_api -->|"checks user"| node_identity
node_agent_api -->|"invokes"| node_agent
node_agent -->|"builds prompts"| node_prompt
node_agent -->|"requests completions"| node_llm
node_agent -->|"searches passages"| node_retrieval
node_agent -->|"resolves tools"| node_registry
node_agent -->|"requests approval"| node_approvals
node_agent -->|"records events"| node_audit
node_llm -->|"calls API"| node_ollama
node_llm -.->|"optionally calls"| node_external_llm
node_doc_api -->|"invokes"| node_documents
node_documents -->|"stores files"| node_blob
node_documents -->|"embeds chunks"| node_embedding
node_documents -->|"records events"| node_audit
node_retrieval -->|"embeds queries"| node_embedding
node_retrieval -->|"queries vectors"| node_db
node_registry -->|"registers capabilities"| node_builtin
node_agent -->|"executes calls"| node_executor
node_executor -->|"resolves specs"| node_registry
node_approval_api -->|"invokes"| node_approvals
node_approvals -->|"executes approved call"| node_executor
node_approvals -->|"records decisions"| node_audit
node_audit_api -->|"queries trail"| node_audit
node_identity -->|"loads user"| node_db
node_app -->|"loads configuration"| node_settings
node_contracts -->|"defines chat payloads"| node_agent_api
node_contracts -->|"defines document payloads"| node_doc_api

click node_app "https://github.com/ivaldev/agentop/blob/feat/admin-agent-core/app/main.py"
click node_identity "https://github.com/ivaldev/agentop/tree/feat/admin-agent-core/app/modules/identity"
click node_contracts "https://github.com/ivaldev/agentop/blob/feat/admin-agent-core/packages/contracts/schemas.py"
click node_documents "https://github.com/ivaldev/agentop/blob/feat/admin-agent-core/app/modules/documents/service.py"
click node_doc_api "https://github.com/ivaldev/agentop/blob/feat/admin-agent-core/app/modules/documents/router.py"
click node_blob "https://github.com/ivaldev/agentop/blob/feat/admin-agent-core/app/modules/documents/storage.py"
click node_retrieval "https://github.com/ivaldev/agentop/blob/feat/admin-agent-core/app/modules/retrieval/service.py"
click node_embedding "https://github.com/ivaldev/agentop/blob/feat/admin-agent-core/app/modules/retrieval/embeddings.py"
click node_agent_api "https://github.com/ivaldev/agentop/blob/feat/admin-agent-core/app/modules/agent/router.py"
click node_agent "https://github.com/ivaldev/agentop/blob/feat/admin-agent-core/app/modules/agent/service.py"
click node_prompt "https://github.com/ivaldev/agentop/blob/feat/admin-agent-core/app/modules/agent/prompt.py"
click node_llm "https://github.com/ivaldev/agentop/blob/feat/admin-agent-core/app/modules/agent/llm.py"
click node_registry "https://github.com/ivaldev/agentop/blob/feat/admin-agent-core/app/modules/tools/registry.py"
click node_builtin "https://github.com/ivaldev/agentop/blob/feat/admin-agent-core/app/modules/tools/builtin.py"
click node_executor "https://github.com/ivaldev/agentop/blob/feat/admin-agent-core/app/modules/tools/executor.py"
click node_approval_api "https://github.com/ivaldev/agentop/blob/feat/admin-agent-core/app/modules/approvals/router.py"
click node_approvals "https://github.com/ivaldev/agentop/blob/feat/admin-agent-core/app/modules/approvals/service.py"
click node_audit_api "https://github.com/ivaldev/agentop/blob/feat/admin-agent-core/app/modules/audit/router.py"
click node_audit "https://github.com/ivaldev/agentop/blob/feat/admin-agent-core/app/modules/audit/service.py"
click node_db "https://github.com/ivaldev/agentop/blob/feat/admin-agent-core/app/core/db.py"
click node_settings "https://github.com/ivaldev/agentop/blob/feat/admin-agent-core/app/core/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_identity,node_contracts,node_user toneBlue
class node_documents,node_doc_api,node_blob,node_retrieval,node_embedding toneAmber
class node_agent_api,node_agent,node_prompt,node_llm,node_registry,node_builtin,node_executor,node_external_llm toneMint
class node_approval_api,node_approvals,node_audit_api,node_audit toneRose
class node_db,node_settings,node_ollama toneIndigo
```

## Components

### API and identity

- [FastAPI application](https://github.com/ivaldev/agentop/blob/feat/admin-agent-core/app/main.py): `app/main.py`
- [Identity and RBAC](https://github.com/ivaldev/agentop/tree/feat/admin-agent-core/app/modules/identity): `app/modules/identity`
- [API contracts](https://github.com/ivaldev/agentop/blob/feat/admin-agent-core/packages/contracts/schemas.py): `packages/contracts/schemas.py`

### Document knowledge

- [Document ingestion](https://github.com/ivaldev/agentop/blob/feat/admin-agent-core/app/modules/documents/service.py): `app/modules/documents/service.py`
- [Document API](https://github.com/ivaldev/agentop/blob/feat/admin-agent-core/app/modules/documents/router.py): `app/modules/documents/router.py`
- [Document blob storage](https://github.com/ivaldev/agentop/blob/feat/admin-agent-core/app/modules/documents/storage.py): `app/modules/documents/storage.py`
- [Search and retrieval](https://github.com/ivaldev/agentop/blob/feat/admin-agent-core/app/modules/retrieval/service.py): `app/modules/retrieval/service.py`
- [Embedding providers](https://github.com/ivaldev/agentop/blob/feat/admin-agent-core/app/modules/retrieval/embeddings.py): `app/modules/retrieval/embeddings.py`

### Agent and tools

- [Chat API](https://github.com/ivaldev/agentop/blob/feat/admin-agent-core/app/modules/agent/router.py): `app/modules/agent/router.py`
- [Agent orchestration](https://github.com/ivaldev/agentop/blob/feat/admin-agent-core/app/modules/agent/service.py): `app/modules/agent/service.py`
- [Prompt construction](https://github.com/ivaldev/agentop/blob/feat/admin-agent-core/app/modules/agent/prompt.py): `app/modules/agent/prompt.py`
- [Chat model adapters](https://github.com/ivaldev/agentop/blob/feat/admin-agent-core/app/modules/agent/llm.py): `app/modules/agent/llm.py`
- [Typed tool registry](https://github.com/ivaldev/agentop/blob/feat/admin-agent-core/app/modules/tools/registry.py): `app/modules/tools/registry.py`
- [Built-in tools](https://github.com/ivaldev/agentop/blob/feat/admin-agent-core/app/modules/tools/builtin.py): `app/modules/tools/builtin.py`
- [Tool execution](https://github.com/ivaldev/agentop/blob/feat/admin-agent-core/app/modules/tools/executor.py): `app/modules/tools/executor.py`

### Approvals and audit

- [Approval API](https://github.com/ivaldev/agentop/blob/feat/admin-agent-core/app/modules/approvals/router.py): `app/modules/approvals/router.py`
- [Approval workflow](https://github.com/ivaldev/agentop/blob/feat/admin-agent-core/app/modules/approvals/service.py): `app/modules/approvals/service.py`
- [Audit API](https://github.com/ivaldev/agentop/blob/feat/admin-agent-core/app/modules/audit/router.py): `app/modules/audit/router.py`
- [Audit trail](https://github.com/ivaldev/agentop/blob/feat/admin-agent-core/app/modules/audit/service.py): `app/modules/audit/service.py`

### Runtime infrastructure

- [Database sessions](https://github.com/ivaldev/agentop/blob/feat/admin-agent-core/app/core/db.py): `app/core/db.py`
- [Application settings](https://github.com/ivaldev/agentop/blob/feat/admin-agent-core/app/core/config.py): `app/core/config.py`

### Other components

- **Tenant user**
- **Ollama inference**
- **Compatible model API**

## Connections

- Tenant user → FastAPI application: uses API (evidence: `README.md`)
- FastAPI application → Chat API: registers routes (evidence: `app/main.py`)
- FastAPI application → Document API: registers routes (evidence: `app/main.py`)
- FastAPI application → Approval API: registers routes (evidence: `app/main.py`)
- FastAPI application → Audit API: registers routes (evidence: `app/main.py`)
- FastAPI application → Identity and RBAC: registers routes (evidence: `app/main.py`)
- FastAPI application → Database sessions: initializes (evidence: `app/main.py`)
- Tenant user → Identity and RBAC: authenticates (evidence: `app/modules/identity/deps.py`)
- Chat API → Identity and RBAC: checks user (evidence: `app/modules/agent/router.py`)
- Document API → Identity and RBAC: checks user (evidence: `app/modules/documents/router.py`)
- Approval API → Identity and RBAC: checks user (evidence: `app/modules/approvals/router.py`)
- Audit API → Identity and RBAC: checks user (evidence: `app/modules/audit/router.py`)
- Chat API → Agent orchestration: invokes (evidence: `app/modules/agent/router.py`)
- Agent orchestration → Prompt construction: builds prompts (evidence: `app/modules/agent/service.py`)
- Agent orchestration → Chat model adapters: requests completions (evidence: `app/modules/agent/service.py`)
- Agent orchestration → Search and retrieval: searches passages (evidence: `app/modules/agent/service.py`)
- Agent orchestration → Typed tool registry: resolves tools (evidence: `app/modules/agent/service.py`)
- Agent orchestration → Approval workflow: requests approval (evidence: `app/modules/agent/service.py`)
- Agent orchestration → Audit trail: records events (evidence: `app/modules/agent/service.py`)
- Chat model adapters → Ollama inference: calls API (evidence: `app/modules/agent/llm.py`)
- Chat model adapters → Compatible model API: optionally calls (evidence: `app/modules/agent/llm.py`)
- Document API → Document ingestion: invokes (evidence: `app/modules/documents/router.py`)
- Document ingestion → Document blob storage: stores files (evidence: `app/modules/documents/service.py`)
- Document ingestion → Embedding providers: embeds chunks (evidence: `app/modules/documents/service.py`)
- Document ingestion → Audit trail: records events (evidence: `app/modules/documents/service.py`)
- Search and retrieval → Embedding providers: embeds queries (evidence: `app/modules/retrieval/service.py`)
- Search and retrieval → Database sessions: queries vectors (evidence: `app/modules/retrieval/service.py`)
- Typed tool registry → Built-in tools: registers capabilities (evidence: `app/modules/tools/builtin.py`)
- Agent orchestration → Tool execution: executes calls (evidence: `app/modules/agent/service.py`)
- Tool execution → Typed tool registry: resolves specs (evidence: `app/modules/tools/executor.py`)
- Approval API → Approval workflow: invokes (evidence: `app/modules/approvals/router.py`)
- Approval workflow → Tool execution: executes approved call (evidence: `app/modules/approvals/service.py`)
- Approval workflow → Audit trail: records decisions (evidence: `app/modules/approvals/service.py`)
- Audit API → Audit trail: queries trail (evidence: `app/modules/audit/router.py`)
- Identity and RBAC → Database sessions: loads user (evidence: `app/modules/identity/deps.py`)
- FastAPI application → Application settings: loads configuration (evidence: `app/main.py`)
- API contracts → Chat API: defines chat payloads (evidence: `app/modules/agent/router.py`)
- API contracts → Document API: defines document payloads (evidence: `app/modules/documents/router.py`)
