Skip to main content

Database Schema Documentation

Database Schema Documentation

Charon uses SQLite with GORM ORM for data persistence. This document describes the database schema and relationships.

Overview

The database consists of 8 main tables:

  • ProxyHost
  • RemoteServer
  • CaddyConfig
  • SSLCertificate
  • AccessList
  • User
  • Setting
  • ImportSession

Entity Relationship Diagram

┌─────────────────┐
│ ProxyHost │
├─────────────────┤
│ UUID │◄──┐
│ Domain │ │
│ ForwardScheme │ │
│ ForwardHost │ │
│ ForwardPort │ │
│ SSLForced │ │
│ WebSocketSupport│ │
│ Enabled │ │
│ RemoteServerID │───┘ (optional)
│ CreatedAt │
│ UpdatedAt │
└─────────────────┘

│ 1:1

┌─────────────────┐
│ CaddyConfig │
├─────────────────┤
│ UUID │
│ ProxyHostID │
│ RawConfig │
│ GeneratedAt │
│ CreatedAt │
│ UpdatedAt │
└─────────────────┘

┌─────────────────┐
│ RemoteServer │
├─────────────────┤
│ UUID │
│ Name │
│ Provider │
│ Host │
│ Port │
│ Reachable │
│ LastChecked │
│ Enabled │
│ CreatedAt │
│ UpdatedAt │
└─────────────────┘

┌─────────────────┐
│ SSLCertificate │
├─────────────────┤
│ UUID │
│ Name │
│ DomainNames │
│ CertPEM │
│ KeyPEM │
│ ExpiresAt │
│ CreatedAt │
│ UpdatedAt │
└─────────────────┘

┌─────────────────┐
│ AccessList │
├─────────────────┤
│ UUID │
│ Name │
│ Addresses │
│ CreatedAt │
│ UpdatedAt │
└─────────────────┘

┌─────────────────┐
│ User │
├─────────────────┤
│ UUID │
│ Email │
│ PasswordHash │
│ IsActive │
│ IsAdmin │
│ CreatedAt │
│ UpdatedAt │
└─────────────────┘

┌─────────────────┐
│ Setting │
├─────────────────┤
│ UUID │
│ Key │ (unique)
│ Value │
│ CreatedAt │
│ UpdatedAt │
└─────────────────┘

┌─────────────────┐
│ ImportSession │
├─────────────────┤
│ UUID │
│ Filename │
│ State │
│ CreatedAt │
│ UpdatedAt │
└─────────────────┘

Table Details

ProxyHost

Stores reverse proxy host configurations.

ColumnTypeDescription
uuidUUIDPrimary key
domainTEXTDomain names (comma-separated)
forward_schemeTEXThttp or https
forward_hostTEXTTarget server hostname/IP
forward_portINTEGERTarget server port
ssl_forcedBOOLEANForce HTTPS redirect
http2_supportBOOLEANEnable HTTP/2
hsts_enabledBOOLEANEnable HSTS header
hsts_subdomainsBOOLEANInclude subdomains in HSTS
block_exploitsBOOLEANBlock common exploits
websocket_supportBOOLEANEnable WebSocket proxying
enabledBOOLEANProxy is active
remote_server_idUUIDForeign key to RemoteServer (nullable)
created_atTIMESTAMPCreation timestamp
updated_atTIMESTAMPLast update timestamp

Indexes:

  • Primary key on uuid
  • Foreign key index on remote_server_id

Relationships:

  • RemoteServer: Many-to-One (optional) - Links to remote Caddy instance
  • CaddyConfig: One-to-One - Generated Caddyfile configuration

RemoteServer

Stores remote Caddy server connection information.

ColumnTypeDescription
uuidUUIDPrimary key
nameTEXTFriendly name
providerTEXTgeneric, docker, kubernetes, aws, gcp, azure
hostTEXTHostname or IP address
portINTEGERPort number (default 2019)
reachableBOOLEANConnection test result
last_checkedTIMESTAMPLast connection test time
enabledBOOLEANServer is active
created_atTIMESTAMPCreation timestamp
updated_atTIMESTAMPLast update timestamp

Indexes:

  • Primary key on uuid
  • Index on enabled for fast filtering

CaddyConfig

Stores generated Caddyfile configurations for each proxy host.

ColumnTypeDescription
uuidUUIDPrimary key
proxy_host_idUUIDForeign key to ProxyHost
raw_configTEXTGenerated Caddyfile content
generated_atTIMESTAMPWhen config was generated
created_atTIMESTAMPCreation timestamp
updated_atTIMESTAMPLast update timestamp

Indexes:

  • Primary key on uuid
  • Unique index on proxy_host_id

SSLCertificate

Stores SSL/TLS certificates (future enhancement).

ColumnTypeDescription
uuidUUIDPrimary key
nameTEXTCertificate name
domain_namesTEXTDomains covered (comma-separated)
cert_pemTEXTCertificate in PEM format
key_pemTEXTPrivate key in PEM format
expires_atTIMESTAMPCertificate expiration
created_atTIMESTAMPCreation timestamp
updated_atTIMESTAMPLast update timestamp

AccessList

Stores IP-based access control lists (future enhancement).

ColumnTypeDescription
uuidUUIDPrimary key
nameTEXTList name
addressesTEXTIP addresses (comma-separated)
created_atTIMESTAMPCreation timestamp
updated_atTIMESTAMPLast update timestamp

User

Stores user authentication information (future enhancement).

ColumnTypeDescription
uuidUUIDPrimary key
emailTEXTEmail address (unique)
password_hashTEXTBcrypt password hash
is_activeBOOLEANAccount is active
is_adminBOOLEANAdmin privileges
created_atTIMESTAMPCreation timestamp
updated_atTIMESTAMPLast update timestamp

Indexes:

  • Primary key on uuid
  • Unique index on email

Setting

Stores application-wide settings as key-value pairs.

ColumnTypeDescription
uuidUUIDPrimary key
keyTEXTSetting key (unique)
valueTEXTSetting value (JSON string)
created_atTIMESTAMPCreation timestamp
updated_atTIMESTAMPLast update timestamp

Indexes:

  • Primary key on uuid
  • Unique index on key

Default Settings:

  • app_name: "Charon"
  • default_scheme: "http"
  • enable_ssl_by_default: "false"

ImportSession

Tracks Caddyfile import sessions.

ColumnTypeDescription
uuidUUIDPrimary key
filenameTEXTUploaded filename (optional)
stateTEXTparsing, reviewing, completed, failed
created_atTIMESTAMPCreation timestamp
updated_atTIMESTAMPLast update timestamp

States:

  • parsing: Caddyfile is being parsed
  • reviewing: Waiting for user to review/resolve conflicts
  • completed: Import successfully committed
  • failed: Import failed with errors

Database Initialization

The database is automatically created and migrated when the application starts. Use the seed script to populate with sample data:

cd backend
go run ./cmd/seed/main.go

Sample Seed Data

The seed script creates:

  • 4 remote servers (Docker registry, API server, web app, database admin)
  • 3 proxy hosts (app.local.dev, api.local.dev, docker.local.dev)
  • 3 settings (app configuration)
  • 1 admin user

Migration Strategy

GORM AutoMigrate is used for schema migrations:

db.AutoMigrate(
&models.ProxyHost{},
&models.RemoteServer{},
&models.CaddyConfig{},
&models.SSLCertificate{},
&models.AccessList{},
&models.User{},
&models.Setting{},
&models.ImportSession{},
)

This ensures the database schema stays in sync with model definitions.

Backup and Restore

Backup

# Backup default DB (charon.db). cpm.db will still be recognized for compatibility.
cp backend/data/charon.db backend/data/charon.db.backup

Restore

# Restore default DB (charon.db). cpm.db backup will still be recognized for compatibility.
cp backend/data/charon.db.backup backend/data/charon.db

Performance Considerations

  • Indexes: All foreign keys and frequently queried columns are indexed
  • Connection Pooling: GORM manages connection pooling automatically
  • SQLite Pragmas: PRAGMA journal_mode=WAL for better concurrency
  • Query Optimization: Use .Preload() for eager loading relationships

Future Enhancements

  • Multi-tenancy support with organization model
  • Audit log table for tracking changes
  • Certificate auto-renewal tracking
  • Integration with Let's Encrypt
  • Metrics and monitoring data storage