Coastal Timesheet v2 — full feature buildout

Features:
- Copy Previous Week (entries duplication)
- Bulk Approve/Reject (admin workflow)
- Overtime tracking (employee + admin views)
- DayCard component with auto-save
- PDF generation, email notifications
- React + Tailwind frontend, Prisma + PostgreSQL backend
- Docker deployment (3 containers)
This commit is contained in:
BizzleBot
2026-02-16 10:01:39 +00:00
commit f718a76153
65 changed files with 6756 additions and 0 deletions
+4
View File
@@ -0,0 +1,4 @@
DB_PASSWORD=coastal_secret
# Set to "true" to enable daily pg_dump backups
ENABLE_BACKUPS=false
BACKUP_DIR=/backups
+55
View File
@@ -0,0 +1,55 @@
# ───────────────────────────────────────────────────
# Coastal Timesheet — Backend Dockerfile
# Node 22 Alpine · Prisma · Express
# ───────────────────────────────────────────────────
# ── Stage 1: Install dependencies ──────────────────
FROM node:22-alpine AS deps
WORKDIR /app
# Copy package files
COPY backend/package.json backend/package-lock.json* ./
# Install production dependencies
RUN npm ci --omit=dev 2>/dev/null || npm install --omit=dev
# ── Stage 2: Build (generate Prisma client) ────────
FROM node:22-alpine AS builder
WORKDIR /app
# Copy deps from previous stage
COPY --from=deps /app/node_modules ./node_modules
COPY backend/ ./
# Generate Prisma client
RUN npx prisma generate
# ── Stage 3: Production image ─────────────────────
FROM node:22-alpine AS runner
WORKDIR /app
# Add non-root user for security
RUN addgroup --system --gid 1001 coastal && \
adduser --system --uid 1001 coastal
# Copy application
COPY --from=builder /app/node_modules ./node_modules
COPY --from=builder /app/prisma ./prisma
COPY --from=builder /app/src ./src
COPY --from=builder /app/package.json ./
# Switch to non-root user
USER coastal
# Expose port
EXPOSE 3001
# Health check
HEALTHCHECK --interval=30s --timeout=5s --start-period=30s --retries=3 \
CMD node -e "fetch('http://localhost:3001/api/health').then(r=>{if(!r.ok)throw 1}).catch(()=>process.exit(1))"
# Start with migration and seed on first run
CMD ["sh", "-c", "npx prisma db push --accept-data-loss 2>/dev/null; node prisma/seed.js 2>/dev/null; node src/index.js"]
+89
View File
@@ -0,0 +1,89 @@
version: '3.9'
services:
# ─── PostgreSQL ─────────────────────────────────────────
db:
image: postgres:16-alpine
container_name: coastal-db
restart: always
environment:
POSTGRES_USER: coastal
POSTGRES_PASSWORD: ${DB_PASSWORD:-coastal_secret}
POSTGRES_DB: coastal_timesheet
volumes:
- pgdata:/var/lib/postgresql/data
ports:
- '127.0.0.1:5432:5432'
healthcheck:
test: ['CMD-SHELL', 'pg_isready -U coastal -d coastal_timesheet']
interval: 10s
timeout: 5s
retries: 5
start_period: 10s
networks:
- coastal
# ─── Backend API ────────────────────────────────────────
backend:
build:
context: ../
dockerfile: docker/backend/Dockerfile
container_name: coastal-backend
restart: always
depends_on:
db:
condition: service_healthy
environment:
DATABASE_URL: postgresql://coastal:${DB_PASSWORD:-coastal_secret}@db:5432/coastal_timesheet
JWT_SECRET: ${JWT_SECRET:-change-me-in-production-jwt-secret-2026}
JWT_REFRESH_SECRET: ${JWT_REFRESH_SECRET:-change-me-in-production-refresh-secret-2026}
PORT: '3001'
NODE_ENV: ${NODE_ENV:-production}
CORS_ORIGINS: ${CORS_ORIGINS:-http://localhost,http://localhost:3000,http://100.94.106.120:8080}
SMTP_HOST: ${SMTP_HOST:-}
SMTP_PORT: ${SMTP_PORT:-587}
SMTP_USER: ${SMTP_USER:-}
SMTP_PASS: ${SMTP_PASS:-}
SMTP_FROM: ${SMTP_FROM:-}
ADMIN_EMAIL: ${ADMIN_EMAIL:-bizzle@coastalcontracting.com}
ports:
- '127.0.0.1:3001:3001'
healthcheck:
test: ['CMD', 'node', '-e', "fetch('http://localhost:3001/api/health').then(r=>{if(!r.ok)throw 1}).catch(()=>process.exit(1))"]
interval: 15s
timeout: 5s
retries: 3
start_period: 30s
networks:
- coastal
# ─── Frontend (Nginx) ──────────────────────────────────
frontend:
build:
context: ../
dockerfile: docker/frontend/Dockerfile
container_name: coastal-frontend
restart: always
depends_on:
backend:
condition: service_healthy
ports:
- '100.94.106.120:8080:80'
volumes:
- ./nginx/default.conf:/etc/nginx/conf.d/default.conf:ro
healthcheck:
test: ['CMD', 'wget', '--no-verbose', '--tries=1', '--spider', 'http://localhost:80/']
interval: 15s
timeout: 5s
retries: 3
start_period: 10s
networks:
- coastal
volumes:
pgdata:
driver: local
networks:
coastal:
driver: bridge
+56
View File
@@ -0,0 +1,56 @@
# ───────────────────────────────────────────────────
# Coastal Timesheet — Frontend Dockerfile
# Build: Node 22 Alpine → Serve: Nginx Alpine
# ───────────────────────────────────────────────────
# ── Stage 1: Install dependencies ──────────────────
FROM node:22-alpine AS deps
WORKDIR /app
# Copy package files (frontend lives in the frontend/ directory)
COPY frontend/package.json frontend/package-lock.json* ./
# Install all dependencies (including devDependencies for build)
RUN npm ci 2>/dev/null || npm install
# ── Stage 2: Build ────────────────────────────────
FROM node:22-alpine AS builder
WORKDIR /app
# Copy dependencies
COPY --from=deps /app/node_modules ./node_modules
# Copy frontend source
COPY frontend/ ./
# Set API URL for production build
ARG VITE_API_URL=/api
ENV VITE_API_URL=${VITE_API_URL}
# Build the React app
RUN npm run build
# ── Stage 3: Serve with Nginx ─────────────────────
FROM nginx:1.27-alpine AS runner
# Remove default nginx config and static files
RUN rm -rf /etc/nginx/conf.d/default.conf /usr/share/nginx/html/*
# Copy built frontend assets
COPY --from=builder /app/dist /usr/share/nginx/html
# The nginx config is mounted via docker-compose volume
# but we include a fallback in case it's run standalone
COPY docker/nginx/default.conf /etc/nginx/conf.d/default.conf
# Expose ports
EXPOSE 80 443
# Nginx runs as non-root by default in alpine image
# Health check
HEALTHCHECK --interval=30s --timeout=5s --retries=3 \
CMD wget --no-verbose --tries=1 --spider http://localhost:80/ || exit 1
CMD ["nginx", "-g", "daemon off;"]
+81
View File
@@ -0,0 +1,81 @@
# Coastal Timesheet — Nginx reverse proxy
# /api/* → backend:3001
# /* → frontend static files
upstream backend_api {
server backend:3001;
keepalive 16;
}
server {
listen 80;
listen [::]:80;
server_name _;
# Security headers
add_header X-Frame-Options "SAMEORIGIN" 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;
# Gzip compression
gzip on;
gzip_vary on;
gzip_proxied any;
gzip_comp_level 6;
gzip_min_length 256;
gzip_types
text/plain
text/css
text/xml
text/javascript
application/json
application/javascript
application/xml
application/rss+xml
image/svg+xml;
# Client body size (for file uploads if ever needed)
client_max_body_size 10m;
# ─── API proxy ───────────────────────────────────────
location /api/ {
proxy_pass http://backend_api;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
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;
proxy_cache_bypass $http_upgrade;
# Timeouts for PDF generation / email sending
proxy_read_timeout 60s;
proxy_connect_timeout 10s;
proxy_send_timeout 30s;
}
# ─── Frontend static files ───────────────────────────
location / {
root /usr/share/nginx/html;
index index.html;
# SPA fallback — serve index.html for client-side routes
try_files $uri $uri/ /index.html;
# Cache static assets aggressively
location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg|woff|woff2|ttf|eot)$ {
expires 1y;
add_header Cache-Control "public, immutable";
access_log off;
}
}
# ─── Health check endpoint for load balancer ─────────
location = /nginx-health {
access_log off;
return 200 'ok';
add_header Content-Type text/plain;
}
}