# esoto6/tip-of-the-day architecture

> Architecture diagram of the GitHub repository esoto6/tip-of-the-day, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-29). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/esoto6/tip-of-the-day
- Repository: https://github.com/esoto6/tip-of-the-day

## Overview

##### Project type and purpose
- This is a single-service Spring Boot web application with a minimal frontend (Thymeleaf templates) and a backend that:
- Generates daily “tip of the day” content by calling an external Ollama AI model
- Stores/retrieves tips in MongoDB
- Exposes HTTP endpoints for manual triggering and serves a home page

##### File structure
- Top-level config:
- .devcontainer/: Dockerfile + docker-compose for local dev (app, MongoDB, Ollama)
- pom.xml / Maven wrapper
- src/main/java/com/edwinsoto/tipoftheday:
- controller/: HomeController (serves templates), TipController (REST endpoints)
- service/: TipService (business logic), TipScheduler (scheduled midnight jobs)
- repository/: TipRepository (Spring Data MongoDB)
- record/Tip.java (domain model)
- src/main/resources:
- application.properties (DB/config)
- static/styles.css, templates/home.html

##### Key insights from README
- Deployment: Docker Compose spins up three containers (app, MongoDB, Ollama).
- Ollama container must have a pulled AI model (“codegemma”) for generating tips.
- Scheduled endpoints invoked at defined times after midnight; initial manual hits recommended.

##### Essential detail points
- DevContainer/Docker-Compose layer to show deployment topology
- Separate the scheduled task flow from the user-triggered flow
- Domain model briefly (Tip record stored in MongoDB)
- Don’t omit the Ollama container as a critical external dependency

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Deployment Layer
    subgraph "DevContainer / Docker Compose"
        direction TB
        DC["Docker Compose"]:::infra
        subgraph "App Container"
            direction TB
            TipApp["Spring Boot App"]:::backend
            subgraph "Web Layer"
                HomeController["HomeController"]:::backend
                TipController["TipController"]:::backend
            end
            subgraph "Service Layer"
                TipService["TipService"]:::backend
                TipScheduler["TipScheduler"]:::backend
            end
            subgraph "Data Layer"
                TipRepository["TipRepository"]:::backend
                Tip["Tip (Domain Model)"]:::backend
            end
            HomeController -->|serves templates| TipRepository
            TipController -->|calls| TipService
            TipService -->|calls AI| Ollama
            TipService -->|persists| TipRepository
            TipScheduler -->|scheduled calls| TipService
            TipRepository -->|stores/queries| Tip
        end
        MongoDB["MongoDB"]:::database
        Ollama["Ollama AI Container"]:::external
        DC -->|orchestrates| TipApp
        DC -->|orchestrates| MongoDB
        DC -->|orchestrates| Ollama
    end

    %% Resource Files
    subgraph "Resources"
        direction TB
        AppConfig["application.properties"]:::infra
        CSS["styles.css"]:::frontend
        HTML["home.html"]:::frontend
    end
    TipApp --> AppConfig
    TipApp --> CSS
    TipApp --> HTML

    %% External Actors
    User["User Browser"]:::frontend

    %% User-triggered Flow
    User -->|"GET /"| HomeController
    HomeController -->|query| TipRepository
    TipRepository -->|read/write| MongoDB
    MongoDB -->|result| TipRepository
    HomeController -->|render HTML| User

    User -->|"GET /ollama/{topic}"| TipController
    TipController -->|invoke| TipService
    TipService -->|REST call| Ollama
    Ollama -->|response| TipService
    TipService -->|save tip| TipRepository
    TipRepository -->|write| MongoDB
    MongoDB -->|ack| TipRepository
    TipController -->|JSON response| User

    %% Scheduled Flow
    TipScheduler -->|trigger| TipService
    TipService -->|generate tip| Ollama
    Ollama -->|response| TipService
    TipService -->|persist| TipRepository
    TipRepository -->|write| MongoDB

    %% Click Events
    click DC "https://github.com/esoto6/tip-of-the-day/blob/main/.devcontainer/docker-compose.yml"
    click TipApp "https://github.com/esoto6/tip-of-the-day/blob/main/src/main/java/com/edwinsoto/tipoftheday/TipOfTheDayApplication.java"
    click HomeController "https://github.com/esoto6/tip-of-the-day/blob/main/src/main/java/com/edwinsoto/tipoftheday/controller/HomeController.java"
    click TipController "https://github.com/esoto6/tip-of-the-day/blob/main/src/main/java/com/edwinsoto/tipoftheday/controller/TipController.java"
    click TipService "https://github.com/esoto6/tip-of-the-day/blob/main/src/main/java/com/edwinsoto/tipoftheday/service/TipService.java"
    click TipScheduler "https://github.com/esoto6/tip-of-the-day/blob/main/src/main/java/com/edwinsoto/tipoftheday/service/TipScheduler.java"
    click TipRepository "https://github.com/esoto6/tip-of-the-day/blob/main/src/main/java/com/edwinsoto/tipoftheday/repository/TipRepository.java"
    click Tip "https://github.com/esoto6/tip-of-the-day/blob/main/src/main/java/com/edwinsoto/tipoftheday/record/Tip.java"
    click AppConfig "https://github.com/esoto6/tip-of-the-day/blob/main/src/main/resources/application.properties"
    click CSS "https://github.com/esoto6/tip-of-the-day/blob/main/src/main/resources/static/styles.css"
    click HTML "https://github.com/esoto6/tip-of-the-day/blob/main/src/main/resources/templates/home.html"

    %% Styles
    classDef frontend fill:#f2f2f2,stroke:#333,stroke-width:1px
    classDef backend fill:#d9e8fb,stroke:#0366d6,stroke-width:2px
    classDef database fill:#daf5d9,stroke:#228b22,stroke-width:2px
    classDef external fill:#ffe5b4,stroke:#ff8c00,stroke-width:2px
    classDef infra fill:#e2d9f3,stroke:#6a0dad,stroke-width:2px
```
