diff --git a/.env.example b/.env.example index 4abc3e3..8c71cd8 100644 --- a/.env.example +++ b/.env.example @@ -1,22 +1,47 @@ # Application Configuration # Copy this file to .env and update with your values -# Hostname for the application (e.g., https://awards.dj7nt.de) +# =================================================================== +# Environment +# =================================================================== +# Development: development +# Production: production +NODE_ENV=development + +# Log Level (debug, info, warn, error) +# Development: debug +# Production: info +LOG_LEVEL=debug + +# Server Port (default: 3001) +PORT=3001 + +# =================================================================== +# URLs +# =================================================================== +# Frontend URL (e.g., https://awards.dj7nt.de) # Leave empty for development (uses localhost) VITE_APP_URL= -# API Base URL (in production, can be same domain or separate) -# Leave empty to use relative paths (recommended for same-domain deployment) +# API Base URL (leave empty for same-domain deployment) +# Only set if API is on different domain VITE_API_BASE_URL= # Allowed CORS origins for backend (comma-separated) -# Only needed for production if not using same domain +# Add all domains that should access the API # Example: https://awards.dj7nt.de,https://www.awards.dj7nt.de ALLOWED_ORIGINS= -# JWT Secret (for production, use a strong random string) -# Generate with: openssl rand -base64 32 +# =================================================================== +# Security +# =================================================================== +# JWT Secret (REQUIRED for production) +# Development: uses default if not set +# Production: Generate with: openssl rand -base64 32 JWT_SECRET=change-this-in-production -# Node Environment -NODE_ENV=development +# =================================================================== +# Database (Optional) +# =================================================================== +# Leave empty to use default SQLite database +# DATABASE_URL=file:/path/to/custom.db diff --git a/.env.production.template b/.env.production.template deleted file mode 100644 index 7389809..0000000 --- a/.env.production.template +++ /dev/null @@ -1,30 +0,0 @@ -# Production Configuration Template -# Copy this file to .env.production and update with your production values - -# Application Environment -NODE_ENV=production - -# Log Level (debug, info, warn, error) -# Recommended: info for production -LOG_LEVEL=info - -# Server Port (default: 3001) -PORT=3001 - -# Frontend URL (e.g., https://awards.dj7nt.de) -VITE_APP_URL=https://awards.dj7nt.de - -# API Base URL (leave empty for same-domain deployment) -VITE_API_BASE_URL= - -# Allowed CORS origins (comma-separated) -# Add all domains that should access the API -ALLOWED_ORIGINS=https://awards.dj7nt.de,https://www.awards.dj7nt.de - -# JWT Secret (REQUIRED - generate a strong secret!) -# Generate with: openssl rand -base64 32 -JWT_SECRET=REPLACE_WITH_SECURE_RANDOM_STRING - -# Database (if using external database) -# Leave empty to use default SQLite database -# DATABASE_URL=file:/path/to/production.db diff --git a/CLAUDE.md b/CLAUDE.md index 94c4804..396d23f 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -77,58 +77,6 @@ test("hello world", () => { }); ``` -## Docker Deployment - -The application supports Docker deployment with single-port architecture and host-mounted database persistence. - -**Quick Start**: -```bash -# Create environment file -cp .env.docker.example .env - -# Generate JWT secret -openssl rand -base64 32 # Add to .env as JWT_SECRET - -# Start application -docker-compose up -d --build - -# Access at http://localhost:3001 -``` - -**Architecture**: -- **Single Port**: Port 3001 serves both API (`/api/*`) and frontend (all other routes) -- **Database Persistence**: SQLite database stored at `./data/award.db` on host -- **Auto-initialization**: Database created from template on first startup -- **Health Checks**: Built-in health monitoring at `/api/health` - -**Key Docker Files**: -- `Dockerfile`: Multi-stage build using official Bun runtime -- `docker-compose.yml`: Stack orchestration with volume mounts -- `docker-entrypoint.sh`: Database initialization logic -- `.env.docker.example`: Environment variable template -- `DOCKER.md`: Complete deployment documentation - -**Environment Variables**: -- `NODE_ENV`: Environment mode (default: production) -- `PORT`: Application port (default: 3001) -- `LOG_LEVEL`: Logging level (debug/info/warn/error) -- `JWT_SECRET`: JWT signing secret (required, change in production!) -- `VITE_APP_URL`: Your application's public URL -- `ALLOWED_ORIGINS`: CORS allowed origins (comma-separated) - -**Database Management**: -- Database location: `./data/award.db` (host-mounted volume) -- Backups: `cp data/award.db data/award.db.backup.$(date +%Y%m%d)` -- Reset: `docker-compose down -v && docker-compose up -d` - -**Important Notes**: -- Database persists across container restarts/recreations -- Frontend dependencies are reinstalled in container to ensure correct platform binaries -- Uses custom init script (`src/backend/scripts/init-db.js`) with `bun:sqlite` -- Architecture-agnostic (works on x86, ARM64, etc.) - -For detailed documentation, see `DOCKER.md`. - ## Frontend Use HTML imports with `Bun.serve()`. Don't use `vite`. HTML imports fully support React, CSS, Tailwind. diff --git a/README.md b/README.md index ac91c5c..dffda41 100644 --- a/README.md +++ b/README.md @@ -116,7 +116,7 @@ award/ │ └── package.json ├── award-definitions/ # Award rule definitions (JSON) ├── award.db # SQLite database (auto-created) -├── .env.production.template # Production configuration template +├── .env.example # Environment configuration template ├── bunfig.toml # Bun configuration ├── drizzle.config.js # Drizzle ORM configuration ├── package.json @@ -149,20 +149,32 @@ cp .env.example .env Edit `.env` with your configuration: ```env -# Application URL (for production deployment) -VITE_APP_URL=https://awards.dj7nt.de +# Environment (development/production) +NODE_ENV=development + +# Log Level (debug/info/warn/error) +LOG_LEVEL=debug + +# Server Port (default: 3001) +PORT=3001 + +# Frontend URL (e.g., https://awards.dj7nt.de) +# Leave empty for development (uses localhost) +VITE_APP_URL= # API Base URL (leave empty for same-domain deployment) VITE_API_BASE_URL= -# JWT Secret (generate with: openssl rand -base64 32) -JWT_SECRET=your-generated-secret-here +# Allowed CORS origins (comma-separated) +# Add all domains that should access the API +ALLOWED_ORIGINS= -# Environment -NODE_ENV=production +# JWT Secret (generate with: openssl rand -base64 32) +JWT_SECRET=change-this-in-production ``` -**For development**: You can leave `.env` empty or use defaults. +**For development**: Use defaults above. +**For production**: Set `NODE_ENV=production`, `LOG_LEVEL=info`, and generate a strong `JWT_SECRET`. 4. Initialize the database with performance indexes: ```bash @@ -414,20 +426,26 @@ bun run build Create `.env` in the project root: ```bash -# Application URL -VITE_APP_URL=https://awards.dj7nt.de - -# API Base URL (empty for same-domain) -VITE_API_BASE_URL= - -# JWT Secret (generate with: openssl rand -base64 32) -JWT_SECRET=your-generated-secret-here - # Environment NODE_ENV=production -# Database path (absolute path recommended) -DATABASE_PATH=/path/to/award/award.db +# Log Level (debug/info/warn/error) +LOG_LEVEL=info + +# Server Port (default: 3001) +PORT=3001 + +# Frontend URL +VITE_APP_URL=https://awards.dj7nt.de + +# API Base URL (leave empty for same-domain deployment) +VITE_API_BASE_URL= + +# Allowed CORS origins (comma-separated) +ALLOWED_ORIGINS=https://awards.dj7nt.de,https://www.awards.dj7nt.de + +# JWT Secret (generate with: openssl rand -base64 32) +JWT_SECRET=your-generated-secret-here ``` **Security**: Ensure `.env` has restricted permissions: