A Go backend and reverse proxy for smogonstats.eu.cc.
It serves Smogon usage stats endpoints, caches queries using BigCache, stores data in PostgreSQL, and generates dynamic sitemaps.
- API Engine: Built in Go using Chi router and pgx PostgreSQL driver.
- Data Storage: PostgreSQL database (
smogon_stats) holding usage, leads, format stats, metagame, and viability data. - Caching: In-memory caching with BigCache to reduce database load.
- Endpoints: Exposes v3 API routes (
/api/v3/init,/api/v3/stats,/api/v3/details,/api/v3/trend,/api/v3/format-stats,/api/v3/metagame), dynamic/sitemap.xml, and reverse-proxy capabilities. - Scrapers and Populators: Go binaries that fetch and parse raw text files from Smogon directly into PostgreSQL.
- Go 1.20 or higher
- PostgreSQL running locally or via
DATABASE_URL ADMIN_TOKENenvironment variable for securing internal endpoints and bypassing rate limitsCLOUDFLARE_HOOK_URLenvironment variable for triggering frontend deployments
Compile all 8 binaries (API server, cache tools, and scrapers):
make buildRun the API server locally:
make runThe server listens on port 9000 by default. Override it with the PORT environment variable.
The cache state is automatically backed up to cache-backup.bin every 24 hours.
Build and run all populator scripts to scrape and import Smogon statistics into PostgreSQL:
make populateIncluded binaries:
populate-usage-stats-binpopulate-format-stats-binpopulate-leads-binpopulate-metagame-binpopulate-viability-binpreload-dbcache-bin(Hydrates cache directly from database)warmup-bin(Warms cache via concurrent HTTP requests)
To run the proxy continuously on Linux:
sudo cp proxy-api.service /etc/systemd/system/
sudo systemctl daemon-reload
sudo systemctl enable proxy-api
sudo systemctl start proxy-apiCheck service status or logs:
sudo systemctl status proxy-api
sudo journalctl -u proxy-api -f- Go: Standard library and concurrency primitives.
- Smogon: Raw competitive Pokémon usage statistics.
- pgx: PostgreSQL driver.
- BigCache: Concurrent in-memory cache.
This project is licensed under the MIT License.