How teby81/app_go works
Purpose and Entry Point
EmailLeakChecker is a Go HTTP API plus static browser UI for checking whether an email appears in known breaches. The process starts in cmd/api/main.go, which loads configuration, initializes logging, MySQL/GORM, the configured breach-provider client, services, and Gin routes.
HTTP/API and UI Boundary
Gin handlers expose the application boundary:
• POST /api/v1/check validates an email and returns its breach result.
• GET /api/v1/checks returns persisted check history.
• GET /health checks application/database availability.
• / serves the static UI.
Routing and request handling reside in internal/handler/router.go, internal/handler/check.go, and internal/handler/history.go. The browser is a thin client in web/index.html and web/assets/app.js; it calls the same API and contains no breach logic.
Check Orchestration Service
internal/service/check.go owns the primary workflow: receive a normalized email, invoke the selected provider, translate provider results into domain models, and persist the check/result graph before returning the response. This layer separates HTTP concerns from persistence and external API semantics. Email-format validation is performed at the inbound boundary through internal/validation/email.go.
Pluggable Breach Data Providers
The client layer abstracts external breach sources:
• HIBP v3 client, including API-key/user-agent usage, rate limiting, and retry behavior: internal/client/hibp.go.
• Free XposedOrNot provider: internal/client/xposed.go.
• Deterministic offline development/test provider: internal/client/mock.go.
Provider selection is configuration-driven, allowing production integrations to be replaced without changing handlers or service flow.
Persistence Model and Database Boundary
MySQL 8 is accessed exclusively through the repository layer, principally internal/repository/mysql.go. The normalized model captures unique emails, individual check events, deduplicated breach records, and check-to-breach result relations; domain structures are in internal/model/models.go. Schema initialization is defined in database/migrations/001_init.sql, while application startup also runs GORM migration synchronization.
Runtime Configuration, Logging, and Privacy
internal/config/config.go loads environment-based settings for server, MySQL, provider selection, API credentials/URLs, rate limits, and logging. Structured logging is centralized in pkg/logger/logger.go; the design avoids logging complete email addresses. Secrets are supplied from environment variables rather than source control.
Deployment Infrastructure
The service runs as a Go process locally or as a container using Dockerfile. docker-compose.yml provisions the API with MySQL and startup health dependencies; render.yaml supports Render deployment. External runtime dependencies are MySQL and, except in mock mode, HIBP or XposedOrNot HTTP APIs.
Main entry points: main.go API bootstrap · router.go Gin router · mysql.go MySQL repository · check.go Check orchestration
Components 19
API & UI
- Gin router · Serves API endpoints, health, and static UI.
internal/handler/router.go - Check endpoint · Handles POST /api/v1/check.
internal/handler/check.go - History endpoint · Handles GET /api/v1/checks.
internal/handler/history.go - Email validation
internal/validation/email.go - Browser UI · Thin client calling the same API.
web/index.html
Check Core
- Check orchestration · Queries a provider, maps results, and persists the check graph.
internal/service/check.go
Breach Providers
- Provider abstraction · Configuration selects a breach source without changing service flow.
- HIBP v3 client · Applies API credentials, rate limiting, and retries.
internal/client/hibp.go - XposedOrNot client
internal/client/xposed.go - Mock provider · Deterministic development and test source.
internal/client/mock.go - Breach APIs · HIBP or XposedOrNot outside mock mode.
Persistence
- MySQL repository · Exclusive database access boundary.
internal/repository/mysql.go - Check result model · Emails, checks, deduplicated breaches, and result relations.
internal/model/models.go - MySQL 8
- Initial schema
database/migrations/001_init.sql
Runtime
- API bootstrap · Initializes configuration, dependencies, and routes.
cmd/api/main.go - Environment config
internal/config/config.go - Structured logger · Avoids logging complete email addresses.
pkg/logger/logger.go - Container deployment · Docker Compose provisions API and MySQL; Render is also supported.
docker-compose.yml
Connections 25
- API bootstrap → Environment config: loads
- API bootstrap → Structured logger: initializes
- API bootstrap → Gin router: registers
- API bootstrap → Provider abstraction: selects from config
- API bootstrap → MySQL repository: initializes GORM
- Gin router → Check endpoint: POST /api/v1/check
- Gin router → History endpoint: GET /api/v1/checks
- Gin router → Browser UI: serves /
- Browser UI → Gin router: calls API
- Check endpoint → Email validation: validates
- Check endpoint → Check orchestration: submits email
- History endpoint → MySQL repository: reads history
- Check orchestration → Provider abstraction: queries
- Check orchestration → MySQL repository: persists results
- Check orchestration → Check result model: maps to
- Provider abstraction → HIBP v3 client: implementation
- Provider abstraction → XposedOrNot client: implementation
- Provider abstraction → Mock provider: implementation
- HIBP v3 client → Breach APIs: HTTP
- XposedOrNot client → Breach APIs: HTTP
- MySQL repository → Check result model: stores
- MySQL repository → MySQL 8: reads and writes
- Initial schema → MySQL 8: initializes
- Container deployment → API bootstrap: runs API
- Container deployment → MySQL 8: provisions