Skip to content

Repository files navigation

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

Project summary

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.

Tech stack & concepts used

  • 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/pages guarded by Spring MVC
  • Multipart file upload for images (stored to webapp/images at runtime)
  • JavaMail (Spring Boot spring-boot-starter-mail) for sending registration emails
  • Dockerfile provided to run the packaged JAR in a Java runtime image

Project structure (key packages)

  • com.FS_Project.Mobile.API - root
    • Controller - web controllers (e.g., Webcontroller.java) exposing endpoints for product, login, register, save, validate
    • Service - 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 resources
  • src/main/webapp/images - image assets shipped with the project (example product images and placeholders)

Key files

  • Application.java - Spring Boot application entry point
  • Controller/Webcontroller.java - request handlers: showregister, savedata, validate, saveProduct, etc.
  • Entity/User.java - user entity (mapped to the existing user table columns)
  • Entity/Product.java, Entity/Category.java - product & category models
  • Service/MailService.java - centralized, defensive mail sending logic (skips sending when SMTP not reachable)
  • Config/MailConfig.java - sets up JavaMailSender from spring.mail.* properties; logs mail config at startup
  • Dockerfile - 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)

Database & entities

  • 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., User maps emailid and username as required).
  • Hibernate ddl-auto is set to update by default in the project's config. Be careful with update/create in production—prefer explicit migrations (Flyway/Liquibase).

Registration flow & email sending

  • The savedata endpoint in Webcontroller saves a User entity in the database, optionally persists an uploaded image to the webapp images folder, and delegates sending a welcome email to MailService.
  • MailService is defensive: it checks configured SMTP host/port and performs a short socket connect test to avoid repeated Connection refused errors when SMTP is not properly configured. If SMTP is not reachable or points to localhost: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).

File upload / images

  • Profile and product images are accepted as multipart uploads (MultipartFile) and written to request.getServletContext().getRealPath("/images") (the webapp runtime images directory). The imagepath field 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.

Configuration (application.yml)

  • src/main/resources/application.yml contains DB and mail settings used at runtime. Example entries:
    • spring.datasource.url, spring.datasource.username, spring.datasource.password
    • spring.mail.host, spring.mail.port, spring.mail.username, spring.mail.password
    • server.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 & run

  1. Build the jar with Maven (in project root):
./mvnw -DskipTests package
  1. Run locally (jar):
java -jar target/Mvc-0.0.1-SNAPSHOT.jar
  1. 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 .
  1. 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

Troubleshooting common issues

  • Permission denied connecting to Docker daemon (on Linux): the socket /var/run/docker.sock is typically owned by root:docker. Add your user to the docker group or run docker commands with sudo:
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 proper spring.mail.host and spring.mail.port, or use environment variables to override application.yml. For dev testing, use Mailtrap and set its credentials as env vars.

Security & production recommendations

  • 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=update in production.
  • Replace System.out/printStackTrace with 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.

Next steps / enhancements

  • Add integration tests for registration flow that mock JavaMailSender and verify an email was attempted.
  • Replace direct SessionFactory usage 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.yml for local dev with MySQL + Maildev/Mailtrap + app.

Contact / where to look in the repo

  • 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.yml for 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.

About

Full Stack Application (Inventory Management App)

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages