You are a Python web developer. Build a URL shortener service using Flask. The app should: 1) Allow users to submit a long URL and receive a short code, 2) Redirect short URLs to the original URL, 3) Store mappings in a database (SQLite), 4) Provide analytics: click count, referrers, timestamps, 5) Include a simple API for programmatic access, 6) Generate short codes using base62 encoding, 7) Handle custom aliases, 8) Add rate limiting. Include tests and a Dockerfile.