How midaug/dream-lottery works
1. Repository shape
- This repo is split into two main runtime parts: a Java Spring Boot web application in dream-lottery-web/ and a Python data spider in the repo root (spider_ssq.py, spider_data/).
- There is also a set of prebuilt/static frontend assets under both dream-lottery-web/src/main/resources/static/ and the top-level html/ folder, suggesting the UI can be served by the Spring app and also exists as standalone static pages.
2. Primary product boundary
- The application is a lottery information service for 双色球 (SSQ).
- Its two core user-facing functions are:
- querying the latest lottery draw results
- uploading a ticket/photo for OCR-based winnings checking
- The README explicitly exposes the main page at /ssq/index.
3. Spring Boot backend
- DreamLotteryWebApplication.java is the application entry point.
- controller/ contains the HTTP boundary:
- IndexController serves the main page/view
- SSQController likely exposes SSQ-related APIs and OCR endpoints
- service/SSQService.java is the main business layer, separating request handling from lottery/OCR logic.
4. Data model and transfer objects
- dto/ contains the request/response shapes used across the controller-service boundary:
- SSQDto for lottery data
- SSQImgOcrDto for OCR/image-related results
- WebResult for standardized web responses
- This indicates the backend is structured as a typical controller → service → utility pipeline, with DTOs insulating the HTTP layer from internal processing.
5. Lottery data source pipeline
- The README documents spider_data/ssq.txt as the lottery history source, with fixed comma-separated fields:
- issue number, six red balls, blue ball, prize amounts, and draw date
- The Python spider (spider_ssq.py) and the generated data files (spider_data/ssq.js, spider_data/ssq.txt) form an ingestion boundary outside the Java app.
- In the architecture, the web service likely reads from these local data artifacts rather than querying a remote API at request time.
6. OCR subsystem
- OCR is a separate concern from lottery data lookup.
- The README says OCR uses the Baidu OCR SDK and requires three environment variables:
- BAIDU_OCR_APPID
- BAIDU_OCR_APPKEY
- BAIDU_OCR_SECRET
- Utility classes in utils/ reflect this split:
- BaiduOcrSdkUtil for Baidu integration
- PaddleOcrUtil as an alternative OCR path
- PicUtils, FileUtil for image/file preprocessing and handling
- SSQUtil for lottery-specific parsing or computation
- This makes OCR a service-adapter style subsystem, not part of the core draw-data pipeline.
7. Frontend delivery
- The app includes server-rendered templates in src/main/resources/templates/index.html plus static CSS/JS/assets under src/main/resources/static/.
- Bootstrap is bundled locally, so the UI does not depend on a CDN.
- The top-level html/ directory mirrors the front-end asset structure and includes tesseract.js, implying there is also a browser-side OCR experiment or a standalone static demo.
8. Containerization and runtime packaging
- dream-lottery-web/Dockerfile packages the Spring Boot service as a container.
- docker-compose.yml supports local orchestration of the app.
- paddleocr-docker-compose.yml indicates an optional companion OCR service/runtime for PaddleOCR.
- The README’s docker run example shows the deployment model is environment-variable driven, with OCR credentials injected at runtime.
9. CI/CD and automation
- .github/workflows/docker_build_push.yml suggests automated container image build and push.
- .github/workflows/start_spider_ssq.yml likely automates the spider/data refresh pipeline.
- .github/workflows/sync2gitee.yml indicates repository mirroring or synchronization to Gitee.
- These workflows matter architecturally because data refresh and image publication are part of the repo’s operational lifecycle.
10. Logging and configuration
- application.properties and logback-spring.xml define runtime configuration and logging for the Spring app.
- This confirms the web app is the operational center, with externalized settings for OCR credentials and service behavior.
11. Main data flow for the lottery lookup path
- User opens the SSQ page in the Spring-served UI.
- UI calls backend endpoints in SSQController.
- SSQService reads or interprets local SSQ data produced by the spider.
- DTOs are returned to the browser for display.
- The spider/update path is separate from the request path, so lookup remains local and fast.
12. Main data flow for OCR/winning check
- User uploads or captures an image in the UI.
- Backend receives the image and hands it to OCR utilities.
- Depending on configuration, OCR may call Baidu OCR or another local OCR component.
- OCR output is parsed into SSQ-related data and returned as a web result.
13. Key architectural boundaries to show in a diagram
- Browser/UI vs Spring Boot backend
- Backend business logic vs OCR provider integration
- Backend vs Python spider/data refresh process
- Application runtime vs container/CI automation
- Local static assets vs dynamic server endpoints
14. What is most important to emphasize
- This is not a generic CRUD web app; it is a specialized lottery assistant built around two data sources:
- historical SSQ draw data maintained by a spider
- OCR-driven ticket/image recognition
- The architecture is therefore a combination of local data ingestion, web presentation, and external OCR service integration.
Main entry points: SSQController.java SSQ API · SSQService.java SSQ service · DreamLotteryWebApplication.java Web app · IndexController.java Index page
Components 16
Spring app
Primary Java web application for SSQ browsing and OCR workflows.
- Web app · Main lottery web service entrypoint.
dream-lottery-web/src/main/java/com/midaug/dream/lottery/DreamLotteryWebApplication.java - Config · Application wiring and bean configuration.
dream-lottery-web/src/main/java/com/midaug/dream/lottery/config/BeanConfig.java - Index page · Serves the main SSQ page and view routing.
dream-lottery-web/src/main/java/com/midaug/dream/lottery/controller/IndexController.java - SSQ API · HTTP boundary for lottery lookup and OCR-related requests.
dream-lottery-web/src/main/java/com/midaug/dream/lottery/controller/SSQController.java - SSQ service · Core lottery and ticket-checking logic.
dream-lottery-web/src/main/java/com/midaug/dream/lottery/service/SSQService.java - DTOs · Request/response shapes for lottery data, OCR results, and web responses.
dream-lottery-web/src/main/java/com/midaug/dream/lottery/dto - Baidu OCR · Adapter to Baidu OCR SDK using runtime credentials.
dream-lottery-web/src/main/java/com/midaug/dream/lottery/utils/BaiduOcrSdkUtil.java - Paddle OCR · Alternative OCR path, likely local or containerized.
dream-lottery-web/src/main/java/com/midaug/dream/lottery/utils/PaddleOcrUtil.java - Image utils · Image and file handling used before OCR.
dream-lottery-web/src/main/java/com/midaug/dream/lottery/utils/PicUtils.java - SSQ utils · Lottery-specific parsing and calculation helpers.
dream-lottery-web/src/main/java/com/midaug/dream/lottery/utils/SSQUtil.java
Data pipeline
Python spider and generated local lottery history artifacts.
- Spider · Fetches and refreshes SSQ history data.
spider_ssq.py - SSQ history · Generated lottery history and script artifacts used by the web app.
spider_data/ssq.txt
Delivery
Container, compose, and CI automation around build and refresh.
- Containers · Dockerfiles and compose files for app and OCR runtime.
dream-lottery-web/Dockerfile - CI workflows · GitHub Actions for image build/push, spider refresh, and repo sync.
.github/workflows/docker_build_push.yml
UI assets
Server-rendered and standalone static pages and assets.
- Static UI · Bundled Bootstrap, CSS, and standalone static pages.
html/index.html - View template · Spring-served HTML template for the main page.
dream-lottery-web/src/main/resources/templates/index.html
Connections 18
- Web app → Config: wires · Bootstraps application configuration.
- Web app → Index page: hosts · Registers the page controller.
- Web app → SSQ API: hosts · Registers lottery/OCR endpoints.
- SSQ API → SSQ service: delegates · Controller passes business requests to service.
- SSQ service → DTOs: returns · Uses DTOs for structured results.
- SSQ API → Baidu OCR: calls · Invokes Baidu OCR for image-based checking.
- SSQ API → Paddle OCR: calls · Can route OCR to alternate OCR engine.
- Baidu OCR → Image utils: preprocess · OCR flow depends on image/file preparation.
- Paddle OCR → Image utils: preprocess · Local OCR path uses image preprocessing.
- SSQ service → SSQ utils: uses · Applies lottery-specific parsing and computation.
- SSQ service → SSQ history: reads · Uses locally generated SSQ draw data.
- Spider → SSQ history: generates · Refreshes the local SSQ dataset.
- Index page → View template: serves · Renders the main page view.
- Index page → Static UI: uses · Serves shared static frontend assets.
- View template → Static UI: loads · Template depends on local CSS/JS assets.
- Containers → Web app: packages · Builds and runs the Spring Boot service.
- CI workflows → Containers: builds · Automates container image publication.
- CI workflows → Spider: refreshes · Automates data update pipeline.