This repository contains the backend API for the Perplexity project.
The backend implementation is located in the backend/ folder and includes:
- User registration with email verification
- Authentication using JWT
- User profile and list endpoints
- Email delivery through Gmail OAuth2
- MongoDB data persistence with Mongoose
backend/src/app.js- Express application setup and middlewarebackend/src/routes/- Route definitions for auth, users, chats, and messagesbackend/src/controllers/- Request handlers and business logicbackend/src/models/- Mongoose schemas and data modelsbackend/src/services/- Email sending and other shared servicesbackend/.gitignore- Ignores local.envand other sensitive filesbackend/README.md- Backend-specific documentation and examples
- Install dependencies:
cd backend
npm install- Create a local
.envfile inbackend/with the required variables:
MONGO_URI=mongodb://127.0.0.1:27017/perplexitydb
PORT=4000
JWT_SECRET=change_this_secret_in_prod
GOOGLE_CLIENT_ID=<your-client-id>
GOOGLE_CLIENT_SECRET=<your-client-secret>
GOOGLE_REFRESH_TOKEN=<your-refresh-token>
GOOGLE_USER=you@example.com- Start the backend server:
npm startImportant: Do not commit
.envto git. Thebackend/.gitignorefile already excludes it.
Common API endpoints include:
POST /api/auth/register- Create a new user and send a verification emailPOST /api/auth/login- Authenticate a user and return a JWTPOST /api/auth/resend-verification- Resend email verification linkGET /api/users- List users (authenticated access)GET /api/users/:id- Fetch a specific user by ID
Example registration request:
curl -X POST http://localhost:4000/api/auth/register \
-H "Content-Type: application/json" \
-d '{"username":"alice","email":"alice@example.com","password":"password123"}'- The project uses
JWT_SECRETto sign authentication tokens. - Gmail OAuth credentials in
backend/.envmust remain secret. - If secrets are exposed, rotate or revoke them immediately in Google Cloud.
A GitHub Actions CI workflow is defined in .github/workflows/ci-cd.yml.
This workflow:
- Installs backend dependencies
- Starts a MongoDB service
- Runs backend tests if a
testscript exists
For complete backend documentation, troubleshooting tips, and more examples, see backend/README.md.