# magomedcoder/kwiki architecture

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

- Interactive diagram: https://gitdiagram.com/magomedcoder/kwiki
- Repository: https://github.com/magomedcoder/kwiki

## Overview

KWiki is a Git-backed wiki: users browse, edit, and manage files and pages through its HTTP UI, while administrators can manage accounts and Git clients can clone or push over HTTP. Startup wires the API to use cases, SQLite metadata/auth repositories, Git content storage, and HTML views. README capabilities guide the subsystem map; unsampled handlers and use cases are included only where their paths are explicit, and unsupported internal links are omitted.

Main entry points: [`internal/adapter/httpapi/handler.go`](https://github.com/magomedcoder/kwiki/blob/main/internal/adapter/httpapi/handler.go) (HTTP router), [`cmd/kwiki/main.go`](https://github.com/magomedcoder/kwiki/blob/main/cmd/kwiki/main.go) (Server startup), [`internal/usecase/page_usecase.go`](https://github.com/magomedcoder/kwiki/blob/main/internal/usecase/page_usecase.go) (Pages and branches), [`internal/adapter/html/renderer.go`](https://github.com/magomedcoder/kwiki/blob/main/internal/adapter/html/renderer.go) (HTML views)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["Runtime entrypoints"]
  node_main["Server startup<br/>[main.go]"]
  node_usercli["User commands<br/>[user.go]"]
end

subgraph group_web["HTTP wiki interface"]
  node_http["HTTP router<br/>[handler.go]"]
  node_fileapi["File routes<br/>[files.go]"]
  node_gitapi["Git HTTP routes<br/>[githttp.go]"]
  node_loginapi["Login and users<br/>[login.go]"]
  node_otherapi["Branches, media, SEO"]
end

subgraph group_wiki["Wiki capabilities"]
  node_pages["Pages and branches<br/>[page_usecase.go]"]
  node_files["File browsing and editing<br/>[files_usecase.go]"]
  node_media["Media operations<br/>[media_usecase.go]"]
  node_staging["Staged edits<br/>[staging.go]"]
  node_auth["Account and sessions<br/>[user_usecase.go]"]
end

subgraph group_storage["Persistence adapters"]
  node_gitstore[("Git content store<br/>[store.go]")]
  node_gitbackend["Git HTTP backend<br/>[httpbackend.go]"]
  node_sqlrepo[("Page and branch index<br/>[repository.go]")]
  node_sqlbranch[("Branch repository<br/>[branch.go]")]
  node_sqlauth[("Account repositories<br/>[auth.go]")]
end

subgraph group_presentation["Rendering and language"]
  node_renderer["HTML views<br/>[renderer.go]"]
  node_markdown["Markdown renderer<br/>[markdown.go]"]
  node_help["Help content<br/>[help.go]"]
  node_i18n["Localization<br/>[i18n.go]"]
end

node_operator(("Wiki user"))
node_gitclient(("Git client"))

node_operator -->|"uses wiki"| node_http
node_gitclient -->|"clones and pushes"| node_gitapi
node_main -->|"opens repository"| node_gitstore
node_main -->|"opens database"| node_sqlrepo
node_main -->|"initializes auth"| node_auth
node_main -->|"registers routes"| node_http
node_main -->|"loads views"| node_renderer
node_main -->|"loads language"| node_i18n
node_main -->|"configures Git"| node_gitbackend
node_usercli -->|"manages accounts"| node_auth
node_http -->|"routes files"| node_fileapi
node_http -->|"routes Git"| node_gitapi
node_http -->|"routes login"| node_loginapi
node_http -->|"registers routes"| node_otherapi
node_http -->|"requests page data"| node_pages
node_http -->|"renders responses"| node_renderer
node_fileapi -->|"handles file actions"| node_files
node_gitapi -->|"dispatches Git"| node_gitbackend
node_loginapi -->|"authenticates users"| node_auth
node_pages -->|"reads and writes content"| node_gitstore
node_pages -->|"indexes pages"| node_sqlrepo
node_pages -.->|"stores branches"| node_sqlbranch
node_files -->|"reads and changes files"| node_gitstore
node_files -.->|"checks branches"| node_pages
node_media -.->|"accesses media"| node_gitstore
node_pages -->|"uses staged media"| node_staging
node_auth -->|"stores users and sessions"| node_sqlauth
node_renderer -->|"renders page text"| node_markdown
node_renderer -->|"translates templates"| node_i18n
node_help -->|"renders help text"| node_markdown

click node_main "https://github.com/magomedcoder/kwiki/blob/main/cmd/kwiki/main.go"
click node_usercli "https://github.com/magomedcoder/kwiki/blob/main/cmd/kwiki/user.go"
click node_http "https://github.com/magomedcoder/kwiki/blob/main/internal/adapter/httpapi/handler.go"
click node_fileapi "https://github.com/magomedcoder/kwiki/blob/main/internal/adapter/httpapi/files.go"
click node_gitapi "https://github.com/magomedcoder/kwiki/blob/main/internal/adapter/httpapi/githttp.go"
click node_loginapi "https://github.com/magomedcoder/kwiki/blob/main/internal/adapter/httpapi/login.go"
click node_otherapi "https://github.com/magomedcoder/kwiki/tree/main/internal/adapter/httpapi"
click node_pages "https://github.com/magomedcoder/kwiki/blob/main/internal/usecase/page_usecase.go"
click node_files "https://github.com/magomedcoder/kwiki/blob/main/internal/usecase/files_usecase.go"
click node_media "https://github.com/magomedcoder/kwiki/blob/main/internal/usecase/media_usecase.go"
click node_staging "https://github.com/magomedcoder/kwiki/blob/main/internal/usecase/staging.go"
click node_auth "https://github.com/magomedcoder/kwiki/blob/main/internal/usecase/user_usecase.go"
click node_gitstore "https://github.com/magomedcoder/kwiki/blob/main/internal/adapter/git/store.go"
click node_gitbackend "https://github.com/magomedcoder/kwiki/blob/main/internal/adapter/git/httpbackend.go"
click node_sqlrepo "https://github.com/magomedcoder/kwiki/blob/main/internal/adapter/sqlite/repository.go"
click node_sqlbranch "https://github.com/magomedcoder/kwiki/blob/main/internal/adapter/sqlite/branch.go"
click node_sqlauth "https://github.com/magomedcoder/kwiki/blob/main/internal/adapter/sqlite/auth.go"
click node_renderer "https://github.com/magomedcoder/kwiki/blob/main/internal/adapter/html/renderer.go"
click node_markdown "https://github.com/magomedcoder/kwiki/blob/main/internal/adapter/markdown/markdown.go"
click node_help "https://github.com/magomedcoder/kwiki/blob/main/internal/adapter/html/help.go"
click node_i18n "https://github.com/magomedcoder/kwiki/blob/main/internal/adapter/i18n/i18n.go"

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_main,node_usercli,node_operator,node_gitclient toneBlue
class node_http,node_fileapi,node_gitapi,node_loginapi,node_otherapi toneAmber
class node_pages,node_files,node_media,node_staging,node_auth toneMint
class node_gitstore,node_gitbackend,node_sqlrepo,node_sqlbranch,node_sqlauth toneRose
class node_renderer,node_markdown,node_help,node_i18n toneIndigo
```

## Components

### Runtime entrypoints

- [Server startup](https://github.com/magomedcoder/kwiki/blob/main/cmd/kwiki/main.go): `cmd/kwiki/main.go`
- [User commands](https://github.com/magomedcoder/kwiki/blob/main/cmd/kwiki/user.go): `cmd/kwiki/user.go`

### HTTP wiki interface

- [HTTP router](https://github.com/magomedcoder/kwiki/blob/main/internal/adapter/httpapi/handler.go): `internal/adapter/httpapi/handler.go`
- [File routes](https://github.com/magomedcoder/kwiki/blob/main/internal/adapter/httpapi/files.go): `internal/adapter/httpapi/files.go`
- [Git HTTP routes](https://github.com/magomedcoder/kwiki/blob/main/internal/adapter/httpapi/githttp.go): `internal/adapter/httpapi/githttp.go`
- [Login and users](https://github.com/magomedcoder/kwiki/blob/main/internal/adapter/httpapi/login.go): `internal/adapter/httpapi/login.go`
- [Branches, media, SEO](https://github.com/magomedcoder/kwiki/tree/main/internal/adapter/httpapi): `internal/adapter/httpapi`

### Wiki capabilities

- [Pages and branches](https://github.com/magomedcoder/kwiki/blob/main/internal/usecase/page_usecase.go): `internal/usecase/page_usecase.go`
- [File browsing and editing](https://github.com/magomedcoder/kwiki/blob/main/internal/usecase/files_usecase.go): `internal/usecase/files_usecase.go`
- [Media operations](https://github.com/magomedcoder/kwiki/blob/main/internal/usecase/media_usecase.go): `internal/usecase/media_usecase.go`
- [Staged edits](https://github.com/magomedcoder/kwiki/blob/main/internal/usecase/staging.go): `internal/usecase/staging.go`
- [Account and sessions](https://github.com/magomedcoder/kwiki/blob/main/internal/usecase/user_usecase.go): `internal/usecase/user_usecase.go`

### Persistence adapters

- [Git content store](https://github.com/magomedcoder/kwiki/blob/main/internal/adapter/git/store.go): `internal/adapter/git/store.go`
- [Git HTTP backend](https://github.com/magomedcoder/kwiki/blob/main/internal/adapter/git/httpbackend.go): `internal/adapter/git/httpbackend.go`
- [Page and branch index](https://github.com/magomedcoder/kwiki/blob/main/internal/adapter/sqlite/repository.go): `internal/adapter/sqlite/repository.go`
- [Branch repository](https://github.com/magomedcoder/kwiki/blob/main/internal/adapter/sqlite/branch.go): `internal/adapter/sqlite/branch.go`
- [Account repositories](https://github.com/magomedcoder/kwiki/blob/main/internal/adapter/sqlite/auth.go): `internal/adapter/sqlite/auth.go`

### Rendering and language

- [HTML views](https://github.com/magomedcoder/kwiki/blob/main/internal/adapter/html/renderer.go): `internal/adapter/html/renderer.go`
- [Markdown renderer](https://github.com/magomedcoder/kwiki/blob/main/internal/adapter/markdown/markdown.go): `internal/adapter/markdown/markdown.go`
- [Help content](https://github.com/magomedcoder/kwiki/blob/main/internal/adapter/html/help.go): `internal/adapter/html/help.go`
- [Localization](https://github.com/magomedcoder/kwiki/blob/main/internal/adapter/i18n/i18n.go): `internal/adapter/i18n/i18n.go`

### Other components

- **Wiki user**
- **Git client**

## Connections

- Wiki user → HTTP router: uses wiki (evidence: `README.md`)
- Git client → Git HTTP routes: clones and pushes (evidence: `README.md`)
- Server startup → Git content store: opens repository (evidence: `cmd/kwiki/main.go`)
- Server startup → Page and branch index: opens database (evidence: `cmd/kwiki/main.go`)
- Server startup → Account and sessions: initializes auth (evidence: `cmd/kwiki/main.go`)
- Server startup → HTTP router: registers routes (evidence: `cmd/kwiki/main.go`)
- Server startup → HTML views: loads views (evidence: `cmd/kwiki/main.go`)
- Server startup → Localization: loads language (evidence: `cmd/kwiki/main.go`)
- Server startup → Git HTTP backend: configures Git (evidence: `cmd/kwiki/main.go`)
- User commands → Account and sessions: manages accounts (evidence: `cmd/kwiki/user.go`)
- HTTP router → File routes: routes files (evidence: `internal/adapter/httpapi/handler.go`)
- HTTP router → Git HTTP routes: routes Git (evidence: `internal/adapter/httpapi/handler.go`)
- HTTP router → Login and users: routes login (evidence: `internal/adapter/httpapi/handler.go`)
- HTTP router → Branches, media, SEO: registers routes (evidence: `internal/adapter/httpapi/handler.go`)
- HTTP router → Pages and branches: requests page data (evidence: `internal/adapter/httpapi/handler.go`)
- HTTP router → HTML views: renders responses (evidence: `internal/adapter/httpapi/handler.go`)
- File routes → File browsing and editing: handles file actions (evidence: `internal/adapter/httpapi/files.go`)
- Git HTTP routes → Git HTTP backend: dispatches Git (evidence: `internal/adapter/httpapi/githttp.go`)
- Login and users → Account and sessions: authenticates users (evidence: `internal/adapter/httpapi/login.go`)
- Pages and branches → Git content store: reads and writes content (evidence: `internal/usecase/page_usecase.go`)
- Pages and branches → Page and branch index: indexes pages (evidence: `internal/usecase/page_usecase.go`)
- Pages and branches → Branch repository: stores branches
- File browsing and editing → Git content store: reads and changes files (evidence: `internal/usecase/files_usecase.go`)
- File browsing and editing → Pages and branches: checks branches
- Media operations → Git content store: accesses media
- Pages and branches → Staged edits: uses staged media (evidence: `internal/usecase/page_usecase.go`)
- Account and sessions → Account repositories: stores users and sessions (evidence: `internal/usecase/user_usecase.go`)
- HTML views → Markdown renderer: renders page text (evidence: `internal/adapter/html/renderer.go`)
- HTML views → Localization: translates templates (evidence: `internal/adapter/html/renderer.go`)
- Help content → Markdown renderer: renders help text (evidence: `internal/adapter/html/help.go`)
