How vervelak/lastwar-alliance-manager works
Purpose and Entry Points
Last War Alliance Manager is a local/self-hosted Go application for alliance operations in *Last War: Survival*: membership, role-controlled administration, scheduling, rankings, awards, VS/storm tracking, and OCR-assisted screenshot ingestion. The server entry point and API/router implementation are centralized in main.go; OCR-specific logic is separated in mg_ocr.go. The browser UI is static vanilla JavaScript served by the Go process, beginning with static/login.html and static/index.html.
Backend and Persistence
main.go owns application bootstrap, SQLite schema/initialization, HTTP routes, authorization middleware, business operations, and static-file serving. SQLite is the sole durable store, located through DATABASE_PATH and persisted as a host-mounted ./data/alliance.db in Compose deployments. Authentication uses bcrypt password hashes and Gorilla signed-cookie sessions, with SESSION_KEY determining session continuity.
Identity and Authorization Boundary
Users may be standalone admins or linked to alliance members, inheriting member rank permissions. Backend API handlers enforce role boundaries: Admin/R5 settings and account management; R4/R5 member and schedule changes; R3+ screenshot/upload workflows; lower ranks read-only. The frontend uses shared session/navigation behavior in static/common.js and static/navigation.js, but backend enforcement in main.go is the security boundary.
Alliance Operations Domain
The main operational model centers on members, ranks, schedules, awards, recommendations, rankings, conduct reports, deleted-member history, and event-specific tracking. Member management is driven from static/index.html / static/app.js; scheduling from static/train.html / static/train.js; configurable scoring and templates from static/settings.html / static/settings.js. These pages call protected JSON APIs exposed by main.go, which calculate and persist results in SQLite.
Ranking, Scheduling, and Messaging Flow
Awards, recommendations, rank bonuses, first-time boosts, and historical conductor penalties feed server-side performance ranking. Auto-scheduling selects weekly conductors and eligible R4/R5 backups, then persisted schedule entries drive generated weekly and daily alliance-chat messages. The primary UI consumers are static/rankings.js, static/train.js, and static/awards.js; authoritative calculations and message generation remain in main.go.
Screenshot Recognition Pipeline
Mobile-oriented uploads and manual entry originate in static/upload.html / static/upload.js, with adjacent VS workflows in static/vs.html / static/vs.js. Requests cross into Go OCR processing in mg_ocr.go, which uses Tesseract and image preprocessing/parsing to extract game data, fuzzy-match members, and store power or VS history. Marshal Guard image segmentation is independently deployable as mg_segment/main.go, with its own container definition at mg_segment/Dockerfile.
Runtime and Deployment
The primary runtime is Go 1.23 with SQLite and Tesseract/gosseract; OCR requires CGO plus native Tesseract libraries outside the supplied container. Dockerfile provides the application image, while docker-compose.yml runs it with persistent database storage. Production can sit behind Caddy via Caddyfile, or run as a systemd service using lastwar.service. Browser automation is external Playwright infrastructure under playwright-tests/.
Main entry points: main.go HTTP API and router · mg_ocr.go OCR extraction and matching · docker-compose.yml Compose deployment · Dockerfile Application container
Components 18
Browser UI
- Member operations · Membership and role administration UI.
static/index.html - Schedule UI
static/train.html - Rankings and awards UI
static/rankings.js - Settings UI · Scoring and template configuration.
static/settings.html - Screenshot upload UI
static/upload.html - VS workflow UI
static/vs.html - Session navigation
static/common.js
Go application
- HTTP API and router · Serves static UI and protected JSON APIs.
main.go - Session and authorization · Backend role enforcement is the security boundary.
main.go - Alliance operations · Members, ranks, schedules, awards, rankings, and messages.
main.go - Alliance database · Sole durable store for operational and history data.
Recognition pipeline
- OCR extraction and matching · Preprocesses images, parses game data, and fuzzy-matches members.
mg_ocr.go - Tesseract native OCR · Used through CGO and gosseract.
- Marshal Guard segmentation · Independently deployable image segmentation stage.
mg_segment/main.go
Deployment
- Application container · Go 1.23 application runtime.
Dockerfile - Compose deployment · Mounts persistent database storage.
docker-compose.yml - Reverse proxy · Optional production proxy.
Caddyfile - Browser automation · External browser automation infrastructure.
Connections 20
- Member operations → HTTP API and router: protected JSON API
- Schedule UI → HTTP API and router: protected JSON API
- Rankings and awards UI → HTTP API and router: read rankings
- Settings UI → HTTP API and router: admin API
- Screenshot upload UI → HTTP API and router: upload and manual entry
- VS workflow UI → HTTP API and router: VS API
- Session navigation → HTTP API and router: session requests
- HTTP API and router → Session and authorization: authorizes requests
- Session and authorization → Alliance operations: permits role-scoped actions
- HTTP API and router → Alliance operations: routes operations
- Alliance operations → Alliance database: persists operational data
- HTTP API and router → OCR extraction and matching: screenshot processing
- OCR extraction and matching → Tesseract native OCR: recognizes text
- OCR extraction and matching → Alliance database: stores power and VS history
- Marshal Guard segmentation → OCR extraction and matching: segmented images
- Application container → HTTP API and router: runs
- Compose deployment → Application container: deploys
- Compose deployment → Alliance database: mounts data volume
- Reverse proxy → HTTP API and router: proxies requests
- Browser automation → HTTP API and router: automates browser flows