# zopefoundation/zope.component architecture

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

- Interactive diagram: https://gitdiagram.com/zopefoundation/zope.component
- Repository: https://github.com/zopefoundation/zope.component

## Overview

zope.component is a reusable implementation of the Zope Component Architecture: it registers adapters, utilities, handlers and factories, then resolves them through component lookup APIs. The principal workflow is to declare or configure components, register them with a site manager, and query that manager to obtain a component or adapted result. Event dispatch, site-specific lookup, persistent registries and security-aware configuration are distinct capabilities. Relationships below follow shown imports/calls and README statements; some source modules were indexed but not excerpted, so uncertain links are omitted.

Main entry points: [`src/zope/component/_api.py`](https://github.com/zopefoundation/zope.component/blob/master/src/zope/component/_api.py) (Component API), [`src/zope/component/zcml.py`](https://github.com/zopefoundation/zope.component/blob/master/src/zope/component/zcml.py) (ZCML handlers), [`src/zope/component/_declaration.py`](https://github.com/zopefoundation/zope.component/blob/master/src/zope/component/_declaration.py) (Adapter declarations), [`src/zope/component/hooks.py`](https://github.com/zopefoundation/zope.component/blob/master/src/zope/component/hooks.py) (Site hooks)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_registration["Registration"]
  node_declarations["Adapter declarations<br/>[_declaration.py]"]
  node_zcml["ZCML handlers<br/>[zcml.py]"]
  node_global[("Global registry<br/>[globalregistry.py]")]
  node_registry["Registry events<br/>[registry.py]"]
end

subgraph group_lookup["Lookup"]
  node_interfaces["Architecture contracts<br/>[interfaces.py]"]
  node_api["Component API<br/>[_api.py]"]
  node_interface["Interface integration<br/>[interface.py]"]
  node_factory["Factory service<br/>[factory.py]"]
end

subgraph group_runtime["Runtime context"]
  node_sitehooks["Site hooks<br/>[hooks.py]"]
  node_persistent[("Persistent registry")]
  node_compat["Compatibility support<br/>[_compat.py]"]
end

subgraph group_extensions["Events and extensions"]
  node_security["Security adapters<br/>[security.py]"]
  node_event["Event dispatch<br/>[event.py]"]
  node_eventtesting["Event setup helpers<br/>[eventtesting.py]"]
end

node_developer(("Application code"))

node_developer -->|"declares adapters"| node_declarations
node_developer -->|"configures components"| node_zcml
node_declarations -.->|"registers components"| node_global
node_zcml -->|"queues registration"| node_api
node_developer -->|"requests lookup"| node_api
node_api -->|"resolves through"| node_global
node_api -->|"uses contracts"| node_interfaces
node_interface -->|"uses lookup"| node_api
node_factory -->|"implements contract"| node_interfaces
node_sitehooks -->|"gets global manager"| node_global
node_sitehooks -->|"sets lookup hooks"| node_api
node_zcml -->|"reads declarations"| node_declarations
node_zcml -->|"uses security wrappers"| node_security
node_security -->|"checks availability"| node_compat
node_sitehooks -->|"checks availability"| node_compat
node_event -->|"dispatches subscribers"| node_api
node_event -->|"declares event adapter"| node_declarations
node_eventtesting -->|"registers notifier"| node_event
node_eventtesting -->|"registers event handlers"| node_registry

click node_declarations "https://github.com/zopefoundation/zope.component/blob/master/src/zope/component/_declaration.py"
click node_zcml "https://github.com/zopefoundation/zope.component/blob/master/src/zope/component/zcml.py"
click node_global "https://github.com/zopefoundation/zope.component/blob/master/src/zope/component/globalregistry.py"
click node_registry "https://github.com/zopefoundation/zope.component/blob/master/src/zope/component/registry.py"
click node_interfaces "https://github.com/zopefoundation/zope.component/blob/master/src/zope/component/interfaces.py"
click node_api "https://github.com/zopefoundation/zope.component/blob/master/src/zope/component/_api.py"
click node_interface "https://github.com/zopefoundation/zope.component/blob/master/src/zope/component/interface.py"
click node_factory "https://github.com/zopefoundation/zope.component/blob/master/src/zope/component/factory.py"
click node_sitehooks "https://github.com/zopefoundation/zope.component/blob/master/src/zope/component/hooks.py"
click node_persistent "https://github.com/zopefoundation/zope.component/blob/master/src/zope/component/persistentregistry.py"
click node_compat "https://github.com/zopefoundation/zope.component/blob/master/src/zope/component/_compat.py"
click node_security "https://github.com/zopefoundation/zope.component/blob/master/src/zope/component/security.py"
click node_event "https://github.com/zopefoundation/zope.component/blob/master/src/zope/component/event.py"
click node_eventtesting "https://github.com/zopefoundation/zope.component/blob/master/src/zope/component/eventtesting.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_declarations,node_zcml,node_global,node_registry toneBlue
class node_interfaces,node_api,node_interface,node_factory toneAmber
class node_sitehooks,node_persistent,node_compat toneMint
class node_security,node_event,node_eventtesting toneRose
class node_developer toneIndigo
```

## Components

### Registration

- [Adapter declarations](https://github.com/zopefoundation/zope.component/blob/master/src/zope/component/_declaration.py): `src/zope/component/_declaration.py`
- [ZCML handlers](https://github.com/zopefoundation/zope.component/blob/master/src/zope/component/zcml.py): `src/zope/component/zcml.py`
- [Global registry](https://github.com/zopefoundation/zope.component/blob/master/src/zope/component/globalregistry.py): `src/zope/component/globalregistry.py`
- [Registry events](https://github.com/zopefoundation/zope.component/blob/master/src/zope/component/registry.py): `src/zope/component/registry.py`

### Lookup

- [Architecture contracts](https://github.com/zopefoundation/zope.component/blob/master/src/zope/component/interfaces.py): `src/zope/component/interfaces.py`
- [Component API](https://github.com/zopefoundation/zope.component/blob/master/src/zope/component/_api.py): `src/zope/component/_api.py`
- [Interface integration](https://github.com/zopefoundation/zope.component/blob/master/src/zope/component/interface.py): `src/zope/component/interface.py`
- [Factory service](https://github.com/zopefoundation/zope.component/blob/master/src/zope/component/factory.py): `src/zope/component/factory.py`

### Runtime context

- [Site hooks](https://github.com/zopefoundation/zope.component/blob/master/src/zope/component/hooks.py): `src/zope/component/hooks.py`
- [Persistent registry](https://github.com/zopefoundation/zope.component/blob/master/src/zope/component/persistentregistry.py): `src/zope/component/persistentregistry.py`
- [Compatibility support](https://github.com/zopefoundation/zope.component/blob/master/src/zope/component/_compat.py): `src/zope/component/_compat.py`

### Events and extensions

- [Security adapters](https://github.com/zopefoundation/zope.component/blob/master/src/zope/component/security.py): `src/zope/component/security.py`
- [Event dispatch](https://github.com/zopefoundation/zope.component/blob/master/src/zope/component/event.py): `src/zope/component/event.py`
- [Event setup helpers](https://github.com/zopefoundation/zope.component/blob/master/src/zope/component/eventtesting.py): `src/zope/component/eventtesting.py`

### Other components

- **Application code**

## Connections

- Application code → Adapter declarations: declares adapters (evidence: `src/zope/component/_declaration.py`)
- Application code → ZCML handlers: configures components (evidence: `README.rst`)
- Adapter declarations → Global registry: registers components
- ZCML handlers → Component API: queues registration (evidence: `src/zope/component/zcml.py`)
- Application code → Component API: requests lookup (evidence: `README.rst`)
- Component API → Global registry: resolves through (evidence: `src/zope/component/_api.py`)
- Component API → Architecture contracts: uses contracts (evidence: `src/zope/component/_api.py`)
- Interface integration → Component API: uses lookup (evidence: `src/zope/component/interface.py`)
- Factory service → Architecture contracts: implements contract (evidence: `src/zope/component/factory.py`)
- Site hooks → Global registry: gets global manager (evidence: `src/zope/component/hooks.py`)
- Site hooks → Component API: sets lookup hooks (evidence: `src/zope/component/hooks.py`)
- ZCML handlers → Adapter declarations: reads declarations (evidence: `src/zope/component/zcml.py`)
- ZCML handlers → Security adapters: uses security wrappers (evidence: `src/zope/component/zcml.py`)
- Security adapters → Compatibility support: checks availability (evidence: `src/zope/component/security.py`)
- Site hooks → Compatibility support: checks availability (evidence: `src/zope/component/hooks.py`)
- Event dispatch → Component API: dispatches subscribers (evidence: `src/zope/component/event.py`)
- Event dispatch → Adapter declarations: declares event adapter (evidence: `src/zope/component/event.py`)
- Event setup helpers → Event dispatch: registers notifier (evidence: `src/zope/component/eventtesting.py`)
- Event setup helpers → Registry events: registers event handlers (evidence: `src/zope/component/eventtesting.py`)
