Skip to content

PhoenixMaster123/car-service

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

48 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Car Service

A Spring Boot application for managing car service operations. It exposes a web UI with Thymeleaf and REST endpoints, integrates with external microservices for booking and payment, and supports OAuth2 login.

Last Update date: 2025-12-04

Stack

  • Language: Java 17
  • Build tool: Maven (wrapper included: mvnw/mvnw.cmd)
  • Frameworks:
    • Spring Boot 3.4.0
    • Spring Cloud 2024.0.2
    • Springdoc OpenAPI
  • Databases:
    • MySQL (default profile)
    • H2 file DB (dev profile)
  • Front-End:
    • Thymeleaf
  • Spring AI:
    • Google GenAI
  • Other: Lombok, Apache Commons Lang, Checkstyle

Entry Point

  • Main class: springboot.bg.harisauto.Application
  • Runs on port 8080 by default (configurable via server.port).

Requirements

  • JDK 17+
  • Maven 3.9+ (or use the provided Maven wrapper)
  • MySQL 8.x (for default profile) or Docker for MailHog (optional for dev email testing)

Quick Start

  • Run with default profile (MySQL required):
    ./mvnw spring-boot:run
  • Run with dev profile (H2 + MailHog):
    # start MailHog (optional but recommended for dev profile)
    docker compose -f docker-compose-mailhog.yml up -d
    
    # run app with dev profile
    ./mvnw spring-boot:run -Dspring-boot.run.profiles=dev

API Docs

  • Swagger UI: http://localhost:8080/swagger-ui.html

Scripts and Tooling

  • check.sh — runs Checkstyle and opens the HTML report (note: has convenience for WSL + Windows Explorer).
  • Maven wrapper — use ./mvnw instead of globally installed Maven.
  • Optional: docker-compose-mailhog.yml — starts MailHog on ports 1025 (SMTP) and 8025 (Web UI).

Configuration and Environment Variables

Configuration lives primarily in:

  • src/main/resources/application.yml (default)
  • src/main/resources/application-dev.yml (dev profile)
  • src/test/resources/application-test.yml (tests)

Set these environment variables before running the app (copy/paste ready):

# Database (default profile uses MySQL)
export DB_USERNAME="your_database_username"
export DB_PASSWORD="your_database_password"

# Outbound email (default profile uses Gmail SMTP)
export EMAIL_USERNAME="your_gmail_address"
export EMAIL_PASSWORD="your_app_password"

# OAuth2 login
export GOOGLE_CLIENT_ID="your_google_client_id"
export GOOGLE_CLIENT_SECRET="your_google_client_secret"
export GITHUB_CLIENT_ID="your_github_client_id"
export GITHUB_CLIENT_SECRET="your_github_client_secret"

# AI (Gemini)
export GEMINI_API_KEY="your_gemini_api_key"

# Payments (Stripe)
export STRIPE_PUBLIC_KEY="your_stripe_public_key"

Explanation and where to obtain keys:

Additional service endpoints configured in application.yml:

  • payment-service.url — default http://localhost:8081
  • booking-service.url — default http://localhost:8082

Profiles

  • Default (no profile):
    • MySQL datasource jdbc:mysql://localhost:3306/car_service_db?createDatabaseIfNotExist=true
    • Gmail SMTP on port 587, TLS
    • OpenAPI at /swagger-ui.html
  • dev profile:
    • H2 file DB at ./data/testdb with web console at /h2-console
    • MailHog SMTP on localhost:1025, UI at http://localhost:8025
    • Redis cache configured (localhost:6379)

Microservices

This service communicates with external microservices via OpenFeign:

  • Payment Service — base URL: ${payment-service.url} (default http://localhost:8081).
  • Booking Service — base URL: ${booking-service.url} (default http://localhost:8082).

Project Structure

Top-level

  • pom.xml — Maven configuration
  • src/main/java — Application sources
  • src/main/resources — App configuration, templates, static assets
  • src/test/java — Tests
  • docker-compose-mailhog.yml — Dev email testing container
  • check.sh — Checkstyle helper
Java packages
├─ api/                       # API docs or specs (if used)
├─ checkstyle/                # Checkstyle configuration
├─ data/                      # Local data (e.g., H2 file DB path)
├─ docker-compose-mailhog.yml # Dev SMTP testing tool
├─ pom.xml                    # Maven build descriptor
springboot.bg.harisauto
├── booking
│   ├── client
│   ├── dto
│   │   ├── request
│   │   └── response
│   └── service
│
├── cart
│
├── chatbot
│   ├── controller
│   ├── dto
│   └── service
│
├── common
│   ├── config
│   │   ├── ai
│   │   ├── database
│   │   ├── interceptor
│   │   ├── rest
│   │   ├── security
│   │   └── swagger
│   ├── exception
│   ├── init
│   └── logger
│
├── email
│
├── event
│
├── payment
│   ├── client
│   ├── controller
│   ├── dto
│   │   ├── request
│   │   └── response
│
├── service
│   ├── model
│   ├── repository
│   └── service
│
├── user
│   ├── model
│   ├── repository
│   └── service
│
├── validation
│   └── annotations
│
├── vehicle
│   ├── model
│   ├── repository
│   └── service
│
└── web
    ├── controller
    ├── dto
    └── mapper
├─ src/main/resources/
│  ├─ application.yml        # Default profile config (MySQL)
│  ├─ application-dev.yml    # Dev profile (H2, Mailhog)
│  ├─ application-ci.properties # CI profile (H2 in-memory)

Resources

  • application.yml — default configuration, including DB, mail, OAuth, Swagger, service URLs
  • application-dev.yml — dev profile overrides (H2, MailHog, Redis cache)
  • templates/ — Thymeleaf templates (auth, account, public, etc.)
  • static/ — static assets (CSS, JS)

Running Tests

  • All tests:

    ./mvnw test
  • Run with a specific profile for tests (if needed):

    ./mvnw test -Dspring.profiles.active=test

Linting/Style

  • Checkstyle report:
    ./mvnw checkstyle:checkstyle
    # or
    bash check.sh
    Report path: target/site/checkstyle.html

Database

  • Default profile uses MySQL with Hibernate ddl-auto: update. Ensure MySQL is running and accessible.
  • Dev profile uses H2 with console at http://localhost:8080/h2-console (when dev profile is active).

Authentication & Authorization

  • Username/password login with Spring Security (login page /login)
  • OAuth2 login with Google and GitHub
  • Role-based access (/admin/** requires ROLE_ADMIN)

Author

License

This project is licensed under the MIT License. For more details, please refer to the file: LICENSE.