# zaqpurpur-neo/topaz-workspace architecture

> Architecture diagram of the GitHub repository zaqpurpur-neo/topaz-workspace, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-08-23). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/zaqpurpur-neo/topaz-workspace
- Repository: https://github.com/zaqpurpur-neo/topaz-workspace

## Overview

#### Purpose and Entry Points
This is a desktop-oriented artwork/reference management application combining a Go backend with a Svelte frontend. It models Krita projects/workspaces, local posts/media, and Danbooru-sourced reference content.

Backend startup is rooted at `main.go`; an additional native entry artifact exists at `main.vala`. Frontend bootstraps from `frontend/src/main.ts` into `frontend/src/App.svelte`, with route selection in `frontend/src/router.ts`.

#### Backend API Boundary
`routes/api.go` defines the backend API surface consumed by the frontend. Controllers form the application boundary for feature operations:
- `controllers/KritaWorkspaceController.go`
- `controllers/KritaArtworkContoller.go`
- `controllers/DanbooruLayerController.go`
- `controllers/PostController.go`

This separates UI/API invocation from project, artwork, post, and external-reference behavior.

#### Krita Workspace and Artwork Domain
Krita-related state is represented by `models/KritaProject.go` and exposed through workspace/artwork controllers. The frontend renders and manipulates this domain through:
- `frontend/src/lib/KritaWorkspacePanel.svelte`
- `frontend/src/lib/KritaWorkspaceItemPanel.svelte`
- `frontend/src/component/KritaWorkspaceComponent.svelte`
- `frontend/src/component/KritaArtworkItemComponent.svelte`

The board-oriented UI also distinguishes primary artwork from references via `frontend/src/component/MainArtworkNode.svelte` and `frontend/src/component/ReferenceNode.svelte`.

#### Post and Media Flow
`models/Post.go` and `controllers/PostController.go` provide the local post/media domain. Presentation is concentrated in `frontend/src/lib/PostDisplay.svelte` and `frontend/src/lib/MediaPanel.svelte`. This creates a flow from backend-managed post data to a dedicated display/media workspace rather than embedding media concerns directly in the Krita project model.

#### Danbooru Reference Integration
Danbooru is a distinct external-content pipeline. Backend handling begins in `controllers/DanbooruLayerController.go`; frontend querying, caching, filtering, pagination, cards, and modal display are split across:
- `frontend/src/stores/danbooruStore.ts`
- `frontend/src/stores/queryCacheStore.ts`
- `frontend/src/lib/DanbooruPanel.svelte`
- `frontend/src/component/DanbooruFilterBar.svelte`
- `frontend/src/component/DanbooruPostModal.svelte`

Typed integration contracts are maintained in `frontend/src/types/DanbooruTypes.ts`. The separation between the Danbooru store and query cache indicates remote-search state is managed independently from workspace state.

#### Frontend Composition and State Boundaries
`frontend/src/lib/MainPanel.svelte` and `frontend/src/lib/SidePanel.svelte` organize the primary application shell. Feature panels isolate major workflows: `frontend/src/lib/KritaBoardPanel.svelte`, `frontend/src/lib/FormPanel.svelte`, and `frontend/src/lib/GitPushPanel.svelte`.

The frontend is a TypeScript Svelte application built with Vite, as indicated by `frontend/package.json`, `frontend/src/main.ts`, and `frontend/vite.config.ts`. Shared cross-feature definitions live in `frontend/src/common.ts`, while board-specific contracts are in `frontend/src/types/KritaBoardTypes.ts`.

#### Runtime, Configuration, and External Services
The backend is Go-based (`go.mod`, `main.go`) and loads application configuration through `config/config.go`. `services/DOHClient.go` introduces a DNS-over-HTTPS service boundary, likely used where resilient or custom hostname resolution is required. Material external dependencies are therefore Danbooru content access and DNS-over-HTTPS; the Git push UI suggests a source-control workflow is exposed to users, though its backend implementation is not present in the listed tree.

Main entry points: [`routes/api.go`](https://github.com/zaqpurpur-neo/topaz-workspace/blob/main/routes/api.go) (API routes), [`frontend/src/lib/MainPanel.svelte`](https://github.com/zaqpurpur-neo/topaz-workspace/blob/main/frontend/src/lib/MainPanel.svelte) (Main and side panels), [`frontend/src/stores/danbooruStore.ts`](https://github.com/zaqpurpur-neo/topaz-workspace/blob/main/frontend/src/stores/danbooruStore.ts) (Danbooru search state), [`main.go`](https://github.com/zaqpurpur-neo/topaz-workspace/blob/main/main.go) (Backend startup)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_backend["Go backend"]
  node_go_main["Backend startup<br/>Go entry point<br/>[main.go]"]
  node_native_main["Native entry artifact<br/>Vala entry point<br/>[main.vala]"]
  node_config["Application config<br/>configuration loader<br/>[config.go]"]
  node_api_routes["API routes<br/>API boundary<br/>[api.go]"]
  node_krita_controllers["Krita controllers<br/>workspace and artwork operations"]
  node_krita_project["Krita project<br/>domain model<br/>[KritaProject.go]"]
  node_post_controller["Post controller<br/>post and media operations<br/>[PostController.go]"]
  node_post_model["Post model<br/>local media domain<br/>[Post.go]"]
  node_danbooru_controller["Danbooru controller<br/>reference-content integration"]
  node_doh_client["DNS-over-HTTPS client<br/>network resolution service<br/>[DOHClient.go]"]
end

subgraph group_frontend["Svelte frontend"]
  node_frontend_boot["Frontend bootstrap<br/>Svelte entry point<br/>[main.ts]"]
  node_app_router["App and router<br/>application composition<br/>[router.ts]"]
  node_app_shell["Main and side panels<br/>application shell<br/>[MainPanel.svelte]"]
  node_krita_ui["Krita workspace and board<br/>workspace UI"]
  node_post_media_ui["Post and media workspace<br/>media UI<br/>[PostDisplay.svelte]"]
  node_danbooru_store["Danbooru search state<br/>remote-query store<br/>[danbooruStore.ts]"]
  node_query_cache["Query cache<br/>search result cache<br/>[queryCacheStore.ts]"]
  node_danbooru_ui["Danbooru panel<br/>reference search UI"]
  node_danbooru_types["Danbooru contracts<br/>TypeScript types<br/>[DanbooruTypes.ts]"]
end

subgraph group_external["External services"]
  node_danbooru(("Danbooru<br/>external content source"))
  node_doh_provider(("DNS-over-HTTPS<br/>external resolver"))
end

node_go_main -->|"loads"| node_config
node_go_main -->|"serves"| node_api_routes
node_api_routes -->|"dispatches"| node_krita_controllers
node_api_routes -->|"dispatches"| node_post_controller
node_api_routes -->|"dispatches"| node_danbooru_controller
node_krita_controllers -->|"manages"| node_krita_project
node_post_controller -->|"manages"| node_post_model
node_danbooru_controller -->|"queries"| node_danbooru
node_doh_client -->|"resolves through"| node_doh_provider
node_frontend_boot -->|"starts"| node_app_router
node_app_router -->|"composes"| node_app_shell
node_app_shell -->|"hosts"| node_krita_ui
node_app_shell -->|"hosts"| node_post_media_ui
node_app_shell -->|"hosts"| node_danbooru_ui
node_krita_ui -->|"workspace API calls"| node_api_routes
node_post_media_ui -->|"post API calls"| node_api_routes
node_danbooru_ui -->|"uses"| node_danbooru_store
node_danbooru_store -->|"caches results"| node_query_cache
node_danbooru_store -->|"search API calls"| node_api_routes
node_danbooru_store -->|"uses contracts"| node_danbooru_types

click node_go_main "https://github.com/zaqpurpur-neo/topaz-workspace/blob/main/main.go"
click node_native_main "https://github.com/zaqpurpur-neo/topaz-workspace/blob/main/main.vala"
click node_config "https://github.com/zaqpurpur-neo/topaz-workspace/blob/main/config/config.go"
click node_api_routes "https://github.com/zaqpurpur-neo/topaz-workspace/blob/main/routes/api.go"
click node_krita_controllers "https://github.com/zaqpurpur-neo/topaz-workspace/blob/main/controllers/KritaWorkspaceController.go"
click node_krita_project "https://github.com/zaqpurpur-neo/topaz-workspace/blob/main/models/KritaProject.go"
click node_post_controller "https://github.com/zaqpurpur-neo/topaz-workspace/blob/main/controllers/PostController.go"
click node_post_model "https://github.com/zaqpurpur-neo/topaz-workspace/blob/main/models/Post.go"
click node_danbooru_controller "https://github.com/zaqpurpur-neo/topaz-workspace/blob/main/controllers/DanbooruLayerController.go"
click node_doh_client "https://github.com/zaqpurpur-neo/topaz-workspace/blob/main/services/DOHClient.go"
click node_frontend_boot "https://github.com/zaqpurpur-neo/topaz-workspace/blob/main/frontend/src/main.ts"
click node_app_router "https://github.com/zaqpurpur-neo/topaz-workspace/blob/main/frontend/src/router.ts"
click node_app_shell "https://github.com/zaqpurpur-neo/topaz-workspace/blob/main/frontend/src/lib/MainPanel.svelte"
click node_krita_ui "https://github.com/zaqpurpur-neo/topaz-workspace/blob/main/frontend/src/lib/KritaWorkspacePanel.svelte"
click node_post_media_ui "https://github.com/zaqpurpur-neo/topaz-workspace/blob/main/frontend/src/lib/PostDisplay.svelte"
click node_danbooru_store "https://github.com/zaqpurpur-neo/topaz-workspace/blob/main/frontend/src/stores/danbooruStore.ts"
click node_query_cache "https://github.com/zaqpurpur-neo/topaz-workspace/blob/main/frontend/src/stores/queryCacheStore.ts"
click node_danbooru_ui "https://github.com/zaqpurpur-neo/topaz-workspace/blob/main/frontend/src/lib/DanbooruPanel.svelte"
click node_danbooru_types "https://github.com/zaqpurpur-neo/topaz-workspace/blob/main/frontend/src/types/DanbooruTypes.ts"

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_go_main,node_native_main,node_config,node_api_routes,node_krita_controllers,node_krita_project,node_post_controller,node_post_model,node_danbooru_controller,node_doh_client toneBlue
class node_frontend_boot,node_app_router,node_app_shell,node_krita_ui,node_post_media_ui,node_danbooru_store,node_query_cache,node_danbooru_ui,node_danbooru_types toneAmber
class node_danbooru,node_doh_provider toneMint
```

## Components

### Go backend

- [Backend startup](https://github.com/zaqpurpur-neo/topaz-workspace/blob/main/main.go): Go entry point · `main.go`
- [Native entry artifact](https://github.com/zaqpurpur-neo/topaz-workspace/blob/main/main.vala): Vala entry point · `main.vala`
- [Application config](https://github.com/zaqpurpur-neo/topaz-workspace/blob/main/config/config.go): configuration loader · `config/config.go`
- [API routes](https://github.com/zaqpurpur-neo/topaz-workspace/blob/main/routes/api.go): API boundary · `routes/api.go`
- [Krita controllers](https://github.com/zaqpurpur-neo/topaz-workspace/blob/main/controllers/KritaWorkspaceController.go): workspace and artwork operations · `controllers/KritaWorkspaceController.go`
- [Krita project](https://github.com/zaqpurpur-neo/topaz-workspace/blob/main/models/KritaProject.go): domain model · `models/KritaProject.go`
- [Post controller](https://github.com/zaqpurpur-neo/topaz-workspace/blob/main/controllers/PostController.go): post and media operations · `controllers/PostController.go`
- [Post model](https://github.com/zaqpurpur-neo/topaz-workspace/blob/main/models/Post.go): local media domain · `models/Post.go`
- [Danbooru controller](https://github.com/zaqpurpur-neo/topaz-workspace/blob/main/controllers/DanbooruLayerController.go): reference-content integration · `controllers/DanbooruLayerController.go`
- [DNS-over-HTTPS client](https://github.com/zaqpurpur-neo/topaz-workspace/blob/main/services/DOHClient.go): network resolution service · `services/DOHClient.go`

### Svelte frontend

- [Frontend bootstrap](https://github.com/zaqpurpur-neo/topaz-workspace/blob/main/frontend/src/main.ts): Svelte entry point · `frontend/src/main.ts`
- [App and router](https://github.com/zaqpurpur-neo/topaz-workspace/blob/main/frontend/src/router.ts): application composition · `frontend/src/router.ts`
- [Main and side panels](https://github.com/zaqpurpur-neo/topaz-workspace/blob/main/frontend/src/lib/MainPanel.svelte): application shell · `frontend/src/lib/MainPanel.svelte`
- [Krita workspace and board](https://github.com/zaqpurpur-neo/topaz-workspace/blob/main/frontend/src/lib/KritaWorkspacePanel.svelte): workspace UI · Renders projects, artwork, and primary/reference board nodes. · `frontend/src/lib/KritaWorkspacePanel.svelte`
- [Post and media workspace](https://github.com/zaqpurpur-neo/topaz-workspace/blob/main/frontend/src/lib/PostDisplay.svelte): media UI · `frontend/src/lib/PostDisplay.svelte`
- [Danbooru search state](https://github.com/zaqpurpur-neo/topaz-workspace/blob/main/frontend/src/stores/danbooruStore.ts): remote-query store · Keeps query state separate from cached results. · `frontend/src/stores/danbooruStore.ts`
- [Query cache](https://github.com/zaqpurpur-neo/topaz-workspace/blob/main/frontend/src/stores/queryCacheStore.ts): search result cache · `frontend/src/stores/queryCacheStore.ts`
- [Danbooru panel](https://github.com/zaqpurpur-neo/topaz-workspace/blob/main/frontend/src/lib/DanbooruPanel.svelte): reference search UI · Includes filtering, pagination, cards, and modal display. · `frontend/src/lib/DanbooruPanel.svelte`
- [Danbooru contracts](https://github.com/zaqpurpur-neo/topaz-workspace/blob/main/frontend/src/types/DanbooruTypes.ts): TypeScript types · `frontend/src/types/DanbooruTypes.ts`

### External services

- **Danbooru**: external content source
- **DNS-over-HTTPS**: external resolver

## Connections

- Backend startup → Application config: loads
- Backend startup → API routes: serves
- API routes → Krita controllers: dispatches
- API routes → Post controller: dispatches
- API routes → Danbooru controller: dispatches
- Krita controllers → Krita project: manages
- Post controller → Post model: manages
- Danbooru controller → Danbooru: queries
- DNS-over-HTTPS client → DNS-over-HTTPS: resolves through
- Frontend bootstrap → App and router: starts
- App and router → Main and side panels: composes
- Main and side panels → Krita workspace and board: hosts
- Main and side panels → Post and media workspace: hosts
- Main and side panels → Danbooru panel: hosts
- Krita workspace and board → API routes: workspace API calls
- Post and media workspace → API routes: post API calls
- Danbooru panel → Danbooru search state: uses
- Danbooru search state → Query cache: caches results
- Danbooru search state → API routes: search API calls
- Danbooru search state → Danbooru contracts: uses contracts
