# midaug/dream-lottery architecture

> Architecture diagram of the GitHub repository midaug/dream-lottery, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-04-16). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/midaug/dream-lottery
- Repository: https://github.com/midaug/dream-lottery

## Overview

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: [`dream-lottery-web/src/main/java/com/midaug/dream/lottery/controller/SSQController.java`](https://github.com/midaug/dream-lottery/blob/main/dream-lottery-web/src/main/java/com/midaug/dream/lottery/controller/SSQController.java) (SSQ API), [`dream-lottery-web/src/main/java/com/midaug/dream/lottery/service/SSQService.java`](https://github.com/midaug/dream-lottery/blob/main/dream-lottery-web/src/main/java/com/midaug/dream/lottery/service/SSQService.java) (SSQ service), [`dream-lottery-web/src/main/java/com/midaug/dream/lottery/DreamLotteryWebApplication.java`](https://github.com/midaug/dream-lottery/blob/main/dream-lottery-web/src/main/java/com/midaug/dream/lottery/DreamLotteryWebApplication.java) (Web app), [`dream-lottery-web/src/main/java/com/midaug/dream/lottery/controller/IndexController.java`](https://github.com/midaug/dream-lottery/blob/main/dream-lottery-web/src/main/java/com/midaug/dream/lottery/controller/IndexController.java) (Index page)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_spring["Spring app"]
  node_app["Web app<br/>Spring Boot"]
  node_webcfg["Config<br/>[BeanConfig.java]"]
  node_indexctl["Index page<br/>MVC controller"]
  node_ssqctl["SSQ API<br/>Web controller<br/>[SSQController.java]"]
  node_ssqsvc["SSQ service<br/>Business service<br/>[SSQService.java]"]
  node_dto["DTOs<br/>Transfer objects"]
  node_ocrsdk["Baidu OCR<br/>External adapter"]
  node_paddleocr["Paddle OCR<br/>OCR utility<br/>[PaddleOcrUtil.java]"]
  node_imgutil["Image utils<br/>Preprocess utility<br/>[PicUtils.java]"]
  node_ssqutil["SSQ utils<br/>Domain utility<br/>[SSQUtil.java]"]
end

subgraph group_data["Data pipeline"]
  node_spider["Spider<br/>Python scraper<br/>[spider_ssq.py]"]
  node_history[("SSQ history<br/>Local dataset<br/>[ssq.txt]")]
end

subgraph group_delivery["Delivery"]
  node_docker["Containers<br/>Packaging"]
  node_ci["CI workflows<br/>Automation"]
end

subgraph group_frontend["UI assets"]
  node_staticui["Static UI<br/>Frontend assets<br/>[index.html]"]
  node_template["View template<br/>Server template<br/>[index.html]"]
end

node_app -->|"wires"| node_webcfg
node_app -->|"hosts"| node_indexctl
node_app -->|"hosts"| node_ssqctl
node_ssqctl -->|"delegates"| node_ssqsvc
node_ssqsvc -->|"returns"| node_dto
node_ssqctl -->|"calls"| node_ocrsdk
node_ssqctl -->|"calls"| node_paddleocr
node_ocrsdk -->|"preprocess"| node_imgutil
node_paddleocr -->|"preprocess"| node_imgutil
node_ssqsvc -->|"uses"| node_ssqutil
node_ssqsvc -->|"reads"| node_history
node_spider -->|"generates"| node_history
node_indexctl -->|"serves"| node_template
node_indexctl -->|"uses"| node_staticui
node_template -->|"loads"| node_staticui
node_docker -->|"packages"| node_app
node_ci -->|"builds"| node_docker
node_ci -->|"refreshes"| node_spider

click node_app "https://github.com/midaug/dream-lottery/blob/main/dream-lottery-web/src/main/java/com/midaug/dream/lottery/DreamLotteryWebApplication.java"
click node_webcfg "https://github.com/midaug/dream-lottery/blob/main/dream-lottery-web/src/main/java/com/midaug/dream/lottery/config/BeanConfig.java"
click node_indexctl "https://github.com/midaug/dream-lottery/blob/main/dream-lottery-web/src/main/java/com/midaug/dream/lottery/controller/IndexController.java"
click node_ssqctl "https://github.com/midaug/dream-lottery/blob/main/dream-lottery-web/src/main/java/com/midaug/dream/lottery/controller/SSQController.java"
click node_ssqsvc "https://github.com/midaug/dream-lottery/blob/main/dream-lottery-web/src/main/java/com/midaug/dream/lottery/service/SSQService.java"
click node_dto "https://github.com/midaug/dream-lottery/tree/main/dream-lottery-web/src/main/java/com/midaug/dream/lottery/dto"
click node_ocrsdk "https://github.com/midaug/dream-lottery/blob/main/dream-lottery-web/src/main/java/com/midaug/dream/lottery/utils/BaiduOcrSdkUtil.java"
click node_paddleocr "https://github.com/midaug/dream-lottery/blob/main/dream-lottery-web/src/main/java/com/midaug/dream/lottery/utils/PaddleOcrUtil.java"
click node_imgutil "https://github.com/midaug/dream-lottery/blob/main/dream-lottery-web/src/main/java/com/midaug/dream/lottery/utils/PicUtils.java"
click node_ssqutil "https://github.com/midaug/dream-lottery/blob/main/dream-lottery-web/src/main/java/com/midaug/dream/lottery/utils/SSQUtil.java"
click node_spider "https://github.com/midaug/dream-lottery/blob/main/spider_ssq.py"
click node_history "https://github.com/midaug/dream-lottery/blob/main/spider_data/ssq.txt"
click node_staticui "https://github.com/midaug/dream-lottery/blob/main/html/index.html"
click node_template "https://github.com/midaug/dream-lottery/blob/main/dream-lottery-web/src/main/resources/templates/index.html"
click node_docker "https://github.com/midaug/dream-lottery/tree/main/dream-lottery-web/Dockerfile"
click node_ci "https://github.com/midaug/dream-lottery/blob/main/.github/workflows/docker_build_push.yml"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_app,node_webcfg,node_indexctl,node_ssqctl,node_ssqsvc,node_dto,node_ocrsdk,node_paddleocr,node_imgutil,node_ssqutil toneBlue
class node_spider,node_history toneAmber
class node_docker,node_ci toneMint
class node_staticui,node_template toneRose
```

## Components

### Spring app

Primary Java web application for SSQ browsing and OCR workflows.

- [Web app](https://github.com/midaug/dream-lottery/blob/main/dream-lottery-web/src/main/java/com/midaug/dream/lottery/DreamLotteryWebApplication.java): Spring Boot · Main lottery web service entrypoint. · `dream-lottery-web/src/main/java/com/midaug/dream/lottery/DreamLotteryWebApplication.java`
- [Config](https://github.com/midaug/dream-lottery/blob/main/dream-lottery-web/src/main/java/com/midaug/dream/lottery/config/BeanConfig.java): Spring config · Application wiring and bean configuration. · `dream-lottery-web/src/main/java/com/midaug/dream/lottery/config/BeanConfig.java`
- [Index page](https://github.com/midaug/dream-lottery/blob/main/dream-lottery-web/src/main/java/com/midaug/dream/lottery/controller/IndexController.java): MVC controller · Serves the main SSQ page and view routing. · `dream-lottery-web/src/main/java/com/midaug/dream/lottery/controller/IndexController.java`
- [SSQ API](https://github.com/midaug/dream-lottery/blob/main/dream-lottery-web/src/main/java/com/midaug/dream/lottery/controller/SSQController.java): Web controller · HTTP boundary for lottery lookup and OCR-related requests. · `dream-lottery-web/src/main/java/com/midaug/dream/lottery/controller/SSQController.java`
- [SSQ service](https://github.com/midaug/dream-lottery/blob/main/dream-lottery-web/src/main/java/com/midaug/dream/lottery/service/SSQService.java): Business service · Core lottery and ticket-checking logic. · `dream-lottery-web/src/main/java/com/midaug/dream/lottery/service/SSQService.java`
- [DTOs](https://github.com/midaug/dream-lottery/tree/main/dream-lottery-web/src/main/java/com/midaug/dream/lottery/dto): Transfer objects · Request/response shapes for lottery data, OCR results, and web responses. · `dream-lottery-web/src/main/java/com/midaug/dream/lottery/dto`
- [Baidu OCR](https://github.com/midaug/dream-lottery/blob/main/dream-lottery-web/src/main/java/com/midaug/dream/lottery/utils/BaiduOcrSdkUtil.java): External adapter · Adapter to Baidu OCR SDK using runtime credentials. · `dream-lottery-web/src/main/java/com/midaug/dream/lottery/utils/BaiduOcrSdkUtil.java`
- [Paddle OCR](https://github.com/midaug/dream-lottery/blob/main/dream-lottery-web/src/main/java/com/midaug/dream/lottery/utils/PaddleOcrUtil.java): OCR utility · Alternative OCR path, likely local or containerized. · `dream-lottery-web/src/main/java/com/midaug/dream/lottery/utils/PaddleOcrUtil.java`
- [Image utils](https://github.com/midaug/dream-lottery/blob/main/dream-lottery-web/src/main/java/com/midaug/dream/lottery/utils/PicUtils.java): Preprocess utility · Image and file handling used before OCR. · `dream-lottery-web/src/main/java/com/midaug/dream/lottery/utils/PicUtils.java`
- [SSQ utils](https://github.com/midaug/dream-lottery/blob/main/dream-lottery-web/src/main/java/com/midaug/dream/lottery/utils/SSQUtil.java): Domain utility · 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](https://github.com/midaug/dream-lottery/blob/main/spider_ssq.py): Python scraper · Fetches and refreshes SSQ history data. · `spider_ssq.py`
- [SSQ history](https://github.com/midaug/dream-lottery/blob/main/spider_data/ssq.txt): Local dataset · 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](https://github.com/midaug/dream-lottery/tree/main/dream-lottery-web/Dockerfile): Packaging · Dockerfiles and compose files for app and OCR runtime. · `dream-lottery-web/Dockerfile`
- [CI workflows](https://github.com/midaug/dream-lottery/blob/main/.github/workflows/docker_build_push.yml): Automation · 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](https://github.com/midaug/dream-lottery/blob/main/html/index.html): Frontend assets · Bundled Bootstrap, CSS, and standalone static pages. · `html/index.html`
- [View template](https://github.com/midaug/dream-lottery/blob/main/dream-lottery-web/src/main/resources/templates/index.html): Server template · Spring-served HTML template for the main page. · `dream-lottery-web/src/main/resources/templates/index.html`

## Connections

- 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.
