# MSN Code Portal CRM V2 Project Guide

## Purpose

This is a full-stack CRM/admin platform for lead capture, sales management, invoices, reminders, finance reporting, SMTP settings, users, plans, and editable site content.

## Main Flow

1. Customer views plans on the homepage.
2. Customer selects a plan.
3. Selected plan is saved in browser storage for the preview and checkout flow.
4. Checkout submits customer/order data to the Express backend.
5. Backend stores customer, order, lead, status history, finance records, reminders, invoice records, and email logs in SQLite.
6. Backend sends customer/admin notifications through Nodemailer.
7. Admin users manage leads, sales, invoices, reminders, finance reports, site content, users, SMTP settings, and plans.

## Important Security Decisions

- No EmailJS.
- No card number, expiry, or CVV fields.
- No raw payment data stored in SQLite.
- Admin dashboard uses server-side session auth.
- Email sends from backend only.
- Finance/report exports are permission scoped.

## Key Locations

- Frontend app: `client/src/`
- Backend API: `server/`
- SQLite schema: `server/db/schema.sql`
- Email templates: `server/email-templates/`
- Admin CRM pages: `client/src/pages/AdminDashboard.jsx`, `AdminLeads.jsx`, `AdminSales.jsx`, `AdminInvoices.jsx`, `AdminReports.jsx`, and `AdminFinance.jsx`
- Release checklist: `RELEASE_CHECKLIST.md`
- Release manifest: generated by `npm run release:prepare`

## API Summary

- `GET /api/plans`
- `GET /api/plans/:id`
- `POST /api/orders`
- `GET /api/orders/:orderNumber`
- `POST /api/admin/login`
- `POST /api/admin/logout`
- `GET /api/admin/me`
- `GET /api/admin/stats`
- `GET /api/admin/orders`
- `GET /api/admin/orders/:id`
- `PATCH /api/admin/orders/:id/status`
- `PATCH /api/admin/orders/:id/notes`
- `GET /api/admin/leads`
- `GET /api/health`
