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
16 changes: 13 additions & 3 deletions backend/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,10 @@ const app = express();
// Connect to MongoDB Atlas
mongoose
.connect(process.env.MONGODB_URI)
.then(() => console.log("✅ MongoDB connected"))
seedAdminUser()
.then(() => {
console.log("✅ MongoDB connected");
seedAdminUser(); // ✅ Inside .then()
})
.catch((err) => console.error("❌ MongoDB connection error:", err));

app.use(cors());
Expand All @@ -54,9 +56,17 @@ const authRoutes = require("./routes/authRoutes");
const historyRoutes = require("./routes/historyRoutes");
const analyticsRoutes = require("./routes/analyticsRoutes");
const chatRoutes = require("./routes/chatRoutes");

// Versioned routes (v1)
app.use("/api/v1/auth", authRoutes);
app.use("/api/v1/history", historyRoutes);
app.use("/api/v1/analytics", analyticsRoutes);
app.use("/api/v1/chat", chatRoutes);

// Keep old routes for backward compatibility
app.use("/api/auth", authRoutes);
app.use("/api/history", historyRoutes);
app.use("/analytics", analyticsRoutes);
app.use("/api/analytics", analyticsRoutes);
app.use("/api/chat", chatRoutes);

const { protect } = require("./middleware/authMiddleware");
Expand Down
146 changes: 146 additions & 0 deletions docs/API.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
\# Spam Detection System - API Documentation



\## Base URL

http://localhost:3000/api/v1



\## Authentication

All protected endpoints require a Bearer token:

Authorization: Bearer <your\_token>



\## Auth Routes



| Method | Endpoint | Description | Auth |

|--------|----------|-------------|------|

| POST | `/auth/register` | Register new user | ❌ |

| POST | `/auth/login` | Login user | ❌ |

| GET | `/auth/profile` | Get user profile | ✅ |



\---



\## Prediction Routes



| Method | Endpoint | Description | Auth |

|--------|----------|-------------|------|

| POST | `/predict` | Predict spam/ham | ✅ |

| POST | `/bulk-predict` | Bulk spam detection | ✅ |

| POST | `/feedback` | Submit feedback | ✅ |

| POST | `/analyze-email-header` | Analyze email headers | ✅ |

| POST | `/bulk-predict/export` | Export predictions as CSV | ✅ |



\---



\## Analytics Routes



| Method | Endpoint | Description | Auth |

|--------|----------|-------------|------|

| GET | `/analytics/page-visits` | Page visit metrics | ✅ |

| GET | `/analytics/visits-by-role` | Visits by role | ✅ |



\---



\## Email Integration Routes



| Method | Endpoint | Description | Auth |

|--------|----------|-------------|------|

| GET | `/gmail/auth-url` | Get Gmail auth URL | ✅ |

| GET | `/gmail/emails` | Get Gmail emails | ✅ |

| GET | `/outlook/auth-url` | Get Outlook auth URL | ✅ |

| GET | `/outlook/emails` | Get Outlook emails | ✅ |

| POST | `/scan-emails` | Scan connected emails | ✅ |



\---



\## Public Routes



| Method | Endpoint | Description | Auth |

|--------|----------|-------------|------|

| GET | `/health` | Health check | ❌ |

| GET | `/api/wordcloud` | Word cloud data | ❌ |

| GET | `/importance` | Feature importance | ❌ |



\---



\## Response Format



\### Success Response

```json

{

&#x20; "success": true,

&#x20; "data": { ... }

}

```





Loading