A comprehensive REST API for enterprise-grade inventory management built with Go, GORM, and PostgreSQL. This project provides complete inventory tracking, warehouse management, purchase orders, sales orders, and audit logging capabilities.
- Product Management – Create, read, update, delete products with detailed specifications
- Warehouse Management – Multi-warehouse support with location tracking
- Inventory Tracking – Real-time stock level monitoring and stock movement history
- Purchase Orders – Supplier order management with item-level tracking
- Sales Orders – Customer order management with fulfillment tracking
- Audit Logging – Comprehensive audit trail for compliance and accountability
- Reporting – Generate inventory and sales reports
- RESTful API – Clean, standard REST endpoints for all operations
- Database Migrations – Automated schema management with SQL migrations
- Environment Configuration – Flexible configuration via .env file
-
Clone the repository
git clone <repository-url> cd Golang
-
Install dependencies
go mod download
-
Set up PostgreSQL database
createdb ims_db createuser ims_user -P # You'll be prompted for a password
Create a .env file in the project root with the following variables:
DB_HOST=localhost
DB_PORT=5432
DB_USER=ims_user
DB_PASSWORD=your_password_here
DB_NAME=ims_db
SERVER_PORT=8080Start the server:
go run main.goThe API will be available at http://localhost:8080
.
├── main.go # Application entry point
├── go.mod # Go module definition
├── api/ # API-related code
├── cmd/ # Command-line interface (Cobra CLI)
├── configs/ # Configuration management
├── internal/ # Private application code
│ ├── db.go # Database initialization
│ ├── models.go # Data models
│ ├── audit/ # Audit logging module
│ ├── inventory/ # Inventory management module
│ ├── orders/ # Sales orders module
│ ├── products/ # Product management module
│ ├── reports/ # Reporting module
│ ├── suppliers/ # Supplier management module
│ └── warehouses/ # Warehouse management module
├── migrations/ # SQL migration files
│ ├── 001_create_users.sql
│ └── 002_ims_schema.sql
├── pkg/ # Public/reusable packages
│ ├── utils.go # Utility functions
│ └── middleware/ # HTTP middleware
├── test/ # Test files
├── web/ # Web assets
└── docs/ # Documentation
GET /products– List all productsGET /products/{id}– Get product detailsPOST /products– Create a new productPUT /products/{id}– Update a productDELETE /products/{id}– Delete a productGET /products/search– Search products
GET /warehouses– List all warehousesGET /warehouses/{id}– Get warehouse detailsPOST /warehouses– Create a warehousePUT /warehouses/{id}– Update a warehouseDELETE /warehouses/{id}– Delete a warehouse
GET /inventory– List inventory itemsGET /inventory/{id}– Get inventory item detailsPOST /inventory– Add inventoryPUT /inventory/{id}– Update inventory levelsDELETE /inventory/{id}– Remove inventory
GET /purchase-orders– List purchase ordersPOST /purchase-orders– Create purchase orderGET /purchase-orders/{id}– Get order detailsPUT /purchase-orders/{id}– Update orderDELETE /purchase-orders/{id}– Cancel order
GET /orders– List sales ordersPOST /orders– Create orderGET /orders/{id}– Get order detailsPUT /orders/{id}– Update orderDELETE /orders/{id}– Cancel order
GET /audit-logs– List audit logs
For complete API documentation, see docs/API_DOCUMENTATION.md or import IMS_Postman_Collection.json into Postman.
The application uses automated migrations via GORM. Database migrations are located in the migrations/ directory:
001_create_users.sql– User table and initial setup002_ims_schema.sql– Complete IMS schema
Migrations run automatically on application startup.
go test ./...Or using the provided test script:
bash scripts/test.shThis project follows Go conventions:
- Package organization – Code is organized by feature domain in
internal/ - Exports – Only exported types and functions (capitalized) are part of the public API
- Interfaces – Used for abstraction and testability
- Error handling – Explicit error handling throughout
- Create a new package under
internal/for your feature - Define models in the appropriate package or in
internal/models.go - Create handlers in
{feature}/handlers.go - Register routes in
main.go - Add database migrations if needed
- Update API documentation
The application includes comprehensive logging:
- Database connection status
- Migration results
- Audit trail of all data modifications
- Error logging for debugging
Logs use Go's standard log package and are printed to stdout.
Key dependencies:
- GORM – Go ORM for database operations
- PostgreSQL Driver – GORM PostgreSQL driver
- Cobra – CLI framework for command-line tools
- godotenv – Environment variable management
See go.mod for complete list of dependencies.
[Add your license information here]
[Add contribution guidelines here]
For more information, see docs/API_DOCUMENTATION.md or contact the development team.