eval "$(ssh-agent -s)" ssh-add /home/ganeshn/sshkey# Product Management API
This repository is a Spring Boot-based Product Management web application (MVC) that provides simple product/category management and user registration/login functionality. This README gives a high-level project overview, concepts and technologies used, key files and packages, build/run instructions (Maven and Docker), configuration notes (database and email), and recommended next steps.
Checklist of what this README covers
- Project summary and goals
- Tech stack and core concepts used
- Important packages and key source files
- Database & entity notes (existing tables preserved)
- Registration flow and email sending behavior
- File upload / images handling
- How to build, run and test (Maven + Docker)
- Configuration (application.yml) and recommended env variables
- Troubleshooting & common issues (Docker socket permissions, mail connect errors)
- Security and production recommendations
- Next steps & improvements
The application is a small product management system written in Java using Spring Boot (2.7.x). It serves JSP pages to manage products, categories and users. Users can register, upload a profile image, log in, and view products. Merchants can manage product entries tied to categories.
The repository includes a packaged artifact under target/ (built JAR), a Dockerfile for containerizing the JAR, and server-side mail support for sending a welcome email to new registrants.
- Java 8 (project configured with
java.version=1.8) - Spring Boot (web, data-jpa)
- Hibernate / JPA entities and session-based DAO usage
- MySQL (connector used in
pom.xml) - JSP views under
src/main/webapp/pagesguarded by Spring MVC - Multipart file upload for images (stored to
webapp/imagesat runtime) - JavaMail (Spring Boot
spring-boot-starter-mail) for sending registration emails - Dockerfile provided to run the packaged JAR in a Java runtime image
com.FS_Project.Mobile.API- rootController- web controllers (e.g.,Webcontroller.java) exposing endpoints for product, login, register, save, validateService- business logic and mail service (e.g.,MailService.java,EmailServiceImpl.java)DAO- data access objects (if used)Entity- JPA/Hibernate entities (Product, Category, User, etc.)Config- configuration classes (e.g.,MailConfig.java)
src/main/resources-application.yml(project configuration), JSP views prefix configured, static resourcessrc/main/webapp/images- image assets shipped with the project (example product images and placeholders)
Application.java- Spring Boot application entry pointController/Webcontroller.java- request handlers:showregister,savedata,validate,saveProduct, etc.Entity/User.java- user entity (mapped to the existingusertable columns)Entity/Product.java,Entity/Category.java- product & category modelsService/MailService.java- centralized, defensive mail sending logic (skips sending when SMTP not reachable)Config/MailConfig.java- sets upJavaMailSenderfromspring.mail.*properties; logs mail config at startupDockerfile- image build instructions (copies built jar and runs it)pom.xml- Maven build and dependencies (spring-boot-starter-web, spring-boot-starter-data-jpa, spring-boot-starter-mail, mysql-connector)
- The app uses MySQL. Connection is configured in
src/main/resources/application.yml. - Existing table and column names have been preserved by entity mappings (e.g.,
Usermapsemailidandusernameas required). - Hibernate
ddl-autois set toupdateby default in the project's config. Be careful withupdate/createin production—prefer explicit migrations (Flyway/Liquibase).
- The
savedataendpoint inWebcontrollersaves aUserentity in the database, optionally persists an uploaded image to the webapp images folder, and delegates sending a welcome email toMailService. MailServiceis defensive: it checks configured SMTP host/port and performs a short socket connect test to avoid repeatedConnection refusederrors when SMTP is not properly configured. If SMTP is not reachable or points tolocalhost:25, it skips actual sending and logs the decision.- For real email sending, configure a valid SMTP provider and credentials (Mailtrap for dev, Gmail with App Password if necessary, or a transactional mail provider).
- Profile and product images are accepted as multipart uploads (MultipartFile) and written to
request.getServletContext().getRealPath("/images")(the webapp runtime images directory). Theimagepathfield stores the original filename or a mapped filename. - Note: storing files inside the WAR/webapp directory works for simple setups but is not robust for scaled deployments. For production, use cloud object storage (S3, GCS) or a shared file store.
src/main/resources/application.ymlcontains DB and mail settings used at runtime. Example entries:spring.datasource.url,spring.datasource.username,spring.datasource.passwordspring.mail.host,spring.mail.port,spring.mail.username,spring.mail.passwordserver.port(default 8081 in this project)
Security note: do not commit real passwords to application.yml in source control. Prefer environment variables or externalized config. The current repo previously had secrets in properties — consider replacing them with environment variables.
- Build the jar with Maven (in project root):
./mvnw -DskipTests package- Run locally (jar):
java -jar target/Mvc-0.0.1-SNAPSHOT.jar- Build Docker image (Docker must be installed and your user allowed to use the Docker daemon):
# from project root
docker build --build-arg JAR_FILE=target/Mvc-0.0.1-SNAPSHOT.jar -t product-management-api:latest .- Run Docker container (pass DB and mail config via environment variables):
docker run -e SPRING_DATASOURCE_URL=jdbc:mysql://<db-host>:3306/mobile \
-e SPRING_DATASOURCE_USERNAME=<db-user> \
-e SPRING_DATASOURCE_PASSWORD=<db-pass> \
-e SPRING_MAIL_HOST=<smtp-host> \
-e SPRING_MAIL_PORT=<smtp-port> \
-e SPRING_MAIL_USERNAME=<smtp-user> \
-e SPRING_MAIL_PASSWORD=<smtp-pass> \
-p 8081:8081 \
product-management-api:latest- Permission denied connecting to Docker daemon (on Linux): the socket
/var/run/docker.sockis typically owned byroot:docker. Add your user to thedockergroup or run docker commands withsudo:
sudo usermod -aG docker $USER
newgrp docker
# or temporarily
sudo docker build ...- Mail send failures like
Couldn't connect to host, port: localhost, 25— set properspring.mail.hostandspring.mail.port, or use environment variables to overrideapplication.yml. For dev testing, use Mailtrap and set its credentials as env vars.
- Externalize secrets: move DB and mail credentials to environment variables or a secrets manager.
- Use Flyway or Liquibase for schema migrations instead of
hibernate.ddl-auto=updatein production. - Replace
System.out/printStackTracewith a proper logging framework (SLF4J + Logback already available) and structured logs. - Do not store uploaded images inside the container filesystem for production; use a durable object store.
- Limit the privileges of any account used to access the database and mail service.
- Add integration tests for registration flow that mock
JavaMailSenderand verify an email was attempted. - Replace direct
SessionFactoryusage with Spring Data JPA repositories for clearer abstraction and easier testing. - Add user authentication/authorization (Spring Security) for protected merchant operations.
- Add Swagger/OpenAPI documentation for REST endpoints used by the app.
- Replace JSP views with a modern frontend (React/Vue) served from a separate frontend app and expose a pure REST API.
- Create
docker-compose.ymlfor local dev with MySQL + Maildev/Mailtrap + app.
- App entry:
src/main/java/com/FS_Project/Mobile/API/Application.java - Controllers:
src/main/java/com/FS_Project/Mobile/API/Controller - Entities:
src/main/java/com/FS_Project/Mobile/API/Entity - Services:
src/main/java/com/FS_Project/Mobile/API/Service - Config:
src/main/java/com/FS_Project/Mobile/API/Config - Views:
src/main/webapp/pages(JSPs) - Static images:
src/main/webapp/images
If you want, I can:
- Generate a
docker-compose.ymlfor local testing with MySQL and Maildev, - Add environment-variable parameterization to
application.yml(so secrets are not stored in repo), - Add basic integration tests for registration and email send with a mocked
JavaMailSender.
If you'd like one of the next-step items done now, tell me which and I'll implement it and verify.