2 Code Layout
Nate edited this page 2026-11-22 17:57:19 -08:00

Code Layout

Every directory and package in the repository. Architecture explains how the layers fit together.

Entry points

Package What it is Imports
cmd/evesynapse/ the release server: thin wiring (config → app → HTTP server). It does not import internal/devtools, so the release binary contains no dev-login code and DEV_LOGIN=1 has no effect on it app, logging, pidfile, selfupdate
cmd/evesynapse-dev/ the dev server: identical wiring plus the dev-only routes (/dev-login). Local testing only; never deploy this binary as above, plus devtools
cmd/modbuild/ the module build tool: lists the modules, what each requires and the scopes it declares, and writes internal/app/modules_enabled.go for a selection app/module, app/modulecatalog
cmd/releasesign/ the maintainer's release-signing tool: makes the release key, signs the release's latest.json in the release job, checks a signature by hand. Never deployed releasesig
cmd/residue-corpus/ builds labeled training examples for the intel residue reader from production exports (the residue calls and the reports they fed), with labels taken only from verified outcomes. A maintainer tool; never deployed intelanalyze
cmd/mkicons/ draws the raster icons from the logo's SVG files in internal/app/static/: logo.svg (the mark, shown in the page header), icon.svg (the app icon) and favicon.svg (the simplified small one). To change the logo, replace those and run go run ./cmd/mkicons: it rewrites favicon.ico, the four PNG app icons and the notification badge beside them standard library only

Core: internal/app/

The application: config + .env loader (core_config.go), EVE SSO auth/sessions/JWT verification (auth.go), account linking and the sign-up policy (auth_links.go, auth_signup.go), token refresh and encryption at rest (auth_refresh.go, auth_tokencrypt.go), cookie, header and cross-site protections (core_httpsec.go), the application struct and router (core_app.go), page handlers and view models (core_pages.go, char_assets.go, char_skills.go, corp_overview.go, market.go, sync.go, char_pages.go, char_killmails.go, intel.go), the background worker (worker.go runs the cycle; each *_worker.go file is the fetching behind one group of pages, and worker_name_harvest.go collects the names a cycle has to resolve), what pages and the worker both read (core_snapshots.go, market_book.go), the SDE static-data importer (sde.go), static assets and their caching (core_static.go), the health check (core_health.go), and the maintenance modes that need the application (core_maintenance.go: -refresh and -seed-demo).

It is one Go package, and a file's name starts with the part of the app it belongs to, so a directory listing groups them. A test file sits beside the code it tests with the same prefix.

Prefix What is in it
core_ the application itself: start-up, config, routing, page rendering, security headers, static files, health, maintenance
auth EVE sign-in, sign-up policy, linking characters, token refresh and encryption
ui_ navigation state and the tests that pin layout and styling
module_, modules_ the module registry: which modules a build has (modules_enabled.go, modules_core_only.go), which an account has by the scopes it granted, and the module.Deps core hands them
home_ the home page: widgets, briefing, net worth
char_ pages about one character: sheet, skills, assets, fittings, killmails, industry
economy_ wallet, orders, contracts
planets_ planetary industry
comms_ mail, calendar, contacts
profit_ the profit pages: per-item trading and per-blueprint industry profit and loss, and their charts
truevalue true values: the bottom-up price for manufacturable items and the learned price for contract-only ships
pub_ public contracts: the worker's mirror of ESI's public contracts and the confirmed sales taken from it
map_ the star map: systems, routes, character and intel layers
corp_ corporation pages and special-interest groups
ops_ the op calendar and attendance
market_ market pages, scanners, price guide, restock
items_ the item database
intel_ wars, incursions, pilots, corporations, alliances, places
battle_ battle reports: fights posted by Axon, joined to their killmails, with findings and a timeline
structures_ structures
search_ search
stats_ the Admin analytics recorder and its charts
fetch_ per-character ESI fetch policy: refusals, gates, and the freshness each page shows
sde the static-data importer
sync the Sync page
notify_ notifications and browser push
worker_ the background worker: the cycle, tiers, lanes, timing, name warm-up

A *_worker.go file under another prefix is the fetching behind that group of pages. Beside the Go files:

  • internal/app/templates/: embedded html/templates (base.html layout)
  • internal/app/static/: embedded assets served at /static/: the scripts, the stylesheets, and the three default wallpaper families (bg, bg-calm, bg-calm-muted). Scheme wallpapers and landing videos come from the asset CDN (ASSETS_PATH)
  • internal/app/jstest/: tests for the page scripts in static/
  • internal/app/seo/: robots.txt

Core imports the module contract, every module the build selects, and nearly all of foundation: store, db/sqlc, esi, logging, dotenv, pidfile, the engines, and the leaf packages webpush, ocikms (token-key wrapping), marketwire, scan, intelanalyze, intelchat and inteltag.

Modules: internal/app/<module>/

internal/app/module/ is the contract between core and the modules: the Module a package registers (its routes, nav entries, worker jobs, scopes and the modules it requires) and module.Deps, what core hands it at run time (the database, the ESI client, the current character's standing, and readers for what core owns). It imports only db/sqlc, esi, fitview and standing. internal/app/modulecatalog/ lists every module in nav order. Only cmd/modbuild imports it, so listing a module there compiles nothing into a build that did not choose it.

Every module imports app/module and logging; all but Intel import db/sqlc, and all but Public Fits, Groups and Discord import esi. The table lists what each needs beyond that. make modules prints the same list of requirements and scopes from the modules themselves.

Module id Package Requires module Foundation it uses ESI scopes it needs
buildplanner buildplanner/: Build Planner: its page, JSON payload and recipe source over the SDE buildplan, piplan, humanize, tags read_blueprints
fitting fitting/: Fitting: workbench, saved loadouts, import/export, save to the game, shopping list fit, fitview read_fittings, write_fittings
publicfits publicfits/: Public Fits: browser, fit pages, ratings and the jobs that keep them stored-only; the flag and storage stay core fitting (no esi)
skillplans skillplans/: Skill Plans: plan pages, plan-from-fit and plan editing skillplan, fitview, humanize
wallet wallet/: Wallet humanize read_character_wallet
mail mail/: Mail htmlsanitize, humanize read_mail, organize_mail, send_mail
calendar calendar/: Calendar humanize read_calendar_events, respond_calendar_events
contacts contacts/: Contacts read_contacts
scanner scanner/: Spread Scanner
tradefinder tradefinder/: Trade Finder
leaderboard leaderboard/: Top Stations
restock restock/: Restock Planner
market orders/: Market orders humanize read_character_orders, structure_markets
contracts contracts/: Contracts humanize read_character_contracts
appraise appraise/: Appraisal / Multi-Sell fitview
corpdata corpdata/: Corporation Data: member, wallet, order, asset and structure pages balancechart, standing, humanize
doctrines doctrines/: Doctrines and corporate loadouts fitting fitview, humanize
srp srp/: Ship Replacement standing, humanize
groups groups/: Groups standing, humanize (no esi)
communities communities/: Communities: groups of players outside the game's corporations, with public pages and joining without an account standing, humanize (no esi)
discord discord/: Discord: connecting an account, the bot's servers (roles by rule, members, private channels, ops announced) and direct-message notifications discord (the API client), standing (no esi)
swarm swarm/: Shared Cache: the signed, spot-checked sharing of public data between instances (see the wiki's Swarm Cache page) humanize
intel intel/: Intel: the killboard, the d-scan and intel parsers' pages, intel channels, the synthesized feed and workbench, pilot dossiers, and the public wars, incursions and faction-warfare pages. The parsers and synthesis live in core and the intelanalyze/intelchat packages; the module is their pages humanize (no db/sqlc)
piplanner piplanner/: PI Planner: colony chain layouts over the SDE, beside the core colonies pages piplan
tradeideas tradeideas/: Trade Ideas: the page and the stored model answers the worker refreshes ideas

Scopes are shortened (read_blueprints is esi-characters.read_blueprints.v1). A module also lists scopes it can use but does not need, and works without them; make modules shows those as "enhances".

Foundation: internal/

Core imports all of these except the update packages selfupdate and releasesig, which only the entry points use. The "Imports" column is the package's own internal imports; a dash means it uses the standard library and third-party packages only.

Data and ESI

Package What it is Imports
internal/store/ the database: opens PostgreSQL through a pgx pool, sizes it from DB_MAX_CONNS, and brings the schema up to date at startup (store.go, schema.go). The schema itself is the numbered steps in internal/store/schema_pg/, which are also sqlc's input none
internal/db/query/ hand-written queries (sqlc input)
internal/db/sqlc/ sqlc-generated pgx code (do not edit) none
internal/esi/ the ESI client: HTTP layer, per-character snapshot cache, and the two-tier type/group/place name resolution (network tier + cache-only render tier). Never imports internal/app; access tokens are injected via a callback db/sqlc, logging
internal/marketwire/ the market API's wire format, version 1: the JSON shapes /api/market/v1 answers with, kept apart so the format is one versioned contract none

Engines (pure arithmetic over what the caller supplies)

Package What it is Imports
internal/fit/ the fitting simulator's stat engine: the dogma arithmetic that turns a ship, its modules, skills and charges into the fit's statistics. Pure over the static data it loads db/sqlc
internal/fitview/ the fit foundation: the fit document, EFT, slot families and the simulation view, read by core and the fitting modules fit, db/sqlc, esi, logging
internal/skillplan/ skill-plan arithmetic: SP per level, training speed, ordering targets with their prerequisites, the remap advisor. Pure; the skill pages supply the skill graph none
internal/buildplan/ the industry build planner's engine: the tree of everything a product needs, the manufacturing formulae, what is already held, and the price of the rest. Pure esi
internal/piplan/ the Planetary Interaction planner engine: the R0 → P4 chain with the game's schematics, yields, facility power/CPU and customs tax. Pure; callers supply prices none
internal/markethistory/ figures and the SVG chart computed from a type's stored daily price history. Pure db/sqlc, esi
internal/balancechart/ the balance-over-time chart builder shared by the wallet pages, the home net-worth card and the corporation wallets markethistory, db/sqlc, esi
internal/standing/ the corporation/alliance standing model: who owns, directs, belongs to or holds a role in a corporation or alliance, and the rule kinds asked against that. Types and checks only; core works a standing out from stored data and modules read it through module.Deps none
internal/ideas/ the stored trade-ideas answer, parsed into strategy groups, and the readers that load it. The Trade Ideas module writes it; core's home widget reads it db/sqlc

Intel parsing

Package What it is Imports
internal/scan/ reads the text players copy out of the EVE client (d-scan, local, fleet composition, probe scanner) into rows. Pure; core enriches and stores them none
internal/intelchat/ reads lines copied out of an intel chat channel into reports: who, when, which system, and what none
internal/intelanalyze/ works out what an intel report says: pilots, ships, gate, the kind of report, and whether the pilots are friendly. Pure; names come from the caller's dictionaries none
internal/inteltag/ the intel classifier: a small sequence tagger (averaged structured perceptron) that labels each word of a report intelanalyze

Helpers

Package What it is Imports
internal/htmlsanitize/ makes text written by other players safe to show inside a page (mail, pilot bios, descriptions) none
internal/card/ draws the 1200x630 summary image a shared link shows none
internal/eveimg/ builds addresses on CCP's image server none
internal/gamelog/ reads EVE game logs for battle reports none
internal/itemsheet/ turns a type's static data into the item sheet db/sqlc
internal/memsize/ estimates how much memory a Go value holds none
internal/netguard/ keeps long-lived outbound connections from hanging on a dead path none
internal/tradefees/ the shared broker fee and sales tax math none
internal/humanize/, internal/tags/ small wording and tag helpers shared by core and modules tags: db/sqlc
internal/logging/ gives every log line a level; LOG_LEVEL decides which are written none
internal/webpush/ sends a browser push message: Web Push encryption and the VAPID signature, standard library only none
internal/discord/ the little of Discord's HTTP API that EveSynapse uses, standard library only. The Discord module is its only caller none
internal/ocikms/ a minimal OCI Key Management client for Encrypt/Decrypt, so the token encryption key can be wrapped by a key held in an OCI Vault ("Keeping the key off the machine" below) none

Install and update

Package What it is Imports
internal/selfupdate/ evesynapse -update: the release channel, checking a release's signature, downloading, verifying and swapping in a new build, and handing over to the running server. It is told the running version and knows nothing else about the application releasesig, pidfile, dotenv
internal/releasesig/ the signature on a release: how an update manifest is signed and how the updater checks one, plus trusted_keys.pem, the public keys compiled into every build ("Release signing" below) none
internal/pidfile/ the server's pidfile: written at start-up, read by -update to restart the server and by -refresh to refuse while it is running (pidfile/pidfiletest is test support) logging
internal/dotenv/ the .env loader the server and the updater both use none

Tests and dev-only code

  • internal/pgtest/: test-only embedded PostgreSQL 16 provisioning (a fresh database per test; go test ./... needs no external database). A package whose tests use it needs a TestMain that calls pgtest.TestMain, which stops the server when the tests finish; without one pgtest refuses to start a server
  • internal/apptest/: shared fixtures for the black-box page tests in internal/app/tests/: the counting stub transport, fixture IDs, page and assertion helpers, and seeders over exported sqlc queries (imports app, db/sqlc, pgtest). White-box tests stay in package app beside the code
  • internal/app/core_testrig.go: TestRig, the one exported seam those tests build a fixture application through. It takes a DSN and returns errors rather than a *testing.T, so the server links no test code; internal/apptest wraps it with pgtest
  • internal/devtools/: dev-only routes (/dev-login), imported solely by cmd/evesynapse-dev

Outside the Go module

  • android/: the Android app (see "The Android app" on the wiki's Notifications page)
  • deploy/: the install script (setup.sh) and the systemd unit
  • ci-assets/: the fonts, wallpapers, screenshots and star tile, base64-encoded; make assets decodes them into internal/app/static/
  • sqlc.yaml, Makefile, FRONTEND.md: sqlc's configuration, the common commands, and the front-end conventions