# Leads CRM

A full-stack CRM for tracking sales leads — built with Node.js + Express + SQLite (backend) and React + plain CSS (frontend).

---

## Installation

### Backend
```bash
cd leads-crm/backend
npm install
```

### Frontend
```bash
cd leads-crm/frontend
npm install
```

---

## Running

### Start Backend (port 3001)
```bash
cd leads-crm/backend
node server.js
```

### Start Frontend (port 3000)
```bash
cd leads-crm/frontend
npm start
```

Open [http://localhost:3000](http://localhost:3000) in your browser.

> The frontend proxies all `/api/*` requests to `http://localhost:3001` automatically.

---

## Features

- **Lead Management** — Create, view, edit, and delete leads
- **Lead Updates** — Per-lead update history with date, person, and details
- **Stats Bar** — Total, today's count, signed deals, and per-type breakdown
- **Filter & Search** — Filter by type, status, agent, system; full-text search by name/phone
- **Dark Theme UI** — Custom dark theme with color-coded badges and status indicators
- **Auto Seed** — 7 sample leads inserted on first run if database is empty
- **Signed Contract Toggle** — Toggle with optional signed date field
- **Updates Modal** — Per-lead update log with inline add/edit/delete

---

## Tracked Fields

### Leads

| Field               | Type    | Description                                               |
|---------------------|---------|-----------------------------------------------------------|
| `id`                | INTEGER | Auto-incremented primary key                              |
| `client_name`       | TEXT    | Full name of the client (optional)                        |
| `phone`             | TEXT    | Phone number (required)                                   |
| `lead_type`         | TEXT    | Cold Lead / Qualified / Mislead / Ready                   |
| `system`            | TEXT    | Ejar / Other / APP or Website / E-commerce / Garage System / Car Rental / call center |
| `channel`           | TEXT    | Whatsapp / Instagram / Call / Email / Walk-in             |
| `contact_person`    | TEXT    | Sales agent name                                          |
| `status`            | TEXT    | Canceled / Meeting / Signed Contract / Waiting his reply  |
| `called`            | TEXT    | Yes / No                                                  |
| `signed`            | INTEGER | 0 or 1 (boolean flag)                                     |
| `signed_date`       | TEXT    | Date of contract signing (YYYY-MM-DD)                     |
| `company_details`   | TEXT    | Free-form company background                              |
| `proposal_quotation`| TEXT    | Pricing / package details                                 |
| `created_at`        | TEXT    | Lead date (YYYY-MM-DD)                                    |
| `call_date`         | TEXT    | Scheduled call date (YYYY-MM-DD)                          |
| `created_ts`        | DATETIME| Auto timestamp on insert                                  |

### Lead Updates

| Field              | Type    | Description                        |
|--------------------|---------|------------------------------------|
| `id`               | INTEGER | Auto-incremented primary key        |
| `lead_id`          | INTEGER | Foreign key → leads.id              |
| `update_date`      | TEXT    | Date of the update (YYYY-MM-DD)     |
| `details`          | TEXT    | Free-form update text               |
| `interested_person`| TEXT    | Who is involved in this update      |
| `created_ts`       | DATETIME| Auto timestamp on insert            |

---

## Tech Stack

| Layer    | Technology                          |
|----------|-------------------------------------|
| Backend  | Node.js, Express, better-sqlite3    |
| Database | SQLite (leads.db)                   |
| Frontend | React 18 (Create React App), Axios  |
| Styling  | Plain CSS, Google Fonts (Syne + DM Sans) |
