cmc-sales/go/README.md

3.1 KiB

CMC Sales Go Application

Modern Go web application for CMC Sales system, designed to work alongside the legacy CakePHP application.

Architecture

  • Backend: Go with Gorilla Mux for HTTP routing
  • Database: sqlc for type-safe SQL queries
  • Frontend: Go templates with HTMX for dynamic interactions
  • Styling: Bulma CSS framework
  • Database Driver: MySQL/MariaDB

Quick Start

Local Development

  1. Configure private module access (required for code.springupsoftware.com):
go env -w GOPRIVATE=code.springupsoftware.com
# If using SSH keys with git:
git config --global url."git@code.springupsoftware.com:".insteadOf "https://code.springupsoftware.com/"
  1. Install dependencies:
make install
  1. Copy environment variables:
cp .env.example .env
  1. Generate sqlc code:
make sqlc
  1. Run the server:
make run

Docker Development

From the project root:

# Standard build (requires Go 1.23+)
docker compose up cmc-go

# If you encounter Go version issues, use the legacy build:
# Edit docker-compose.yml to use: dockerfile: Dockerfile.go.legacy

Web Interface

The application provides a modern web interface accessible at:

  • Home: / - Dashboard with quick links
  • Customers: /customers - Customer management interface
  • Products: /products - Product catalog management
  • Purchase Orders: /purchase-orders - Order tracking

Features

  • Real-time search with HTMX
  • Responsive design with Bulma CSS
  • Form validation and error handling
  • Pagination for large datasets
  • CRUD operations with dynamic updates

API Endpoints

REST API endpoints are available under /api/v1:

Customers

  • GET /api/v1/customers - List customers (JSON)
  • GET /api/v1/customers/{id} - Get customer by ID
  • POST /api/v1/customers - Create new customer
  • PUT /api/v1/customers/{id} - Update customer
  • DELETE /api/v1/customers/{id} - Delete customer
  • GET /api/v1/customers/search?q={query} - Search customers

Products

  • GET /api/v1/products - List products (JSON)
  • GET /api/v1/products/{id} - Get product by ID
  • POST /api/v1/products - Create new product
  • PUT /api/v1/products/{id} - Update product
  • DELETE /api/v1/products/{id} - Delete product
  • GET /api/v1/products/search?q={query} - Search products

Purchase Orders

  • GET /api/v1/purchase-orders - List purchase orders (JSON)
  • GET /api/v1/purchase-orders/{id} - Get purchase order by ID
  • POST /api/v1/purchase-orders - Create new purchase order
  • PUT /api/v1/purchase-orders/{id} - Update purchase order
  • DELETE /api/v1/purchase-orders/{id} - Delete purchase order
  • GET /api/v1/purchase-orders/search?q={query} - Search purchase orders

Health Check

  • GET /api/v1/health - Service health check

Development

Adding New Queries

  1. Add SQL queries to sql/queries/
  2. Run make sqlc to generate Go code
  3. Create handler in internal/cmc/handlers/
  4. Register routes in cmd/server/main.go

Testing

make test

Building

make build

The binary will be output to bin/server