Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 66 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,71 @@ MailMERN/
git clone https://github.com/OPCODE-Open-Spring-Fest/MailMERN.git
cd MailMERN
```

## 🐳 Run with Docker (Recommended for Development & Testing)

You can now easily run the entire **MailMERN** stack (Frontend + Backend + MongoDB) using **Docker Compose** — no manual setup needed!

---

### 1️⃣ Prerequisites
Make sure you have these installed:
- [Docker](https://docs.docker.com/get-docker/)
- [Docker Compose](https://docs.docker.com/compose/install/)

---

### 2️⃣ Setup Environment Variables
Create a `.env` file inside the `backend/` folder (if not already present):

```env
PORT=5000
MONGO_URI=mongodb://mongo:27017/mailmern
[email protected]
EMAIL_PASS=your_app_password
OPENAI_API_KEY=your_openai_key

SMTP_HOST=smtp.gmail.com
SMTP_PORT=587
SMTP_SECURE=false # true for 465, false for 587
[email protected]
SMTP_PASS=your_app_password
EMAIL_FROM="MailMERN [email protected]"
[email protected]
NODE_ENV=development
```

### 3️⃣ Start the Containers

From the project root, run:

```bash
docker-compose up --build
```

This will:

🧩 Start the MongoDB container

⚙️ Run the Express backend on port 5000

💻 Serve the React frontend on port 5173

Once started:

Frontend: http://localhost:5173

Backend API: http://localhost:5000/api

### 4️⃣ Stopping Containers

To stop and remove all running containers, use:

```bash
docker-compose down
```
---
## Individual Setup
2️⃣ Backend Setup
```bash
cd backend
Expand All @@ -112,6 +177,7 @@ [email protected]
EMAIL_PASS=your_app_password
OPENAI_API_KEY=your_openai_key
```

Run the backend:
```bash
npm run dev
Expand Down
3 changes: 3 additions & 0 deletions backend/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node_modules
npm-debug.log
.DS_Store
12 changes: 12 additions & 0 deletions backend/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
FROM node:22-alpine

WORKDIR /app

COPY package*.json ./
RUN npm install

COPY . .

EXPOSE 5000

CMD ["npm", "run", "dev"]
1 change: 1 addition & 0 deletions backend/src/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const userRoutes = require('./routes/userRoutes');
const { errorMiddleware } = require('./middlewares/errorMiddleware');
const chatbotRoutes = require('./routes/chatbotRoutes');
const emailRoutes = require('./routes/emailRoutes');
const googleRoutes = require('./routes/googleRoute');
const trackRoutes = require('./routes/trackRoutes');
const { configDotenv } = require('dotenv');
const contactRoutes = require('./routes/contactRoutes');
Expand Down
40 changes: 40 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
services:
mongo:
image: mongo:6
container_name: mongo
restart: always
ports:
- "27017:27017"
volumes:
- mongo_data:/data/db

backend:
build: ./backend
container_name: mailmern_backend
ports:
- "5000:5000"
env_file:
- ./backend/.env
depends_on:
- mongo
volumes:
- ./backend:/app
- /app/node_modules
command: npm run dev

frontend:
build: ./frontend
container_name: mailmern_frontend
ports:
- "5173:5173"
stdin_open: true
tty: true
depends_on:
- backend
volumes:
- ./frontend:/app
- /app/node_modules
command: npm run dev

volumes:
mongo_data:
4 changes: 4 additions & 0 deletions frontend/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
node_modules
npm-debug.log
.env
.DS_Store
12 changes: 12 additions & 0 deletions frontend/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
FROM node:22-alpine

WORKDIR /app

COPY package*.json ./
RUN npm install

COPY . .

EXPOSE 5173

CMD ["npm", "run", "dev"]
2 changes: 1 addition & 1 deletion frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"version": "0.0.0",
"type": "module",
"scripts": {
"dev": "vite",
"dev": "vite --host 0.0.0.0",
"build": "vite build",
"lint": "eslint .",
"preview": "vite preview"
Expand Down
Loading