2019-04-25 01:12:22 -07:00
# cmc-sales
2025-11-20 04:44:07 -08:00
CMC Sales is a business management system with two applications:
- **PHP Application**: CakePHP 1.2.5 (currently the primary application)
- **Go Application**: Go + HTMX (used for select features, growing)
**Future development should be done in the Go application wherever possible.**
## Architecture
Both applications:
- Share the same MariaDB database
- Run behind a shared Caddy reverse proxy with basic authentication
- Support staging and production environments on the same server
2025-06-24 03:32:28 -07:00
2025-11-20 04:44:07 -08:00
The PHP application currently handles most functionality, while the Go application is used for select screens and new features as they're developed.
## Development Setup
2025-06-24 03:32:28 -07:00
### Quick Start
2019-04-25 01:12:22 -07:00
2025-06-02 14:49:29 -07:00
``` shell
git clone git@code.springupsoftware.com:cmc/cmc-sales.git
cd cmc-sales
2025-06-24 03:32:28 -07:00
# Easy way - use the setup script
./start-development.sh
# Manual way
2025-06-02 14:49:29 -07:00
rsync -avz --progress cmc@sales.cmctechnologies.com.au:~/backups .
2025-06-24 03:32:28 -07:00
docker compose up --build
2025-06-02 14:49:29 -07:00
gunzip < backups / backup_ * . sql . gz | mariadb -h 127 . 0 . 0 . 1 -u cmc -p cmc
2025-06-24 03:32:28 -07:00
```
2025-06-02 14:49:29 -07:00
2025-06-24 03:32:28 -07:00
### Access Applications
2025-06-02 14:49:29 -07:00
2025-06-24 03:32:28 -07:00
**Add to /etc/hosts:**
```
127.0.0.1 cmclocal
2025-06-02 14:49:29 -07:00
```
2025-06-24 03:32:28 -07:00
**Application URLs:**
- **CakePHP (Legacy)**: http://cmclocal - Original CakePHP 1.2.5 application
- **Go (Modern)**: http://localhost:8080 - New Go application with HTMX frontend
- **Database**: localhost:3306 (user: `cmc` , password: see `app/config/database.php` )
### Architecture
- **cmc-php**: Legacy CakePHP application (nginx proxied)
- **cmc-go**: Modern Go application (direct access on port 8080)
- **db**: Shared MariaDB database
- **nginx**: Reverse proxy for CakePHP app
Both applications share the same database, allowing for gradual migration.
### Requirements
- **Go Application**: Requires Go 1.23+ (for latest sqlc)
- Alternative: Use `Dockerfile.go.legacy` with Go 1.21 and sqlc v1.26.0
2025-11-20 04:44:07 -08:00
## Deployment
2025-06-02 14:49:29 -07:00
2025-11-20 04:44:07 -08:00
### Prerequisites
2019-12-17 20:06:53 -08:00
2025-11-20 04:44:07 -08:00
The deployment scripts use SSH to connect to the server. Configure your SSH config (`~/.ssh/config`) with a host entry named `cmc` pointing to the correct server:
2019-12-17 20:06:53 -08:00
```
2025-11-20 04:44:07 -08:00
Host cmc
HostName node0.prd.springupsoftware.com
User cmc
IdentityFile ~/.ssh/cmc
2019-12-17 20:06:53 -08:00
```
2025-11-20 04:44:07 -08:00
### Deployment Procedures
2019-12-17 20:06:53 -08:00
2025-11-20 04:44:07 -08:00
Deploy to staging or production using the scripts in the `deploy/` directory:
2019-12-17 20:06:53 -08:00
2025-11-20 04:44:07 -08:00
**Deploy to Staging:**
```bash
2025-11-22 18:03:06 -08:00
./scripts/deploy/deploy-stg.sh
2019-12-17 20:06:53 -08:00
```
2025-11-20 04:44:07 -08:00
**Deploy to Production:**
```bash
./deploy/deploy-prod.sh
2019-12-17 20:06:53 -08:00
```
2025-11-20 04:44:07 -08:00
**Rebuild without cache (useful after dependency changes):**
```bash
2025-11-22 18:03:06 -08:00
./scripts/deploy/deploy-prod.sh --no-cache
./scripts/deploy/deploy-stg.sh --no-cache
2019-12-17 20:06:53 -08:00
```
2025-11-20 04:44:07 -08:00
### How Deployment Works
2019-12-17 20:06:53 -08:00
2025-11-20 04:44:07 -08:00
1. The deploy script connects to the server via the `cmc` SSH host
2. Clones or updates the appropriate git branch (`stg` or `prod` )
3. Creates environment configuration for the Go application
4. Builds and starts Docker containers using the appropriate compose file
5. Applications are accessible through Caddy reverse proxy with basic auth
2020-09-09 23:54:22 -07:00
2025-11-20 04:44:07 -08:00
### Deployment Environments
2019-12-17 20:06:53 -08:00
2025-11-20 04:44:07 -08:00
- **Staging**: Branch `stg` → https://stg.cmctechnologies.com.au
- **Production**: Branch `prod` → https://sales.cmctechnologies.com.au or https://prod.cmctechnologies.com.au
2020-09-30 19:05:35 -07:00
2025-11-20 04:44:07 -08:00
Both environments run on the same server and share:
- A single Caddy reverse proxy (handles HTTPS and basic authentication for both environments)
- Separate Docker containers for each environment's PHP and Go applications
- Separate MariaDB database instances