Files
hnh-map/docs/architecture.md
Nikolay Tatarinov fea17e6bac Refactor routing and documentation for SPA deployment
- Updated the application to serve the SPA from the root path instead of /map/, enhancing accessibility.
- Modified redirect logic to ensure backward compatibility with old /map/* URLs.
- Adjusted documentation across multiple files to reflect the new routing structure and API endpoints.
- Improved handling of OAuth redirects and session management in the backend.
- Updated frontend configuration to align with the new base URL settings.
2026-02-25 00:32:59 +03:00

45 lines
3.7 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# Архитектура hnh-map
## Обзор
hnh-map — сервер автомаппера для HnH: Go-бэкенд с хранилищем bbolt, сессиями и Nuxt 3 SPA по корню `/`. API, SSE и тайлы — по `/map/api/`, `/map/updates`, `/map/grids/`. Данные гридов и тайлов хранятся в каталоге `grids/` и в БД.
```
┌─────────────┐ HTTP/SSE ┌──────────────────────────────────────┐
│ Браузер │ ◄────────────────► │ Go-сервер (cmd/hnh-map) │
│ (Nuxt SPA │ /, /login, │ • bbolt (users, sessions, grids, │
│ по /) │ /map/api, │ markers, tiles, maps, config) │
│ │ /map/updates, │ • Статика фронта (frontend/) │
│ │ /map/grids/ │ • internal/app — вся логика │
└─────────────┘ └──────────────────────────────────────┘
```
## Структура бэкенда
- **cmd/hnh-map/main.go** — единственная точка входа (`package main`): парсинг флагов (`-grids`, `-port`) и переменных окружения (`HNHMAP_PORT`), открытие bbolt, запуск миграций, создание `App`, регистрация маршрутов, запуск HTTP-сервера. Пути к `frontend/` и `public/` задаются из рабочей директории при старте.
- **internal/app/** — пакет `app` с типом `App` и всей логикой:
- **app.go** — структура `App`, общие типы (`Character`, `Session`, `Coord`, `Position`, `Marker`, `User`, `MapInfo`, `GridData` и т.д.), регистрация маршрутов (`RegisterRoutes`), `serveSPARoot`, `CleanChars`.
- **auth.go** — сессии и авторизация: `getSession`, `deleteSession`, `saveSession`, `getUser`, `getPage`, `createSession`, `setupRequired`, `requireAdmin`.
- **api.go** — HTTP API: авторизация (login, me, logout, setup), кабинет (tokens, password), админ (users, settings, maps, wipe, rebuildZooms, export, merge), роутер `/map/api/...`.
- **handlers_redirects.go** — редирект `/logout``/login` (после удаления сессии).
- **client.go** — роутер клиента маппера (`/client/{token}/...`), `locate`.
- **client_grid.go** — `gridUpdate`, `gridUpload`, `updateZoomLevel`.
- **client_positions.go** — `updatePositions`.
- **client_markers.go** — `uploadMarkers`.
- **admin_rebuild.go** — `doRebuildZooms`.
- **admin_tiles.go** — `wipeTile`, `setCoords`.
- **admin_markers.go** — `hideMarker`.
- **admin_export.go** — `export`.
- **admin_merge.go** — `merge`.
- **map.go** — доступ к карте: `canAccessMap`, `getChars`, `getMarkers`, `getMaps`, `config`.
- **tile.go** — тайлы и гриды: `GetTile`, `SaveTile`, `watchGridUpdates` (SSE), `gridTile`, `reportMerge`.
- **topic.go** — типы `topic` и `mergeTopic` для рассылки обновлений тайлов и слияний карт.
- **migrations.go** — миграции bbolt; из main вызывается `app.RunMigrations(db)`.
Сборка из корня репозитория:
```bash
go build -o hnh-map ./cmd/hnh-map
```