A web-based inventory management system designed for small retail businesses.
The Stock Management System is a REST API built with Spring Boot for teams that need a dependable way to manage products, sales, customers, suppliers, and stock in one place.
It is built around day-to-day retail operations: clear inventory visibility, low-stock alerts, traceable sales, and reporting that helps store teams make practical decisions. The API is backed by MySQL, documented with OpenAPI, and protected with JWT-based role access.
- Give store owners real-time visibility into inventory.
- Track sales and associate them with customers.
- Surface low-stock conditions before they become operational issues.
- Provide useful reporting for products, revenue, payments, and sales activity.
- Support clear access boundaries for owners, administrators, and operators.
- Product catalogue with brands, categories, suppliers, active-state controls, and barcode lookup.
- Inventory movement tracking for entries, exits, adjustments, and sales.
- Sales and sale-item management with payment status and stock validation.
- Customer addresses, administrator accounts, users, and permission-based access.
- Low-stock alerts and reporting endpoints for revenue, sales, payment methods, and top products.
- Database versioning through Flyway and integration tests backed by Testcontainers.
| Area | Choice |
|---|---|
| Runtime | Java 21 |
| Framework | Spring Boot 4 |
| API | Spring MVC and springdoc-openapi |
| Security | Spring Security, JWT, refresh tokens |
| Persistence | Spring Data JPA, Hibernate, MySQL 8 |
| Migrations | Flyway |
| Build | Maven |
| Testing | JUnit 5, Rest Assured, Spring Security Test, Testcontainers |
| Containers | Docker and Docker Compose |
Docker Compose starts the API and a MySQL 8 database. Create a .env file at the repository root; it is ignored by Git.
DB_PASSWORD=change-me
JWT_SECRET=use-a-long-random-secret
JWT_EXPIRATION=3600000
JWT_REFRESH_EXPIRATION=604800000
OPENAI_API_KEY=your-openai-api-keyStart the stack:
docker compose up --buildThe API is then available at http://localhost:8080. MySQL is published locally on port 3307; inside Compose the application connects to the db service on port 3306.
Requirements: Java 21, Maven 3.9+, and a reachable MySQL 8 instance.
Set the required environment variables before starting the application:
export DB_URL='jdbc:mysql://localhost:3306/stock_db?useTimezone=true&serverTimezone=UTC'
export DB_USERNAME='root'
export DB_PASSWORD='change-me'
export JWT_SECRET='use-a-long-random-secret'
export JWT_EXPIRATION='3600000'
export JWT_REFRESH_EXPIRATION='604800000'
export OPENAI_API_KEY='your-openai-api-key'
mvn spring-boot:runFlyway applies the schema migrations during startup. The application uses ddl-auto: validate, so schema changes belong in src/main/resources/db/migration, not in automatic Hibernate DDL.
OpenAPI documentation is served by the application:
- Swagger UI:
http://localhost:8080/swagger-ui.html - OpenAPI document:
http://localhost:8080/api-docs
Authentication endpoints are available under /auth for login, token refresh, and logout. For protected routes, send the JWT as a Bearer token:
Authorization: Bearer <access-token>| Resource | Base path |
|---|---|
| Authentication | /auth |
| Products | /products |
| Categories and brands | /categories, /brands |
| Suppliers | /suppliers |
| Customers and addresses | /clients, /clients/{id}/address |
| Administrators and users | /administrators, /users |
| Sales and items | /sales, /sales/{saleId}/items |
| Stock movements | /stock-movements |
| Alerts | /alerts |
| Analytics | /analytics |
| AI assistant | /assistant/chat |
Access is governed by ROLE_OWNER, ROLE_ADMIN, and ROLE_OPERATOR. The security configuration defines the allowed operations for each route group.
The test suite uses Testcontainers to run MySQL-backed integration tests. Docker must be available before running:
mvn testTo run one controller test class:
mvn -Dtest=AdministratorControllerTest testsrc/main/java/br/com/system
├── config # application, web, and OpenAPI configuration
├── controllers # HTTP endpoints and API contracts
├── data/dto # request and response payloads
├── model # JPA entities
├── repository # persistence access
├── security # JWT and authorization configuration
└── services # application use cases
src/main/resources/db/migration
└── Flyway SQL migrations
- Keep secrets and environment-specific values outside version control.
.envandapplication-local.ymlare already ignored. - Add a Flyway migration for every database change.
- Use the generated OpenAPI documentation as the source of truth for endpoint payloads and response shapes.
- Run the test suite before opening a pull request.