A fullstack inventory management system built with Go (Golang) for the backend and React for the frontend, supporting Stock In, Stock Out (Two-Phase Commitment), Inventory management, and transaction reporting.
| Layer | Technology |
|---|---|
| Backend | Go (Golang), Gin / Chi Router |
| Database | PostgreSQL |
| Frontend | React, Zustand (State Management) |
| Auth | JWT |
The backend follows a layered architecture with SOLID and DRY principles applied throughout:
backend/
├── cmd/
│ └── main.go # Entry point
├── internal/
│ ├── handler/ # HTTP handlers (controllers)
│ ├── service/ # Business logic layer
│ ├── repository/ # Database access layer (interfaces + implementations)
│ ├── model/ # Domain models & DTOs
│ └── middleware/ # Auth, logging, error handling
├── db/
│ └── migrations/ # SQL migration files
├── config/
│ └── config.go # Environment config loader
└── .env.example
- Handler → receives HTTP requests, validates input, delegates to Service
- Service → contains all business rules (state machines, stock checks, rollback logic)
- Repository → abstracts all DB queries; uses interfaces for testability
- PostgreSQL transactions are used explicitly for multi-step operations (e.g., Stock Out Two-Phase Commit, Stock In → DONE state update)
frontend/
├── src/
│ ├── pages/
│ │ ├── StockIn/
│ │ ├── StockOut/
│ │ ├── Inventory/
│ │ └── Report/
│ ├── components/ # Shared UI components
│ ├── store/ # Zustand global state
│ ├── services/ # API call layer (axios)
│ └── App.tsx
- Zustand manages global state (inventory list, active transactions)
- Services layer abstracts all API calls, keeping components clean
- Each feature page manages its own local UI state (loading, error, form)
- Go >= 1.21
- Node.js >= 18
- PostgreSQL >= 14
migrateCLI (optional, for running migrations manually)
git clone https://github.com/<your-username>/smart-inventory.git
cd smart-inventorycd backend
cp .env.example .envEdit .env:
DB_HOST=localhost
DB_PORT=5432
DB_USER=postgres
DB_PASSWORD=yourpassword
DB_NAME=smart_inventory
SERVER_PORT=8080
JWT_SECRET=your_jwt_secret# Using migrate CLI
migrate -path db/migrations -database "postgres://postgres:yourpassword@localhost:5432/smart_inventory?sslmode=disable" upOr manually execute the SQL files in db/migrations/ in order.
go mod tidy
go run cmd/main.goBackend will be available at: http://localhost:8080
cd frontend
npm installCreate a .env file:
VITE_API_BASE_URL=http://localhost:8080/apiStart the development server:
npm run devFrontend will be available at: http://localhost:5173
- State machine:
CREATED → IN_PROGRESS → DONE - Every status change is logged to a history/log table
- Physical stock in
Inventorytable only increases when status becomesDONE CANCELLEDis only allowed beforeDONE
- View all items with filter by Name, SKU, or Customer
- Displays:
- Physical Stock: total quantity in warehouse
- Available Stock: physical stock minus quantity reserved by in-progress Stock Out orders
- Stock Adjustment feature to manually edit stock quantity
- Stage 1 — Allocation (DRAFT): System checks available stock → reserves it (status:
ALLOCATED). Reserved stock is locked from other orders. - Stage 2 — Execution: Draft moves to
IN_PROGRESS→ thenDONE - If cancelled at
IN_PROGRESS, system performs rollback: reserved stock is returned to Available
- Only shows transactions with status
DONE - Detailed per-transaction view (Stock In & Stock Out)
| Method | Endpoint | Description |
|---|---|---|
| POST | /api/stock-in |
Create new Stock In |
| PATCH | /api/stock-in/:id/status |
Update Stock In status |
| GET | /api/inventory |
List inventory with filters |
| PATCH | /api/inventory/:id/adjust |
Stock adjustment |
| POST | /api/stock-out |
Create Stock Out (Stage 1) |
| PATCH | /api/stock-out/:id/execute |
Execute Stock Out (Stage 2) |
| PATCH | /api/stock-out/:id/cancel |
Cancel & rollback Stock Out |
| GET | /api/reports |
Get completed transaction report |
# Backend unit tests
cd backend
go test ./...- All multi-step database operations use explicit PostgreSQL transactions with rollback on error.
- Repository layer uses interfaces, enabling easy mocking for unit tests.
- Stock availability is computed at query time to ensure accuracy under concurrent load.