How valdetad/stockmanagement works
Project type and purpose
• This is a Java-based backend application built with Spring Boot and Maven that exposes a set of RESTful APIs for managing products, markets, stocks, purchases, and users. It does not include a separate frontend; clients consume its endpoints via HTTP (e.g., Postman or a web/mobile frontend).
File structure
• Top level:
• pom.xml, mvnw wrappers – build and dependency management
• src/main/java/com/example/StockManagement – application code
• src/main/resources/application.properties – externalized configuration
• src/test – unit/integration tests
• data folder – an embedded H2 test database
• Under src/main/java:
• controller – REST controllers (API layer)
• services – business logic layer
• repository – Spring Data JPA layer (data access)
• data/model – JPA entities
• data/dto – input/output data transfer objects
• data/constants – enums for roles, statuses, categories
• security – JWT-based authentication and authorization
• Notice the classic layered architecture (Controller → Service → Repository → Database) and JWT security filters intercepting requests.
README insights
• Confirms REST APIs for Product, Stock, Purchase, Market, and User Authentication.
• Uses MySQL for persistence and JWT Bearer tokens for security.
• Export functionality to Excel and PDF via ImportExportService.
a. Main components
• Clients (Web app, Postman, Mobile)
• API Layer (Spring MVC Controllers)
• Security Layer (JWT filter, AuthenticationService)
• Service Layer (ProductService, StockService, PurchaseService, MarketService, ImportExportService)
• Persistence Layer (Spring Data JPA Repositories)
• Database (MySQL)
• External Libraries (PDF/Excel generation)
b. Relationships and interactions
1. Client sends HTTP requests with/without JWT
2. JWTAuthenticationFilter validates token → AuthenticationService
3. Valid requests go to Controller methods
4. Controllers invoke Service layer methods
5. Services apply business rules and call Repositories
6. Repositories perform CRUD operations on MySQL
7. ImportExportService accesses data via Services/Repos and uses libraries to generate Excel/PDF, returning binary streams
c. Architectural patterns
• Layered (Controller → Service → Repository → Database)
• DTO pattern to decouple API contracts from entities
• JWT filter chain in SecurityConfig for stateless authentication
d. Technologies/frameworks
• Spring Boot (web, data-jpa, security)
• Spring Security + JWT
• MySQL (production) / H2 (tests)
• Maven
• Libraries for Excel/PDF export (e.g., Apache POI, iText)