initial commit
This commit is contained in:
commit
ebd5bb09fd
30 changed files with 1920 additions and 0 deletions
143
docs/README.md
Normal file
143
docs/README.md
Normal file
|
|
@ -0,0 +1,143 @@
|
|||
# go-mad
|
||||
|
||||
A web application for managing tenant database connections and running migration scripts.
|
||||
|
||||
## Overview
|
||||
|
||||
go-mad is a Go web application that helps administrators manage database connections for multiple tenants. When a new tenant is added, the application contains all the database connection information for the applications associated with that tenant. The frontend is built with React and provides a beautiful, intuitive interface for managing tenants, applications, and database migrations.
|
||||
|
||||
## Features
|
||||
|
||||
- **Tenant Management**: Create and manage tenants with their database connections
|
||||
- **Application Management**: Register and manage applications per tenant
|
||||
- **Database Connection Management**: Track database connections and status per tenant
|
||||
- **Migration Scripts**: Run goose-style SQL migration scripts per tenant database
|
||||
- **Role-Based Access Control**: System administrators and tenant-specific permissions
|
||||
- **Beautiful React UI**: Inspired by go-loose with dark/light theme support
|
||||
|
||||
## Quick Start
|
||||
|
||||
### Using Docker Compose
|
||||
|
||||
```bash
|
||||
make compose-up
|
||||
```
|
||||
|
||||
This will start:
|
||||
- PostgreSQL database (`postgres:15-alpine`)
|
||||
- go-mad application
|
||||
|
||||
Access the application at `http://localhost:8080`
|
||||
|
||||
### Manual Development
|
||||
|
||||
```bash
|
||||
# Format and vet
|
||||
make fmt
|
||||
make vet
|
||||
|
||||
# Build and run
|
||||
make build
|
||||
./go-mad
|
||||
|
||||
# Or run with docker compose
|
||||
make compose-up
|
||||
```
|
||||
|
||||
## Configuration
|
||||
|
||||
go-mad can be configured via environment variables or a `config.yaml` file:
|
||||
|
||||
| Variable | Default | Description |
|
||||
|---|---|---|
|
||||
| `GO_MAD_DATABASE_URL` | `postgres://mad:mad@localhost:5432/mad?sslmode=disable` | PostgreSQL connection string |
|
||||
| `GO_MAD_SERVER_PORT` | `8080` | HTTP server port |
|
||||
| `GO_MAD_JWT_SECRET` | `change-me-to-a-32-plus-char-secret` | JWT secret for authentication |
|
||||
| `GO_MAD_CONFIG_PATH` | `config.yaml` | Path to YAML config file |
|
||||
|
||||
### config.yaml example
|
||||
|
||||
```yaml
|
||||
server:
|
||||
host: "0.0.0.0"
|
||||
port: "8080"
|
||||
|
||||
database:
|
||||
url: "postgres://mad:mad@localhost:5432/mad?sslmode=disable"
|
||||
|
||||
jwt:
|
||||
secret_key: "your-32-plus-char-secret-here"
|
||||
```
|
||||
|
||||
## API Endpoints
|
||||
|
||||
### Dashboard
|
||||
|
||||
- `GET /api/v1/dashboard` - Get dashboard data including tenants, applications, and databases
|
||||
|
||||
### Tenants
|
||||
|
||||
- `GET /api/v1/tenants` - List all tenants
|
||||
- `POST /api/v1/tenants` - Create a new tenant
|
||||
|
||||
### Applications
|
||||
|
||||
- `GET /api/v1/applications` - List applications for a tenant
|
||||
- `POST /api/v1/applications` - Register a new application
|
||||
|
||||
### Databases
|
||||
|
||||
- `GET /api/v1/databases` - List databases for a tenant
|
||||
- `POST /api/v1/databases` - Add a database connection for a tenant
|
||||
- `POST /api/v1/databases/{id}/migrations` - Run migrations for a database
|
||||
|
||||
### Authentication
|
||||
|
||||
- `GET /login` - Login page
|
||||
- `POST /api/v1/auth/login` - Authenticate
|
||||
|
||||
## Development Workflow
|
||||
|
||||
```bash
|
||||
# Build the Go binary
|
||||
make build
|
||||
|
||||
# Build the React frontend
|
||||
make web-build
|
||||
|
||||
# Start with docker compose
|
||||
make compose-up
|
||||
|
||||
# View logs
|
||||
make compose-logs
|
||||
|
||||
# Stop
|
||||
make compose-down
|
||||
```
|
||||
|
||||
## Docker
|
||||
|
||||
### Build
|
||||
|
||||
```bash
|
||||
docker build -t go-mad:latest .
|
||||
```
|
||||
|
||||
### Push
|
||||
|
||||
```bash
|
||||
docker push go-mad:latest
|
||||
```
|
||||
|
||||
## Kubernetes
|
||||
|
||||
Deploy using Helm:
|
||||
|
||||
```bash
|
||||
helm repo add go-mad ./helm/go-mad
|
||||
helm install go-mad go-mad/go-mad
|
||||
```
|
||||
|
||||
## License
|
||||
|
||||
MIT
|
||||
96
docs/installation.md
Normal file
96
docs/installation.md
Normal file
|
|
@ -0,0 +1,96 @@
|
|||
# Installation
|
||||
|
||||
## Prerequisites
|
||||
|
||||
- Go 1.27.1 or later
|
||||
- Docker and Docker Compose (for containerized deployment)
|
||||
- Node.js and npm (for React frontend development)
|
||||
- PostgreSQL 15+ (or use Docker)
|
||||
|
||||
## Local Development
|
||||
|
||||
### 1. Clone the repository
|
||||
|
||||
```bash
|
||||
git clone https://github.com/your-organization/go-mad.git
|
||||
cd go-mad
|
||||
```
|
||||
|
||||
### 2. Install dependencies
|
||||
|
||||
```bash
|
||||
# Go dependencies
|
||||
go mod download
|
||||
|
||||
# Node dependencies
|
||||
npm install
|
||||
```
|
||||
|
||||
### 3. Set up the database
|
||||
|
||||
```bash
|
||||
# Using Docker Compose
|
||||
make compose-up
|
||||
|
||||
# Or manually
|
||||
createdb mad
|
||||
# Or set up PostgreSQL with user 'mad' and database 'mad'
|
||||
```
|
||||
|
||||
### 4. Configure the application
|
||||
|
||||
```bash
|
||||
# Create config.yaml
|
||||
cp config.example.yaml config.yaml
|
||||
# Edit config.yaml with your settings
|
||||
```
|
||||
|
||||
### 5. Run migrations
|
||||
|
||||
```bash
|
||||
make test
|
||||
# Or run manually
|
||||
go run ./cmd/go-mad
|
||||
```
|
||||
|
||||
The application will automatically run migrations on startup.
|
||||
|
||||
### 6. Start the development server
|
||||
|
||||
```bash
|
||||
# Development mode with hot reload
|
||||
make web-dev
|
||||
|
||||
# Or run the Go binary
|
||||
make run
|
||||
```
|
||||
|
||||
Access the application at `http://localhost:8080`
|
||||
|
||||
## Docker Deployment
|
||||
|
||||
```bash
|
||||
# Build and start
|
||||
docker compose up --build -d
|
||||
|
||||
# View logs
|
||||
docker compose logs -f
|
||||
|
||||
# Stop
|
||||
docker compose down
|
||||
```
|
||||
|
||||
## Kubernetes Deployment
|
||||
|
||||
```bash
|
||||
helm install go-mad oci://your-registry/go-mad/helm/go-mad
|
||||
```
|
||||
|
||||
## Production Checklist
|
||||
|
||||
- [ ] Change the default JWT secret
|
||||
- [ ] Configure proper PostgreSQL credentials
|
||||
- [ ] Set up HTTPS/TLS via ingress
|
||||
- [ ] Configure backups for the PostgreSQL data volume
|
||||
- [ ] Set up monitoring and logging
|
||||
- [ ] Review role-based access control settings
|
||||
110
docs/operations.md
Normal file
110
docs/operations.md
Normal file
|
|
@ -0,0 +1,110 @@
|
|||
# Operations
|
||||
|
||||
## Migration Scripts
|
||||
|
||||
go-mad uses goose-style SQL migration scripts stored in `internal/migration/`. Each migration file contains `-- +goose Up` and `-- +goose Down` markers.
|
||||
|
||||
### Migration Format
|
||||
|
||||
```sql
|
||||
-- +goose Up
|
||||
CREATE TABLE users (
|
||||
id SERIAL PRIMARY KEY,
|
||||
tenant_id INTEGER REFERENCES tenants(id) ON DELETE CASCADE,
|
||||
username VARCHAR(255) NOT NULL UNIQUE
|
||||
);
|
||||
|
||||
-- +goose Down
|
||||
DROP TABLE IF EXISTS users CASCADE;
|
||||
```
|
||||
|
||||
### Running Migrations
|
||||
|
||||
Migrations are automatically run at application startup via `database.Migrate()`. To run migrations manually or for a specific tenant:
|
||||
|
||||
```bash
|
||||
# Using the API
|
||||
curl -X POST http://localhost:8080/api/v1/databases/{id}/migrations
|
||||
|
||||
# Or via command line (if exposing migration tooling)
|
||||
go run ./cmd/go-mad --migrate
|
||||
```
|
||||
|
||||
### Creating New Migrations
|
||||
|
||||
```bash
|
||||
# Create a new migration file
|
||||
touch internal/migration/0004_permissions.sql
|
||||
|
||||
# Write up/down sections
|
||||
-- +goose Up
|
||||
CREATE TABLE permissions (
|
||||
id SERIAL PRIMARY KEY,
|
||||
name VARCHAR(255) NOT NULL UNIQUE
|
||||
);
|
||||
|
||||
-- +goose Down
|
||||
DROP TABLE IF EXISTS permissions CASCADE;
|
||||
```
|
||||
|
||||
### Checking Migration Status
|
||||
|
||||
The application tracks applied migrations in a `schema_migrations` table. To check which migrations have been applied, query the database:
|
||||
|
||||
```sql
|
||||
SELECT * FROM schema_migrations ORDER BY version;
|
||||
```
|
||||
|
||||
## Backup and Restore
|
||||
|
||||
### PostgreSQL Backup
|
||||
|
||||
```bash
|
||||
# Using docker exec
|
||||
docker exec go-mad-postgres pg_dump -U mad -d mad > backup.sql
|
||||
|
||||
# Or using pg_dump directly
|
||||
pg_dump -U mad -d mad > backup.sql
|
||||
```
|
||||
|
||||
### Restore
|
||||
|
||||
```bash
|
||||
psql -U mad -d mad < backup.sql
|
||||
```
|
||||
|
||||
## Monitoring
|
||||
|
||||
The application exposes a `/health` endpoint for liveness and readiness probes:
|
||||
|
||||
```bash
|
||||
curl http://localhost:8080/health
|
||||
```
|
||||
|
||||
## Logs
|
||||
|
||||
```bash
|
||||
# Docker compose logs
|
||||
make compose-logs
|
||||
|
||||
# Or kubectl
|
||||
kubectl logs deployment/go-mad
|
||||
```
|
||||
|
||||
## Scaling
|
||||
|
||||
The application is designed to be stateless (except for the database connection pool). Multiple replicas can be run behind a load balancer.
|
||||
|
||||
## Upgrading
|
||||
|
||||
```bash
|
||||
# Pull new image
|
||||
docker pull go-mad:latest
|
||||
|
||||
# Or rebuild
|
||||
make docker-build
|
||||
docker push go-mad:latest
|
||||
|
||||
# Deploy
|
||||
helm upgrade go-mad oci://your-registry/go-mad/helm/go-mad
|
||||
```
|
||||
Loading…
Add table
Add a link
Reference in a new issue