# cairnepal/heritagegraph architecture

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

- Interactive diagram: https://gitdiagram.com/cairnepal/heritagegraph
- Repository: https://github.com/cairnepal/heritagegraph

## Overview

1. **This is a multi-app monorepo, not a single application.** The runtime is split into a Django backend, two Next.js frontends, and supporting infrastructure for identity, database, proxying, documentation, and ontology assets.

2. **Public-facing entry point:** `heritage_graph_landing` is a separate Next.js site for the public homepage and narrative content. It uses client-heavy visual components like `ThreeCanvas`, `NetworkVisualization`, and a small set of marketing UI components, distinct from the authenticated product UI.

3. **Main product UI:** `heritage_graph_ui` is the authenticated Next.js application. It is organized by product area: dashboard, contribute, curation, knowledge browsing, community, notifications, and user/team pages. The app router structure and reusable component library suggest a page-driven UI over API-backed data, with some pages also using static JSON fixtures.

4. **Backend API and domain logic:** `heritage_graph` is a Django REST Framework service. Its main domain apps are `heritage_data` and `cidoc_data`. `heritage_data` appears to own the core heritage entities, contribution/review workflows, permissions, signals, serializers, and role setup. `cidoc_data` likely supports CIDOC-CRM-aligned or ontology-derived data structures.

5. **Primary request/response flow:** browser requests hit the reverse proxy, then route to the Next.js frontend or Django API depending on hostname/path. The frontend talks to the backend over REST, while the backend also exposes a browsable/admin interface and OpenAPI docs. This means the architecture has a clear UI/API boundary.

6. **Authentication boundary:** authentication is OIDC-based and centered on **Keycloak**. The frontend uses NextAuth-style routes and session handling, while the backend contains auth helpers and token verification logic. The repo includes custom Keycloak themes, so auth is not just external plumbing; it is branded and configured as part of the system.

7. **Persistence layer:** the operational database is **PostgreSQL** in the containerized deployment. The backend has migrations, seed/import commands, and CSV fixtures for domain entities such as persons, deities, festivals, monuments, locations, and sources. This indicates the database is the canonical store for structured heritage content and workflow state.

8. **Knowledge/ontology layer:** the repo also contains a formal schema and RDF/OWL assets (`schema.yaml`, `final_schema.yaml`, `ontology/Heritage.ttl`, `doc_schema.owl`, generated `.owl`/`.yaml` files). This suggests the domain model is ontology-driven, with the backend and UI likely reflecting schema-registry concepts rather than purely ad hoc forms.

9. **Graph/RDF artifact boundary:** the presence of `oxigraph_db` and ontology conversion scripts (`parse_ontology.py`) indicates there is a graph-knowledge representation layer alongside the relational app. Even if not all of it is live runtime, it is architecturally important because it anchors linked-open-data publishing and semantic interoperability.

10. **Infrastructure and deployment:** Docker Compose is the main orchestration mechanism, with separate compose files for backend, frontend, Keycloak, Postgres, and Traefik. Traefik is the edge router, and the repo includes production variants plus Coolify deployment notes. This means environment topology is designed around multiple internal services rather than a single deployable.

11. **Admin and operations surfaces:** the backend includes Django admin and management commands such as CSV import, DB seeding, and role setup. These are operational tools for maintaining data and access control, separate from the public contributor/reviewer UI.

12. **Documentation is a first-class subsystem:** MkDocs content lives in `docs/`, with a generated published site in `site/`, plus several repo-level guides for architecture, auth, forms, deployment, conventions, and troubleshooting. The documentation mirrors the system boundaries and is intended to support both engineers and AI agents.

13. **Internationalization is built into the product:** both backend and frontend have English and Nepali translation assets. The UI and docs are multilingual, so locale routing/content is part of the user-facing architecture, not an afterthought.

Main entry points: [`heritage_graph`](https://github.com/cairnepal/heritagegraph/tree/main/heritage_graph) (Django API), [`heritage_graph_ui`](https://github.com/cairnepal/heritagegraph/tree/main/heritage_graph_ui) (Product UI), [`infra/docker/docker-compose.yml`](https://github.com/cairnepal/heritagegraph/blob/main/infra/docker/docker-compose.yml) (Compose), [`docs`](https://github.com/cairnepal/heritagegraph/tree/main/docs) (Docs source)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_group_infra["Infrastructure"]
  node_node_traefik["Traefik<br/>edge router"]
  node_node_compose["Compose<br/>deployment<br/>[docker-compose.yml]"]
end

subgraph group_group_frontend["Frontends"]
  node_node_public["Landing site<br/>Next.js app"]
  node_node_public_vis["Visuals<br/>client UI"]
  node_node_public_shell["Site shell<br/>app router"]
  node_node_app["Product UI<br/>Next.js app"]
  node_node_app_router["App routes<br/>app router"]
  node_node_app_components["UI kit<br/>component library"]
  node_node_app_i18n["Localization<br/>i18n"]
end

subgraph group_group_backend["Backend"]
  node_node_backend["Django API<br/>DRF service"]
  node_node_backend_urls["API surface<br/>routing<br/>[urls.py]"]
  node_node_heritage_data["Heritage data<br/>domain app"]
  node_node_cidoc_data["CIDOC data<br/>domain app"]
  node_node_backend_ops["Ops commands<br/>management"]
end

subgraph group_group_identity["Identity"]
  node_node_auth["Keycloak<br/>OIDC provider"]
  node_node_keycloak_theme["Themes<br/>branding"]
end

subgraph group_group_knowledge["Knowledge"]
  node_node_schema["Schemas<br/>ontology schema<br/>[schema.yaml]"]
  node_node_ontology["Ontology<br/>RDF/OWL<br/>[Heritage.ttl]"]
  node_node_graphdb[("Graph DB<br/>rdf store")]
end

subgraph group_group_docs["Docs"]
  node_node_docs_src["Docs source<br/>documentation"]
  node_node_docs_site["Published docs<br/>generated site"]
end

node_node_compose -->|"deploys"| node_node_traefik
node_node_compose -->|"starts"| node_node_public
node_node_compose -->|"starts"| node_node_app
node_node_compose -->|"starts"| node_node_backend
node_node_compose -->|"starts"| node_node_auth
node_node_compose -->|"mounts"| node_node_graphdb
node_node_traefik -->|"routes"| node_node_public
node_node_traefik -->|"routes"| node_node_app
node_node_traefik -->|"routes"| node_node_backend
node_node_public -->|"contains"| node_node_public_shell
node_node_public -->|"contains"| node_node_public_vis
node_node_app -->|"contains"| node_node_app_router
node_node_app -->|"uses"| node_node_app_components
node_node_app -->|"uses"| node_node_app_i18n
node_node_app -->|"calls"| node_node_backend
node_node_app -->|"authenticates"| node_node_auth
node_node_backend -->|"exposes"| node_node_backend_urls
node_node_backend -->|"contains"| node_node_heritage_data
node_node_backend -->|"contains"| node_node_cidoc_data
node_node_backend -->|"administers"| node_node_backend_ops
node_node_backend -->|"verifies"| node_node_auth
node_node_backend -->|"aligns to"| node_node_schema
node_node_schema -->|"derives"| node_node_ontology
node_node_ontology -->|"loads into"| node_node_graphdb
node_node_auth -->|"brands"| node_node_keycloak_theme
node_node_docs_src -->|"builds"| node_node_docs_site
node_node_docs_src -->|"documents"| node_node_schema
node_node_docs_src -->|"documents"| node_node_app
node_node_docs_src -->|"documents"| node_node_backend

click node_node_traefik "https://github.com/cairnepal/heritagegraph/tree/main/infra/traefik"
click node_node_compose "https://github.com/cairnepal/heritagegraph/blob/main/infra/docker/docker-compose.yml"
click node_node_public "https://github.com/cairnepal/heritagegraph/tree/main/heritage_graph_landing"
click node_node_public_vis "https://github.com/cairnepal/heritagegraph/tree/main/heritage_graph_landing/app/components"
click node_node_public_shell "https://github.com/cairnepal/heritagegraph/tree/main/heritage_graph_landing/app"
click node_node_app "https://github.com/cairnepal/heritagegraph/tree/main/heritage_graph_ui"
click node_node_app_router "https://github.com/cairnepal/heritagegraph/tree/main/heritage_graph_ui/src/app"
click node_node_app_components "https://github.com/cairnepal/heritagegraph/tree/main/heritage_graph_ui/src/components"
click node_node_app_i18n "https://github.com/cairnepal/heritagegraph/tree/main/heritage_graph_ui/src/i18n"
click node_node_backend "https://github.com/cairnepal/heritagegraph/tree/main/heritage_graph"
click node_node_backend_urls "https://github.com/cairnepal/heritagegraph/blob/main/heritage_graph/urls.py"
click node_node_heritage_data "https://github.com/cairnepal/heritagegraph/tree/main/heritage_graph/apps/heritage_data"
click node_node_cidoc_data "https://github.com/cairnepal/heritagegraph/tree/main/heritage_graph/apps/cidoc_data"
click node_node_backend_ops "https://github.com/cairnepal/heritagegraph/tree/main/heritage_graph/apps/heritage_data/management/commands"
click node_node_auth "https://github.com/cairnepal/heritagegraph/tree/main/keycloak"
click node_node_keycloak_theme "https://github.com/cairnepal/heritagegraph/tree/main/keycloak-themes"
click node_node_schema "https://github.com/cairnepal/heritagegraph/blob/main/schema.yaml"
click node_node_ontology "https://github.com/cairnepal/heritagegraph/blob/main/ontology/Heritage.ttl"
click node_node_graphdb "https://github.com/cairnepal/heritagegraph/tree/main/oxigraph_db"
click node_node_docs_src "https://github.com/cairnepal/heritagegraph/tree/main/docs"
click node_node_docs_site "https://github.com/cairnepal/heritagegraph/tree/main/site"

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_node_traefik,node_node_compose toneBlue
class node_node_public,node_node_public_vis,node_node_public_shell,node_node_app,node_node_app_router,node_node_app_components,node_node_app_i18n toneAmber
class node_node_backend,node_node_backend_urls,node_node_heritage_data,node_node_cidoc_data,node_node_backend_ops toneMint
class node_node_auth,node_node_keycloak_theme toneRose
class node_node_schema,node_node_ontology,node_node_graphdb toneIndigo
class node_node_docs_src,node_node_docs_site toneTeal
```

## Components

### Infrastructure

Deployment, routing, and service orchestration.

- [Traefik](https://github.com/cairnepal/heritagegraph/tree/main/infra/traefik): edge router · Routes browser traffic to the appropriate frontend or API service. · `infra/traefik`
- [Compose](https://github.com/cairnepal/heritagegraph/blob/main/infra/docker/docker-compose.yml): deployment · Service topology for backend, frontend, Keycloak, and Postgres. · `infra/docker/docker-compose.yml`

### Frontends

Public and authenticated Next.js applications.

- [Landing site](https://github.com/cairnepal/heritagegraph/tree/main/heritage_graph_landing): Next.js app · Public-facing homepage and narrative content. · `heritage_graph_landing`
- [Visuals](https://github.com/cairnepal/heritagegraph/tree/main/heritage_graph_landing/app/components): client UI · Hero and graph-like marketing visuals used on the public site. · `heritage_graph_landing/app/components`
- [Site shell](https://github.com/cairnepal/heritagegraph/tree/main/heritage_graph_landing/app): app router · Global layout and main landing page entry points. · `heritage_graph_landing/app`
- [Product UI](https://github.com/cairnepal/heritagegraph/tree/main/heritage_graph_ui): Next.js app · Authenticated application for dashboard, contribution, curation, and knowledge browsing. · `heritage_graph_ui`
- [App routes](https://github.com/cairnepal/heritagegraph/tree/main/heritage_graph_ui/src/app): app router · Route tree for dashboard areas, auth, and content flows. · `heritage_graph_ui/src/app`
- [UI kit](https://github.com/cairnepal/heritagegraph/tree/main/heritage_graph_ui/src/components): component library · Reusable product components, tables, forms, and navigation. · `heritage_graph_ui/src/components`
- [Localization](https://github.com/cairnepal/heritagegraph/tree/main/heritage_graph_ui/src/i18n): i18n · Locale routing, message catalogs, and translation hooks. · `heritage_graph_ui/src/i18n`

### Backend

Django API, domain apps, and operational commands.

- [Django API](https://github.com/cairnepal/heritagegraph/tree/main/heritage_graph): DRF service · Main backend service exposing REST, admin, and browsable API surfaces. · `heritage_graph`
- [API surface](https://github.com/cairnepal/heritagegraph/blob/main/heritage_graph/urls.py): routing · Project URL routing and service entrypoints. · `heritage_graph/urls.py`
- [Heritage data](https://github.com/cairnepal/heritagegraph/tree/main/heritage_graph/apps/heritage_data): domain app · Core heritage entities, contribution workflow, permissions, serializers, and role setup. · `heritage_graph/apps/heritage_data`
- [CIDOC data](https://github.com/cairnepal/heritagegraph/tree/main/heritage_graph/apps/cidoc_data): domain app · CIDOC-CRM-aligned or ontology-derived backend data structures and views. · `heritage_graph/apps/cidoc_data`
- [Ops commands](https://github.com/cairnepal/heritagegraph/tree/main/heritage_graph/apps/heritage_data/management/commands): management · Import, seed, and role provisioning commands for maintaining data and access. · `heritage_graph/apps/heritage_data/management/commands`

### Identity

OIDC authentication and Keycloak theming.

- [Keycloak](https://github.com/cairnepal/heritagegraph/tree/main/keycloak): OIDC provider · Identity provider used for login and session-based authentication. · `keycloak`
- [Themes](https://github.com/cairnepal/heritagegraph/tree/main/keycloak-themes): branding · Custom login, admin, and account themes for the identity layer. · `keycloak-themes`

### Knowledge

Ontology, schema, and graph data assets.

- [Schemas](https://github.com/cairnepal/heritagegraph/blob/main/schema.yaml): ontology schema · YAML and OWL schema artifacts describing the domain model. · `schema.yaml`
- [Ontology](https://github.com/cairnepal/heritagegraph/blob/main/ontology/Heritage.ttl): RDF/OWL · Heritage ontology and generated semantic artifacts. · `ontology/Heritage.ttl`
- [Graph DB](https://github.com/cairnepal/heritagegraph/tree/main/oxigraph_db): rdf store · On-disk graph knowledge store used alongside the relational backend. · `oxigraph_db`

### Docs

Documentation sources and generated site.

- [Docs source](https://github.com/cairnepal/heritagegraph/tree/main/docs): documentation · MkDocs and documentation sources for architecture, auth, deployment, forms, and translation. · `docs`
- [Published docs](https://github.com/cairnepal/heritagegraph/tree/main/site): generated site · Built documentation site and static API reference output. · `site`

## Connections

- Compose → Traefik: deploys · Compose defines the edge router service.
- Compose → Landing site: starts · Compose includes the public Next.js site.
- Compose → Product UI: starts · Compose includes the authenticated Next.js app.
- Compose → Django API: starts · Compose includes the Django backend.
- Compose → Keycloak: starts · Compose includes Keycloak.
- Compose → Graph DB: mounts · Deployment includes the graph store volume.
- Traefik → Landing site: routes · Public traffic is routed to the landing site.
- Traefik → Product UI: routes · Authenticated browser traffic is routed to the product UI.
- Traefik → Django API: routes · API and admin traffic reach the Django service.
- Landing site → Site shell: contains · Landing app shell and page entrypoints.
- Landing site → Visuals: contains · Visual storytelling and hero components.
- Product UI → App routes: contains · App router defines the product area pages.
- Product UI → UI kit: uses · Pages compose shared UI components and widgets.
- Product UI → Localization: uses · Locale-aware routing and messages power translations.
- Product UI → Django API: calls · The frontend consumes backend APIs over REST.
- Product UI → Keycloak: authenticates · Login and session handling rely on OIDC.
- Django API → API surface: exposes · Project URL routing exposes API and admin surfaces.
- Django API → Heritage data: contains · Core heritage domain app.
- Django API → CIDOC data: contains · CIDOC-aligned domain app.
- Django API → Ops commands: administers · Management commands support importing and role setup.
- Django API → Keycloak: verifies · Backend auth helpers verify identity tokens and sessions.
- Django API → Schemas: aligns to · Backend domain models reflect formal schema artifacts.
- Schemas → Ontology: derives · Schema and OWL assets are part of the semantic model.
- Ontology → Graph DB: loads into · Ontology/graph artifacts are persisted in the RDF store.
- Keycloak → Themes: brands · Custom themes shape login and account experience.
- Docs source → Published docs: builds · Docs sources are published as the generated site.
- Docs source → Schemas: documents · Documentation explains the ontology and forms model.
- Docs source → Product UI: documents · Docs cover product workflows and UI behavior.
- Docs source → Django API: documents · Docs cover backend architecture and authentication.
