Skip to content

trifonstanchevtech/mini-erp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Mini ERP – Spring Boot + PostgreSQL + JWT

A backend-focused Mini-ERP system built with Spring Boot. The project demonstrates REST architecture, business logic implementation, role-based security with JWT, and stock management.


Features

Customers

  • Create customer
  • List customers

Products

  • Create product
  • List products
  • Manage stock quantity

Orders

  • Create draft order
  • Add items to order
  • Confirm order
  • Cancel order
  • Stock reduction on confirmation
  • Business rule enforcement (no empty orders, no cancel after confirmation)

Security

  • JWT authentication
  • Role-based authorization (ADMIN, SALES)
  • BCrypt password hashing
  • Stateless session management

Architecture Overview

  • api/ → REST Controllers
  • domain/ → JPA Entities
  • dto/ → Request & Response DTOs
  • repository/ → Spring Data JPA Repositories
  • security/ → JWT service + filter
  • config/ → Spring Security configuration

Entity Relationship Diagram

ER Diagram The diagram reflects the relational database structure used by the application, including primary keys, foreign keys, and business-relevant constraints.


Business Rules Implemented

  • Orders must contain at least one item before confirmation
  • Confirmed orders cannot be canceled
  • Stock is reduced permanently upon confirmation
  • Orders cannot be confirmed if stock is insufficient
  • Price and VAT are stored as snapshots in OrderItem

Authentication & Authorization

Login Endpoint

POST /auth/login

Example:

{
  "username": "sales",
  "password": "sales123"
}

Returns:

{
"token": "JWT_TOKEN"
}

Roles

  • ADMIN
  • SALES

Protected Endpoints

All ERP endpoints require:

Authorization: Bearer <token>

📡 API Endpoints

Health

GET /health

Admin Only

GET /admin/ping

Customers

POST /customers
GET /customers

Products

POST /products
GET /products

Example product:

{
  "sku": "P-001",
  "name": "Laptop",
  "description": "Business Laptop",
  "unitPriceNet": 1200.00,
  "vatRate": 0.19,
  "stockQty": 10
}

Orders

Create draft:

POST /orders

Add item:

POST /orders/{orderId}/items

Confirm order:

PATCH /orders/{orderId}/confirm

Cancel order:

PATCH /orders/{orderId}/cancel

🗄 Database

PostgreSQL (Docker)

Example start command:

docker run --name minierp-postgres \
-e POSTGRES_USER=erp \
-e POSTGRES_PASSWORD=erp \
-e POSTGRES_DB=minierp \
-p 5432:5432 \
-d postgres:16

Configuration

application.properties
  • spring.datasource.url
  • spring.datasource.username
  • spring.datasource.password
  • jwt.secret
  • jwt.expiration

Security Design Decisions

  • Stateless API (no sessions)
  • JWT signed with HS256
  • BCrypt password hashing
  • Roles mapped to Spring Security authorities
  • /error endpoint permitted to allow proper HTTP error responses

Example Workflow

1. Login → receive JWT

2. Create product

3. Create order (draft)

4. Add item

5. Confirm order → stock decreases

6. Attempt cancel → rejected (409 Conflict)


Tech Stack

  • Java 21
  • Spring Boot
  • Spring Web
  • Spring Data JPA
  • Spring Security
  • JWT (jjwt)
  • PostgreSQL
  • Gradle
  • Docker

Possible Improvements

  • Users stored in database
  • Role table and user-role mapping
  • Global exception handling (@RestControllerAdvice)
  • Invoice generation (PDF)
  • Unit tests (JUnit)
  • Integration tests
  • OpenAPI / Swagger documentation

About

Mini ERP system built with Spring Boot, JWT authentication and PostgreSQL.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages