How hugohu0224/sportshot works
Project Type and Purpose
• Sportshot is a full-stack sports odds scanning tool composed of three primary services:
1. A crawler that periodically fetches sports betting odds (currently basketball) from an external API.
2. A gRPC event server that provides filtered, historical odds data to clients, using etcd for service discovery.
3. A web server (with frontend UI) that handles user authentication, exposes RESTful APIs, and acts as a gRPC client to retrieve odds.
• Data persistence layers include MongoDB (odds storage) and MySQL (user auth), plus etcd for gRPC naming/discovery.
File-Structure Analysis
• Top-level commands under cmd/:
• crawler/main.go – starts the crawler worker
• grpcserver/events/main.go – starts the gRPC event server
• webserver/main.go – starts the web server + UI
• Internal packages in internal/ map each service:
• internal/crawler – crawling logic & interfaces
• internal/grpcserver/events – gRPC handler, persistence layer
• internal/webserver – HTTP API endpoints, JWT auth, routing, templating, static assets
• Shared code in pkg/:
• pkg/utils/db – adapters for MongoDB, MySQL, etcd (viper config)
• pkg/utils/proto – protobuf definitions & generated gRPC stubs
• pkg/utils/models – domain models (Event, User, Login)
• Infrastructure config:
• docker-compose.yaml – orchestrates MongoDB, MySQL, etcd, and the three Go services
• config.yaml – application settings (crawler interval, DB URIs)
• scripts/entrypoint.sh, Dockerfile – container bootstrapping
Key Architectural Patterns
• Micro-service style: Three independent Go binaries, each with their own internal layers.
• Dependency injection via interfaces in internal/crawler/interfaces.go.
• API gateway / BFF: Web server stands between UI and gRPC service.
• Service discovery & load balancing: gRPC server registers with etcd; web server uses etcd client to locate instances.
• Separation of concerns:
• Crawling → data ingestion
• gRPC server → data filtering & access
• Web server → user management & UI
• Components:
A. External API (BetsAPI)
B. Crawler Service (cmd/crawler)
C. MongoDB (odds storage)
D. gRPC Event Server (cmd/grpcserver)
E. etcd Cluster (service registry)
F. MySQL (user credentials)
G. Web Server + UI (cmd/webserver)
H. Browser/UI Client
• Interactions:
1. Crawler polls External API → writes to MongoDB.
2. gRPC Server reads from MongoDB → serves filtered odds via gRPC.
3. gRPC Server registers its endpoint(s) in etcd upon startup.
4. Web Server uses etcd client to discover gRPC Server addresses.
5. Web Server authenticates users against MySQL (via pkg/utils/db/mysql).
6. Authenticated Browser/UI → Web Server REST API → Web server calls gRPC to fetch odds → returns JSON/UI templates.
Final Checklist
• Clear, distinct labels for each service and datastore
• Annotations for key frameworks/libs (Go, gRPC, etcd, Viper, Gin/Chi or net/http insofar as applicable)