# keras-team/keras architecture

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

- Interactive diagram: https://gitdiagram.com/keras-team/keras
- Repository: https://github.com/keras-team/keras

## Overview

Keras 3 is a multi-backend deep-learning framework. A typical user builds a model from inputs, layers and operations, configures a loss, metrics and optimizer, then trains or predicts; models can also be saved or exported. The repository tree and README establish these capabilities, while excerpts show selected layer, operation and backend internals. Several domain branches are represented at their documented subsystem directories because their implementations were not sampled; dashed edges mark relationships not verified in the excerpts.

Main entry points: [`keras/api/__init__.py`](https://github.com/keras-team/keras/blob/master/keras/api/__init__.py) (Public API), [`keras/src/models`](https://github.com/keras-team/keras/tree/master/keras/src/models) (Model construction), [`keras/src/trainers/trainer.py`](https://github.com/keras-team/keras/blob/master/keras/src/trainers/trainer.py) (Training and prediction), [`keras/src/ops`](https://github.com/keras-team/keras/tree/master/keras/src/ops) (Keras operations)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_modeling["Modeling and tensors"]
  node_api["Public API<br/>[__init__.py]"]
  node_models["Model construction"]
  node_layers["Layers<br/>[layer.py]"]
  node_attention["Attention layers"]
  node_symbolic["Symbolic tensors<br/>[keras_tensor.py]"]
  node_ops["Keras operations"]
  node_applications["Application models"]
end

subgraph group_learning["Training and data"]
  node_data["Datasets and preprocessing"]
  node_training["Training and prediction<br/>[trainer.py]"]
  node_objectives["Losses and metrics<br/>[losses.py]"]
  node_optimizers["Optimizers"]
  node_callbacks["Training callbacks"]
end

subgraph group_runtime["Backend runtime"]
  node_backend["Backend dispatch<br/>[__init__.py]"]
  node_backend_impl["Backend implementations"]
  node_distribution["Distribution"]
end

subgraph group_lifecycle["Model lifecycle"]
  node_saving["Model saving"]
  node_export["Model export"]
end

node_user(("Keras user"))
node_external_backends{{"Backend frameworks"}}
node_external_storage[("Remote storage")]

node_user -->|"uses"| node_api
node_api -.->|"exposes"| node_models
node_api -->|"exposes"| node_layers
node_api -->|"exposes"| node_ops
node_api -->|"exposes"| node_applications
node_models -.->|"builds graphs"| node_symbolic
node_layers -->|"computes with"| node_ops
node_attention -->|"extends"| node_layers
node_attention -->|"uses"| node_ops
node_ops -->|"dispatches operations"| node_backend
node_backend -->|"selects backend"| node_backend_impl
node_backend_impl -->|"runs on"| node_external_backends
node_user -.->|"provides data"| node_data
node_models -.->|"trains or predicts"| node_training
node_training -.->|"evaluates"| node_objectives
node_training -.->|"updates weights"| node_optimizers
node_training -.->|"uses callbacks"| node_callbacks
node_training -.->|"scales training"| node_distribution
node_models -.->|"saves model"| node_saving
node_models -.->|"exports model"| node_export
node_saving -.->|"reads or writes"| node_external_storage

click node_api "https://github.com/keras-team/keras/blob/master/keras/api/__init__.py"
click node_models "https://github.com/keras-team/keras/tree/master/keras/src/models"
click node_layers "https://github.com/keras-team/keras/blob/master/keras/src/layers/layer.py"
click node_attention "https://github.com/keras-team/keras/blob/master/keras/src/layers/attention/multi_head_attention.py"
click node_symbolic "https://github.com/keras-team/keras/blob/master/keras/src/backend/common/keras_tensor.py"
click node_ops "https://github.com/keras-team/keras/tree/master/keras/src/ops"
click node_backend "https://github.com/keras-team/keras/blob/master/keras/src/backend/__init__.py"
click node_backend_impl "https://github.com/keras-team/keras/tree/master/keras/src/backend"
click node_data "https://github.com/keras-team/keras/tree/master/keras/src/datasets"
click node_training "https://github.com/keras-team/keras/blob/master/keras/src/trainers/trainer.py"
click node_objectives "https://github.com/keras-team/keras/blob/master/keras/src/losses/losses.py"
click node_optimizers "https://github.com/keras-team/keras/tree/master/keras/src/optimizers"
click node_callbacks "https://github.com/keras-team/keras/tree/master/keras/src/callbacks"
click node_applications "https://github.com/keras-team/keras/tree/master/keras/src/applications"
click node_distribution "https://github.com/keras-team/keras/tree/master/keras/src/distribution"
click node_saving "https://github.com/keras-team/keras/tree/master/keras/src/saving"
click node_export "https://github.com/keras-team/keras/tree/master/keras/src/export"

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_api,node_models,node_layers,node_attention,node_symbolic,node_ops,node_applications,node_user toneBlue
class node_data,node_training,node_objectives,node_optimizers,node_callbacks,node_external_storage toneAmber
class node_backend,node_backend_impl,node_distribution toneMint
class node_saving,node_export toneRose
class node_external_backends toneIndigo
```

## Components

### Modeling and tensors

- [Public API](https://github.com/keras-team/keras/blob/master/keras/api/__init__.py): `keras/api/__init__.py`
- [Model construction](https://github.com/keras-team/keras/tree/master/keras/src/models): `keras/src/models`
- [Layers](https://github.com/keras-team/keras/blob/master/keras/src/layers/layer.py): `keras/src/layers/layer.py`
- [Attention layers](https://github.com/keras-team/keras/blob/master/keras/src/layers/attention/multi_head_attention.py): `keras/src/layers/attention/multi_head_attention.py`
- [Symbolic tensors](https://github.com/keras-team/keras/blob/master/keras/src/backend/common/keras_tensor.py): `keras/src/backend/common/keras_tensor.py`
- [Keras operations](https://github.com/keras-team/keras/tree/master/keras/src/ops): `keras/src/ops`
- [Application models](https://github.com/keras-team/keras/tree/master/keras/src/applications): `keras/src/applications`

### Training and data

- [Datasets and preprocessing](https://github.com/keras-team/keras/tree/master/keras/src/datasets): `keras/src/datasets`
- [Training and prediction](https://github.com/keras-team/keras/blob/master/keras/src/trainers/trainer.py): `keras/src/trainers/trainer.py`
- [Losses and metrics](https://github.com/keras-team/keras/blob/master/keras/src/losses/losses.py): `keras/src/losses/losses.py`
- [Optimizers](https://github.com/keras-team/keras/tree/master/keras/src/optimizers): `keras/src/optimizers`
- [Training callbacks](https://github.com/keras-team/keras/tree/master/keras/src/callbacks): `keras/src/callbacks`

### Backend runtime

- [Backend dispatch](https://github.com/keras-team/keras/blob/master/keras/src/backend/__init__.py): `keras/src/backend/__init__.py`
- [Backend implementations](https://github.com/keras-team/keras/tree/master/keras/src/backend): `keras/src/backend`
- [Distribution](https://github.com/keras-team/keras/tree/master/keras/src/distribution): `keras/src/distribution`

### Model lifecycle

- [Model saving](https://github.com/keras-team/keras/tree/master/keras/src/saving): `keras/src/saving`
- [Model export](https://github.com/keras-team/keras/tree/master/keras/src/export): `keras/src/export`

### Other components

- **Keras user**
- **Backend frameworks**
- **Remote storage**

## Connections

- Keras user → Public API: uses (evidence: `README.md`)
- Public API → Model construction: exposes
- Public API → Layers: exposes (evidence: `keras/api/__init__.py`)
- Public API → Keras operations: exposes
- Public API → Application models: exposes
- Model construction → Symbolic tensors: builds graphs
- Layers → Keras operations: computes with (evidence: `keras/src/layers/layer.py`)
- Attention layers → Layers: extends
- Attention layers → Keras operations: uses
- Keras operations → Backend dispatch: dispatches operations (evidence: `keras/src/ops/numpy.py`)
- Backend dispatch → Backend implementations: selects backend (evidence: `keras/src/backend/__init__.py`)
- Backend implementations → Backend frameworks: runs on (evidence: `README.md`)
- Keras user → Datasets and preprocessing: provides data
- Model construction → Training and prediction: trains or predicts
- Training and prediction → Losses and metrics: evaluates
- Training and prediction → Optimizers: updates weights
- Training and prediction → Training callbacks: uses callbacks
- Training and prediction → Distribution: scales training
- Model construction → Model saving: saves model (evidence: `keras/src/saving/serialization_lib.py`)
- Model construction → Model export: exports model
- Model saving → Remote storage: reads or writes (evidence: `README.md`)
