diff --git a/.env.example b/.env.example new file mode 100644 index 000000000..b9b6a039c --- /dev/null +++ b/.env.example @@ -0,0 +1,32 @@ +# ───────────────────────────────────────────────────────────────────────────── +# urBackend — Environment Variables +# Copy this file to .env and fill in your values before running docker-compose. +# ───────────────────────────────────────────────────────────────────────────── + +# Server +PORT=1234 +NODE_ENV=production + +# ── Database & Cache ────────────────────────────────────────────────────────── +# When using docker-compose, these are automatically overridden to point to +# internal service names (mongo, redis). You do NOT need to change these. +MONGO_URL=mongodb://mongo:27017/urbackend +REDIS_URL=redis://redis:6379 + +# ── Authentication ──────────────────────────────────────────────────────────── +JWT_SECRET=your_super_secret_jwt_key_min_32_chars +ENCRYPTION_KEY=32_character_long_string_for_byod_creds +API_KEY_SALT=your_random_api_key_salt + +# ── External Storage (Supabase) ─────────────────────────────────────────────── +# Required for file upload/storage features. +SUPABASE_URL=https://your-project.supabase.co +SUPABASE_KEY=your-supabase-anon-key + +# ── Email (Resend) ──────────────────────────────────────────────────────────── +# Required for OTP / email verification flow. +RESEND_API_KEY=re_your_resend_api_key +EMAIL_FROM=onboarding@resend.dev + +# ── Frontend ────────────────────────────────────────────────────────────────── +FRONTEND_URL=http://localhost:5173 diff --git a/backend/.dockerignore b/backend/.dockerignore new file mode 100644 index 000000000..e6697ebb5 --- /dev/null +++ b/backend/.dockerignore @@ -0,0 +1,7 @@ +node_modules +.env +*.log +tests/ +.git +.gitignore +npm-debug.log* diff --git a/backend/Dockerfile b/backend/Dockerfile new file mode 100644 index 000000000..0a502eff9 --- /dev/null +++ b/backend/Dockerfile @@ -0,0 +1,18 @@ +# ── Stage: Production ───────────────────────────────────────────────────────── +FROM node:20-alpine + +# Set working directory +WORKDIR /app + +# Install dependencies first (layer caching) +COPY package*.json ./ +RUN npm ci --omit=dev + +# Copy source +COPY . . + +# Expose backend port +EXPOSE 1234 + +# Start the server +CMD ["node", "app.js"] diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 000000000..0e6a8d50c --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,47 @@ + +services: + # ── MongoDB ─────────────────────────────────────────────────────────────────── + mongo: + image: mongo:7 + container_name: urbackend_mongo + restart: unless-stopped + ports: + - '27017:27017' + volumes: + - mongo_data:/data/db + + # ── Redis ───────────────────────────────────────────────────────────────────── + redis: + image: redis:latest + container_name: urbackend_redis + restart: unless-stopped + ports: + - '6379:6379' + volumes: + - redis_data:/data + + # ── Backend (Node.js) ───────────────────────────────────────────────────────── + backend: + build: + context: ./backend + dockerfile: Dockerfile + container_name: urbackend_api + restart: unless-stopped + ports: + - '1234:1234' + depends_on: + - mongo + - redis + env_file: + - path: .env + required: false + environment: + # Override DB URLs to use Docker service names + MONGO_URL: mongodb://mongo:27017/urbackend + REDIS_URL: redis://redis:6379 + NODE_ENV: production + PORT: 1234 + +volumes: + mongo_data: + redis_data: