SGVS API is a robust RESTful backend application built with Spring Boot that provides complete management capabilities for sales, inventory, customers, and expenses. Designed to deliver a "CEO experience" with business intelligence, the API integrates real-time inflation tracking and delivers analytical reports to help small and medium-sized businesses optimize their financial operations.
Here's an example of an authenticated request successfully returning a product list:
GET http://localhost:8081/api/v1/products
Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...
β
Status: 200 OK
{
"data": [
{
"id": 1,
"name": "Product A",
"sku": "SKU-001",
"cost": 50.00,
"price": 99.90,
"profitMargin": 99.80,
"stock": 150,
"category": "Electronics"
},
{
"id": 2,
"name": "Product B",
"sku": "SKU-002",
"cost": 30.00,
"price": 79.90,
"profitMargin": 166.33,
"stock": 45
}
],
"meta": {
"total": 2,
"page": 0,
"limit": 20
}
}
π‘ Tip: All responses follow consistent RESTful patterns with appropriate HTTP status codes (200 OK, 400 Bad Request, 401 Unauthorized, 500 Server Error).
- Java 21 β Modern language with cutting-edge features
- Spring Boot 3.5.3 β Web framework and security
- Spring Data JPA β Object-relational mapping (ORM)
- Spring Security + JWT β Stateless authentication with tokens
- OAuth2 Google β Integrated social login
- PostgreSQL β Robust relational database
- Hibernate β ORM for automatic persistence
- Google OAuth 2.0 β Authentication via Google
- Maven β Dependency management and build automation
- Lombok β Reduces boilerplate (getters, setters, constructors)
- JUnit 5 + Mockito β Unit testing with coverage
- Docker β Containerization for deployment
- β User registration and login with robust validation
- β JWT authentication with configurable token expiration
- β Google OAuth 2.0 login with integrated profile
- β Role-based access control (ADMIN, USER)
- β Complete CRUD operations on products
- β Automatic profit margin calculation
- β Inventory control (global, per-item, or disabled)
- β Categorization and unique SKU
- β ABC report (top-selling products)
- β Complete CRUD for customers with contact validation
- β Advanced filters and pagination
- β Purchase history tracking
- β Support for generic customer (sale without specific customer)
- β Sales recording with multiple items
- β Automatic calculation of totals (gross and net)
- β Per-item discount control
- β Automatic inventory updates
- β Sales reports by period
- β Registration of operational expenses
- β Restocking expenses (automatically update inventory)
- β Expense categorization
- β Advanced filters and reports
- β Summary metric cards (revenue, profit, inventory)
- β Sales evolution charts
- β Product ABC report
- β Integration with Central Bank inflation indices
- β Inventory control modes (global, per-item, or disabled)
- β Currency and localization
- β Business parameters (default margins, etc.)
We started by designing the database schema based on a real-world sales management business model. The greatest challenge was balancing ease of use with business robustness β many startups fail because they over-engineer simple things.
The first major milestone was implementing the Products and Sales API with precise profit calculations. We faced initial challenges with:
- Automatic inventory updates β We needed to synchronize sales and restocking expenses without creating inconsistencies. Solution: transactions with
@Transactionalin Spring. - Efficient pagination β Thousands of records loading slowly. Solution: database indices on PostgreSQL + optimized queries with
@Queryin JPA. - Inflation integration β We needed to fetch Central Bank indices but with safe fallback. Solution: scheduled task that updates cache periodically.
This project forced me to deeply understand:
- Spring Security: Configuring JWT correctly is non-trivial. I now understand why many projects fail with token leaks.
- Transaction Management: Operations modifying multiple tables require careful isolation. I learned when to use
@Transactionaland isolation levels. - API Design: Consistent naming, versioning (
/api/v1/), and standardized responses make ALL the difference in maintainability. - Testing Strategy: Unit tests in services with Mockito revealed bugs that manual testing never caught, especially in calculation logic.
- Infrastructure: Docker + PostgreSQL in production is different from h2 in tests. I learned about connectionPool, timeout, and real performance.
If you just want to USE the project, just click on the URL https://sgvs-ui.onrender.com/
You'll need to have installed:
- Java 21+ (Download)
- Maven 3.8+ (usually comes with IDEs like IntelliJ or Eclipse)
- PostgreSQL 12+ (Download)
- Git to clone the repository
git clone https://github.com/your-username/sgvs-api.git
cd sgvs-api- Copy the example file:
cp .env.example .env- Edit the .env file and set real values:
# Database
DB_PASSWORD=your-postgres-password-here
# JWT Secret (generate a random string with at least 32 characters)
# Tip: use `openssl rand -base64 32` to generate automatically
JWT_SECRET_KEY=your-random-32-character-minimum-secret-key-here
β οΈ IMPORTANT: Never commit real passwords! Use environment variables in production.
- Create the database:
CREATE DATABASE sgvs_db;
CREATE USER postgres WITH PASSWORD 'your-postgres-password-here';
GRANT ALL PRIVILEGES ON DATABASE sgvs_db TO postgres;- Or use Docker (recommended):
docker run --name sgvs-postgres \
-e POSTGRES_PASSWORD=your-password \
-e POSTGRES_DB=sgvs_db \
-p 5432:5432 \
-d postgres:latestOn Linux/macOS:
export DB_PASSWORD='your-postgres-password-here'
export JWT_SECRET_KEY='your-random-32-character-minimum-secret-key-here'
export GOOGLE_CLIENT_ID='your-google-client-id'
export GOOGLE_CLIENT_SECRET='your-google-client-secret'On Windows (PowerShell):
$env:DB_PASSWORD = 'your-postgres-password-here'
$env:JWT_SECRET_KEY = 'your-random-32-character-minimum-secret-key-here'
$env:GOOGLE_CLIENT_ID = 'your-google-client-id'
$env:GOOGLE_CLIENT_SECRET = 'your-google-client-secret'# With Maven wrapper (recommended)
./mvnw spring-boot:run
# Or with globally installed Maven
mvn spring-boot:runThe application will start at: http://localhost:8081
curl http://localhost:8081/actuator/health
# Expected response:
# {"status":"UP"}curl -X POST http://localhost:8081/api/auth/register \
-H "Content-Type: application/json" \
-d '{
"username": "your-username",
"email": "your-email@example.com",
"password": "secure-password-here"
}'The .env.example file is already included in the repository. Copy and configure:
# Database
DB_PASSWORD=your-secure-password-here
# JWT Security
# Generate with: openssl rand -base64 32
JWT_SECRET_KEY=your-32-character-minimum-secret-key-here
# (Optional) Google OAuth
# GOOGLE_CLIENT_ID=your-client-id.apps.googleusercontent.com
# GOOGLE_CLIENT_SECRET=your-client-secret
# GOOGLE_REDIRECT_URI=http://localhost:8081/api/auth/google/callbackmvn clean package -DskipTestsThis generates an executable JAR in target/sgvs-api-0.0.1-SNAPSHOT.jar.
java -jar target/sgvs-api-0.0.1-SNAPSHOT.jardocker build -t sgvs-api:latest .
docker run -p 8081:8081 \
-e DB_PASSWORD='your-password' \
-e JWT_SECRET_KEY='your-secret' \
sgvs-api:latestRun unit tests:
# Run all tests
mvn test
# Run with coverage
mvn test jacoco:reportTests cover main services: ProductService, SaleService, CustomerService, ExpenseService.
- API Docs: [Swagger UI] (coming soon)
- Roadmap: See README.md for complete phases
- Project Structure:
- controller β REST Controllers
src/main/java/com/flick/business/core/service/β Business logic- entity β JPA Entities
- repository β Data access
This is a portfolio project. If you find bugs or have suggestions, open an issue or pull request.
This project is under the MIT license. See the LICENSE file for details.
Developed with β€οΈ as a modern full-stack business management project.
Frontend (React + Vite): sgvs-ui