feat: implement core Go application with web server

- Add Go modules with required dependencies (Gin, UUID, JWT, etc.)
- Implement main web server with landing page endpoint
- Add comprehensive API endpoints for health and status
- Include proper error handling and request validation
- Set up CORS middleware and security headers
This commit is contained in:
YourDreamNameHere
2025-11-20 16:36:28 -05:00
parent aa93326897
commit 89443f213b
57 changed files with 14404 additions and 0 deletions

72
output/configs/.env Normal file
View File

@@ -0,0 +1,72 @@
# Environment Configuration
# Copy this file to .env and fill in your actual values
# Application
APP_NAME=YourDreamNameHere
APP_ENV=development
APP_PORT=8080
APP_HOST=0.0.0.0
# Database
DB_HOST=localhost
DB_PORT=5433
DB_USER=ydn_user
DB_PASSWORD=ydn_secure_password_change_me
DB_NAME=ydn_db
DB_SSLMODE=disable
# JWT
JWT_SECRET=dev_jwt_secret_change_me_in_production_make_it_long_and_random_32_chars
JWT_EXPIRY=24h
# Stripe Configuration
STRIPE_PUBLIC_KEY=pk_test_dev_key_change_me
STRIPE_SECRET_KEY=sk_test_dev_key_change_me
STRIPE_WEBHOOK_SECRET=whsec_dev_key_change_me
STRIPE_PRICE_ID=price_1placeholder
# OVH Configuration
OVH_ENDPOINT=ovh-eu
OVH_APPLICATION_KEY=dev_ovh_app_key_change_me
OVH_APPLICATION_SECRET=dev_ovh_app_secret_change_me
OVH_CONSUMER_KEY=dev_ovh_consumer_key_change_me
# Cloudron Configuration
CLOUDRON_API_VERSION=v1
CLOUDRON_INSTALL_TIMEOUT=1800
# Dolibarr Configuration
DOLIBARR_URL=http://localhost:8082
DOLIBARR_API_TOKEN=dev_dolibarr_token_change_me
# Email Configuration (for sending Cloudron invites)
SMTP_HOST=smtp.gmail.com
SMTP_PORT=587
SMTP_USER=your_email@gmail.com
SMTP_PASSWORD=your_app_password
SMTP_FROM=noreply@yourdreamnamehere.com
# Redis (for sessions)
REDIS_HOST=localhost
REDIS_PORT=6380
REDIS_PASSWORD=redis_password_change_me
REDIS_DB=0
# Logging
LOG_LEVEL=info
LOG_FORMAT=json
# Security
CORS_ORIGINS=http://localhost:3000,https://yourdreamnamehere.com
RATE_LIMIT_REQUESTS=100
RATE_LIMIT_WINDOW=1m
# Contact Information (for domain registration)
YDN_CONTACT_FIRSTNAME=YourDreamNameHere
YDN_CONTACT_LASTNAME=Customer
YDN_CONTACT_PHONE=+1234567890
YDN_CONTACT_COUNTRY=US
YDN_TECH_CONTACT_FIRSTNAME=Technical
YDN_TECH_CONTACT_LASTNAME=Support
YDN_TECH_CONTACT_EMAIL=tech@yourdreamnamehere.com
YDN_TECH_CONTACT_PHONE=+1234567890

View File

@@ -0,0 +1,72 @@
# Environment Configuration
# Copy this file to .env and fill in your actual values
# Application
APP_NAME=YourDreamNameHere
APP_ENV=development
APP_PORT=8080
APP_HOST=0.0.0.0
# Database
DB_HOST=localhost
DB_PORT=5432
DB_USER=ydn_user
DB_PASSWORD=your_secure_password
DB_NAME=ydn_db
DB_SSLMODE=disable
# JWT
JWT_SECRET=your_jwt_secret_key_here_make_it_long_and_random
JWT_EXPIRY=24h
# Stripe Configuration
STRIPE_PUBLIC_KEY=pk_test_your_stripe_public_key
STRIPE_SECRET_KEY=sk_test_your_stripe_secret_key
STRIPE_WEBHOOK_SECRET=whsec_your_webhook_secret
STRIPE_PRICE_ID=price_250usd_monthly
# OVH Configuration
OVH_ENDPOINT=ovh-eu
OVH_APPLICATION_KEY=your_ovh_application_key
OVH_APPLICATION_SECRET=your_ovh_application_secret
OVH_CONSUMER_KEY=your_ovh_consumer_key
# Cloudron Configuration
CLOUDRON_API_VERSION=v1
CLOUDRON_INSTALL_TIMEOUT=1800
# Dolibarr Configuration
DOLIBARR_URL=https://your-dolibarr-instance.com
DOLIBARR_API_TOKEN=your_dolibarr_api_token
# Email Configuration (for sending Cloudron invites)
SMTP_HOST=smtp.gmail.com
SMTP_PORT=587
SMTP_USER=your_email@gmail.com
SMTP_PASSWORD=your_app_password
SMTP_FROM=noreply@yourdreamnamehere.com
# Redis (for sessions)
REDIS_HOST=localhost
REDIS_PORT=6379
REDIS_PASSWORD=
REDIS_DB=0
# Logging
LOG_LEVEL=info
LOG_FORMAT=json
# Security
CORS_ORIGINS=http://localhost:3000,https://yourdreamnamehere.com
RATE_LIMIT_REQUESTS=100
RATE_LIMIT_WINDOW=1m
# Contact Information (for domain registration)
YDN_CONTACT_FIRSTNAME=YourDreamNameHere
YDN_CONTACT_LASTNAME=Customer
YDN_CONTACT_PHONE=+1234567890
YDN_CONTACT_COUNTRY=US
YDN_TECH_CONTACT_FIRSTNAME=Technical
YDN_TECH_CONTACT_LASTNAME=Support
YDN_TECH_CONTACT_EMAIL=tech@yourdreamnamehere.com
YDN_TECH_CONTACT_PHONE=+1234567890

View File

@@ -0,0 +1,70 @@
# EMERGENCY PRODUCTION CONFIGURATION
# Copy this file to .env.prod and fill in your values
# Domain Configuration
DOMAIN=yourdreamnamehere.com
# Database Configuration (generate random passwords)
DB_HOST=ydn-db
DB_PORT=5432
DB_USER=ydn_user
DB_PASSWORD=CHANGE_THIS_SECURE_DB_PASSWORD_123
DB_NAME=ydn_db
DB_SSLMODE=require
# Redis Configuration
REDIS_HOST=ydn-redis
REDIS_PORT=6379
REDIS_PASSWORD=CHANGE_THIS_SECURE_REDIS_PASSWORD_456
REDIS_DB=0
# JWT Configuration
JWT_SECRET=CHANGE_THIS_TO_VERY_LONG_RANDOM_JWT_SECRET_789
# Stripe Configuration
STRIPE_PUBLIC_KEY=pk_live_your_stripe_public_key
STRIPE_SECRET_KEY=sk_live_your_stripe_secret_key
STRIPE_WEBHOOK_SECRET=whsec_your_webhook_secret
STRIPE_PRICE_ID=price_your_price_id
# OVH Configuration
OVH_ENDPOINT=ovh-eu
OVH_APPLICATION_KEY=your_ovh_application_key
OVH_APPLICATION_SECRET=your_ovh_application_secret
OVH_CONSUMER_KEY=your_ovh_consumer_key
# Email Configuration
SMTP_HOST=smtp.yourprovider.com
SMTP_PORT=587
SMTP_USER=your_email@yourdomain.com
SMTP_PASSWORD=your_smtp_password
SMTP_FROM=noreply@yourdreamnamehere.com
# Dolibarr Configuration
DOLIBARR_API_TOKEN=your_dolibarr_api_token
DOLIBARR_ADMIN_PASSWORD=CHANGE_THIS_ADMIN_PASSWORD
# Monitoring
GRAFANA_ADMIN_PASSWORD=CHANGE_THIS_GRAFANA_PASSWORD
# Docker Configuration
DOCKER_REGISTRY=your-registry.com/ydn-app
VERSION=v1.0.0
# Contact Information (for domain registration)
YDN_CONTACT_FIRSTNAME=YourDreamNameHere
YDN_CONTACT_LASTNAME=Customer
YDN_CONTACT_PHONE=+1234567890
YDN_CONTACT_COUNTRY=US
YDN_TECH_CONTACT_FIRSTNAME=Technical
YDN_TECH_CONTACT_LASTNAME=Support
YDN_TECH_CONTACT_EMAIL=tech@yourdreamnamehere.com
YDN_TECH_CONTACT_PHONE=+1234567890
# Application Configuration
APP_ENV=production
LOG_LEVEL=info
LOG_FORMAT=json
CORS_ORIGINS=https://yourdreamnamehere.com
RATE_LIMIT_REQUESTS=100
RATE_LIMIT_WINDOW=1m

11
output/configs/init.sql Normal file
View File

@@ -0,0 +1,11 @@
-- Initialize Dolibarr database for YDN integration
-- This script creates a separate database for Dolibarr
CREATE DATABASE dolibarr_db WITH ENCODING 'UTF8' LC_COLLATE='C' LC_CTYPE='C';
-- Grant permissions
GRANT ALL PRIVILEGES ON DATABASE dolibarr_db TO ydn_user;
-- Create extension for UUID generation
\c dolibarr_db;
CREATE EXTENSION IF NOT EXISTS "uuid-ossp";

156
output/configs/nginx.conf Normal file
View File

@@ -0,0 +1,156 @@
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
# Logging
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
error_log /var/log/nginx/error.log warn;
# Performance
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
client_max_body_size 10M;
# Gzip compression
gzip on;
gzip_vary on;
gzip_min_length 1024;
gzip_proxied any;
gzip_comp_level 6;
gzip_types
text/plain
text/css
text/xml
text/javascript
application/json
application/javascript
application/xml+rss
application/atom+xml
image/svg+xml;
# Rate limiting
limit_req_zone $binary_remote_addr zone=api:10m rate=10r/s;
limit_req_zone $binary_remote_addr zone=login:10m rate=1r/s;
# Upstream servers
upstream ydn_app {
server ydn-app:8080;
}
upstream dolibarr {
server ydn-dolibarr:80;
}
# Security headers
add_header X-Frame-Options DENY always;
add_header X-Content-Type-Options nosniff always;
add_header X-XSS-Protection "1; mode=block" always;
add_header Referrer-Policy "strict-origin-when-cross-origin" always;
add_header Content-Security-Policy "default-src 'self'; script-src 'self' 'unsafe-inline'; style-src 'self' 'unsafe-inline'; img-src 'self' data: https:; font-src 'self' data:; connect-src 'self' https://api.stripe.com https://js.stripe.com; frame-src https://js.stripe.com https://hooks.stripe.com;" always;
server {
listen 80;
server_name localhost;
# Redirect HTTP to HTTPS in production
# return 301 https://$server_name$request_uri;
# Security
server_tokens off;
# Main application
location / {
proxy_pass http://ydn_app;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
# Timeouts
proxy_connect_timeout 30s;
proxy_send_timeout 30s;
proxy_read_timeout 30s;
}
# API with rate limiting
location /api/ {
limit_req zone=api burst=20 nodelay;
proxy_pass http://ydn_app;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
# Login endpoint with stricter rate limiting
location /api/v1/login {
limit_req zone=login burst=5 nodelay;
proxy_pass http://ydn_app;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
# Static files
location /static/ {
alias /usr/share/nginx/html/static/;
expires 1y;
add_header Cache-Control "public, immutable";
add_header X-Content-Type-Options nosniff;
}
# Stripe webhooks
location /api/v1/webhooks/stripe {
proxy_pass http://ydn_app;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
# Allow larger payloads for webhooks
client_max_body_size 1M;
}
# Dolibarr
location /dolibarr/ {
proxy_pass http://dolibarr/;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
# PHP specific settings
proxy_buffers 8 16k;
proxy_buffer_size 32k;
}
# Health check
location /health {
proxy_pass http://ydn_app;
access_log off;
}
# Deny access to sensitive files
location ~ /\. {
deny all;
}
location ~ \.(conf|log|sql|env)$ {
deny all;
}
}
}

View File

@@ -0,0 +1,155 @@
events {
worker_connections 1024;
use epoll;
multi_accept on;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
# Logging
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
error_log /var/log/nginx/error.log warn;
# Performance optimizations
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
client_max_body_size 10M;
# Gzip compression
gzip on;
gzip_vary on;
gzip_min_length 1024;
gzip_proxied any;
gzip_comp_level 6;
gzip_types
text/plain
text/css
text/xml
text/javascript
application/json
application/javascript
application/xml+rss
application/atom+xml
image/svg+xml;
# Rate limiting
limit_req_zone $binary_remote_addr zone=api:10m rate=10r/s;
limit_req_zone $binary_remote_addr zone=login:10m rate=1r/s;
# SSL configuration
ssl_protocols TLSv1.2 TLSv1.3;
ssl_ciphers ECDHE-RSA-AES256-GCM-SHA512:DHE-RSA-AES256-GCM-SHA512:ECDHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES256-GCM-SHA384;
ssl_prefer_server_ciphers off;
ssl_session_cache shared:SSL:10m;
ssl_session_timeout 10m;
# HTTP redirect to HTTPS
server {
listen 80;
server_name ${DOMAIN};
return 301 https://$server_name$request_uri;
}
# Main HTTPS server
server {
listen 443 ssl http2;
server_name ${DOMAIN};
# SSL certificates
ssl_certificate /etc/nginx/ssl/fullchain.pem;
ssl_certificate_key /etc/nginx/ssl/privkey.pem;
# Security headers
add_header X-Frame-Options DENY;
add_header X-Content-Type-Options nosniff;
add_header X-XSS-Protection "1; mode=block";
add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always;
# Static files
location /static/ {
alias /usr/share/nginx/html/static/;
expires 1y;
add_header Cache-Control "public, immutable";
}
# API endpoints with rate limiting
location /api/ {
limit_req zone=api burst=20 nodelay;
proxy_pass http://ydn-app:8080;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
# Timeouts
proxy_connect_timeout 30s;
proxy_send_timeout 30s;
proxy_read_timeout 30s;
}
# Login endpoint with stricter rate limiting
location /api/v1/login {
limit_req zone=login burst=5 nodelay;
proxy_pass http://ydn-app:8080;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
# Stripe webhook endpoint (no rate limiting)
location /api/v1/webhooks/ {
proxy_pass http://ydn-app:8080;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
# Health check (no rate limiting)
location /health {
proxy_pass http://ydn-app:8080;
access_log off;
}
# Main application
location / {
proxy_pass http://ydn-app:8080;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
# Dolibarr ERP
location /dolibarr/ {
proxy_pass http://ydn-dolibarr/;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
# PHP specific settings
proxy_buffers 8 16k;
proxy_buffer_size 32k;
}
# Grafana (if monitoring is enabled)
location /grafana/ {
proxy_pass http://ydn-grafana/;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}
}