# Aibit Backend

Express backend providing complete Jobs CRUD operations for the admin panel.

## Project Structure

```
Backend/
├── src/
│   ├── config/          # Configuration files
│   │   └── index.js
│   ├── constants/       # Application constants
│   │   └── index.js
│   ├── controllers/     # Request handlers
│   │   └── jobs.controller.js
│   ├── db/              # Database layer
│   │   └── lowdb.js
│   ├── middlewares/     # Express middlewares
│   │   └── errorHandler.js
│   ├── models/          # Data models and schemas
│   │   └── job.schema.js
│   ├── routes/          # API routes
│   │   ├── index.js
│   │   └── jobs.routes.js
│   ├── services/        # Business logic
│   │   └── jobs.service.js
│   ├── utils/           # Utility functions
│   │   ├── logger.js
│   │   └── response.js
│   ├── app.js           # Express app setup
│   └── server.js        # Server entry point
├── .env                 # Environment variables (create from .env.example)
├── .gitignore
├── package.json
└── README.md
```

## Setup

1. Install dependencies:

```bash
npm install
```

2. Create `.env` file for configuration:

```env
PORT=4000
NODE_ENV=development
CORS_ORIGIN=*
MONGO_URL=mongodb+srv://<user>:<password>@<cluster>/<db>?retryWrites=true&w=majority
CORS_ORIGIN=http://localhost:3000

# Zoom Meeting Integration (copy from aibit_soft/.env.local)
ZOOM_ACCOUNT_ID=your_zoom_account_id
ZOOM_CLIENT_ID=your_zoom_client_id
ZOOM_CLIENT_SECRET=your_zoom_client_secret
ZOOM_HOST_USER_ID=me

# Email Configuration (Optional - for sending meeting emails)
SMTP_HOST=smtp.gmail.com
SMTP_PORT=465
SMTP_USER=your_email@gmail.com
SMTP_PASS=your_app_password
ADMIN_EMAIL=admin@yourcompany.com
COMPANY_EMAIL=contact@yourcompany.com
```

**Note:** If you already have Zoom credentials configured in `aibit_soft/.env.local`, simply copy the `ZOOM_*` variables to this `Backend/.env` file. See `ZOOM_SETUP.md` for detailed instructions.

3. Start the development server:

```bash
npm run dev
```

4. Start the production server:

```bash
npm start
```

Server runs on http://localhost:4000 (or the port specified in `.env`)

## API Endpoints

### Health Check
- **GET** `/api/health` - Server health check

### Jobs CRUD

- **GET** `/api/jobs` - Get all jobs (sorted by creation date, newest first)
- **GET** `/api/jobs/:id` - Get a specific job by ID
- **POST** `/api/jobs` - Create a new job
- **PUT** `/api/jobs/:id` - Update an existing job
- **DELETE** `/api/jobs/:id` - Delete a job

### Request/Response Format

**Create Job (POST /api/jobs):**

Request Body:
```json
{
  "title": "Senior Full Stack Engineer",
  "department": "Engineering",
  "location": "Remote",
  "employmentType": "Full-time",
  "description": "Build scalable AI-powered solutions...",
  "responsibilities": ["Design and implement APIs", "Write clean code"],
  "requirements": ["4+ years with React/Next.js", "Experience with TypeScript"],
  "applicationUrl": "https://example.com/apply",
  "tags": "AI, React, Next.js" // or ["AI", "React", "Next.js"]
  "status": "Draft" // or "Published"
}
```

Success Response (201):
```json
{
  "success": true,
  "data": {
    "id": "uuid",
    "title": "Senior Full Stack Engineer",
    "department": "Engineering",
    "location": "Remote",
    "employmentType": "Full-time",
    "description": "...",
    "responsibilities": ["..."],
    "requirements": ["..."],
    "applicationUrl": "https://example.com/apply",
    "tags": ["AI", "React", "Next.js"],
    "status": "Draft",
    "createdAt": "2024-01-01T00:00:00.000Z",
    "updatedAt": "2024-01-01T00:00:00.000Z"
  }
}
```

**Update Job (PUT /api/jobs/:id):**

Same request body as create, but all fields are optional (partial update).

**List Jobs (GET /api/jobs):**

Success Response (200):
```json
{
  "success": true,
  "data": [
    {
      "id": "uuid",
      "title": "...",
      // ... other fields
    }
  ]
}
```

**Get Job (GET /api/jobs/:id):**

Success Response (200):
```json
{
  "success": true,
  "data": {
    "id": "uuid",
    // ... job fields
  }
}
```

**Delete Job (DELETE /api/jobs/:id):**

Success Response (204): No content

### Error Responses

All errors follow this format:
```json
{
  "success": false,
  "error": "Error message",
  "errors": {} // Optional validation errors
}
```

Status Codes:
- `400` - Bad Request (validation errors)
- `404` - Not Found
- `500` - Internal Server Error

## Data Storage

Data persists in your MongoDB cluster specified by `MONGO_URL`.

## Features

- ✅ Complete CRUD operations for jobs
- ✅ Input validation using Zod schemas
- ✅ Error handling middleware
- ✅ Request logging
- ✅ Environment variable configuration
- ✅ CORS support
- ✅ Consistent API response format
- ✅ Automatic database initialization

## Employment Types

- Full-time
- Part-time
- Contract
- Internship

## Job Status

- Draft
- Published

## Departments

- Engineering
- Design
- Marketing
- Sales
- Research
- Operations
- HR

