feat(go-crm): full auth, routing, middleware, and supporting infra

- Add auth handlers (signup, login, logout, account management) with bcrypt
- Add client, customer, service, scheduling, payment, question, answer handlers
- Add dashboard, monthly report, and lead pipeline pages
- Add UTF-8 middleware to force charset on HTML responses
- Add config package with env-based overrides for DB path, secrets, endpoints
- Add parser package for WhatsApp message ingestion
- Add clean-arch layers: pkg/domain, pkg/repo, pkg/usecase for leads
- Add cmd/migrate utility for DB migrations
- Add Makefile, README, run-tests.sh, and dev scripts
- Update docker-compose.yml with memory limits
- Update .air.toml to exclude DB files and stop on errors
- Update whatsapp-sync dependencies and add src/index.js entrypoint
- Add whatsme standalone WhatsApp reader app (source only)
- Untrack .opencode-sandbox/data/go-crm.db from git history
- Expand root .gitignore: ngrok, tmp dirs, sandbox DBs, compiled binaries
This commit is contained in:
2026-05-23 16:55:55 -03:00
parent 57920d45d6
commit 744868caa1
52 changed files with 4868 additions and 1068 deletions

View File

@@ -0,0 +1,110 @@
package config
import (
"os"
"path/filepath"
)
const (
defaultWorkspaceRoot = "/workspace"
defaultDataDirName = "data"
defaultDatabaseFile = "go-crm.db"
defaultWhatsAppStore = "whatsapp.db"
defaultHTTPEndpoint = "http://localhost:8080"
defaultInternalSecret = "internal-secret"
)
// WorkspaceRoot returns the path to the shared workspace. CRM_WORKSPACE_PATH overrides it.
// When no override is provided, we try to detect the workspace by walking up from the current
// working directory and looking for the typical monorepo layout. If that fails, we fall back
// to `../..` relative to the current directory and ultimately to `/workspace`.
func WorkspaceRoot() string {
if v := os.Getenv("CRM_WORKSPACE_PATH"); v != "" {
return filepath.Clean(v)
}
if candidate := detectWorkspaceRoot(); candidate != "" {
return candidate
}
if fallback := fallbackWorkspaceRoot(); fallback != "" {
return fallback
}
return defaultWorkspaceRoot
}
func detectWorkspaceRoot() string {
wd, err := os.Getwd()
if err != nil {
return ""
}
for dir := wd; ; {
if hasDir(dir, "data") && hasDir(dir, "apps") {
return filepath.Clean(dir)
}
parent := filepath.Dir(dir)
if parent == dir {
break
}
dir = parent
}
return ""
}
func fallbackWorkspaceRoot() string {
wd, err := os.Getwd()
if err != nil {
return ""
}
return filepath.Clean(filepath.Join(wd, "..", ".."))
}
func hasDir(dir, name string) bool {
info, err := os.Stat(filepath.Join(dir, name))
return err == nil && info.IsDir()
}
// DataDir returns the directory that stores SQLite files and related state. CRM_DATA_DIR overrides it.
// If a local ".dev-data" directory exists (for junior-friendly dev), it is preferred.
func DataDir() string {
if v := os.Getenv("CRM_DATA_DIR"); v != "" {
return filepath.Clean(v)
}
// prefer local .dev-data directory if present
if cwd, err := os.Getwd(); err == nil {
if info, err := os.Stat(filepath.Join(cwd, ".dev-data")); err == nil && info.IsDir() {
return filepath.Join(cwd, ".dev-data")
}
}
return filepath.Join(WorkspaceRoot(), defaultDataDirName)
}
// DatabasePath returns the path to the Go CRM SQLite database. CRM_DATABASE_PATH overrides it.
func DatabasePath() string {
if v := os.Getenv("CRM_DATABASE_PATH"); v != "" {
return filepath.Clean(v)
}
return filepath.Join(DataDir(), defaultDatabaseFile)
}
// WhatsAppStorePath returns the path where the Whatsmeow session DB is stored. CRM_WHATSAPP_STORE_PATH overrides it.
func WhatsAppStorePath() string {
if v := os.Getenv("CRM_WHATSAPP_STORE_PATH"); v != "" {
return filepath.Clean(v)
}
return filepath.Join(DataDir(), defaultWhatsAppStore)
}
// HTTPServerEndpoint returns the HTTP endpoint used when WhatsApp events need to call back to the Go server.
func HTTPServerEndpoint() string {
if v := os.Getenv("CRM_HTTP_ENDPOINT"); v != "" {
return v
}
return defaultHTTPEndpoint
}
// InternalSecret returns the internal secret required by the WhatsApp connector.
func InternalSecret() string {
if v := os.Getenv("CRM_INTERNAL_SECRET"); v != "" {
return v
}
return defaultInternalSecret
}