100 lines
2.9 KiB
Markdown
100 lines
2.9 KiB
Markdown
# Guardian AI Backend
|
|
|
|
A scalable, production-ready Node.js backend using Express, MySQL, and Sequelize, following a modular MVC architecture. Features include JWT authentication, role-based access, Stripe payments, real-time alerts, and more.
|
|
|
|
---
|
|
|
|
## Project Structure
|
|
|
|
```
|
|
├── public/ # Static files
|
|
├── src/
|
|
│ ├── config/ # App and DB config
|
|
│ ├── controllers/ # Route controllers
|
|
│ ├── middlewares/ # Express middlewares (auth, validation, etc.)
|
|
│ ├── migrations/ # Sequelize migrations
|
|
│ ├── models/ # Sequelize models
|
|
│ ├── routes/ # Express route definitions
|
|
│ ├── services/ # Business logic/services (Stripe, email, etc.)
|
|
│ ├── sockets/ # Socket.IO logic
|
|
│ ├── utils/ # Utility/helper functions
|
|
│ └── seeders/ # Sequelize seed scripts
|
|
├── .env.example # Example environment variables
|
|
├── package.json # Project dependencies and scripts
|
|
├── server.js # Main server entry point
|
|
```
|
|
|
|
---
|
|
|
|
## Getting Started
|
|
|
|
1. **Clone the repo:**
|
|
```bash
|
|
git clone <repo-url>
|
|
cd guardian-ai
|
|
```
|
|
2. **Install dependencies:**
|
|
```bash
|
|
npm install
|
|
```
|
|
3. **Configure environment:**
|
|
- Copy `.env.example` to `.env` and fill in your values.
|
|
4. **Run migrations & seeders:**
|
|
```bash
|
|
npx sequelize-cli db:migrate
|
|
npx sequelize-cli db:seed:all
|
|
```
|
|
5. **Start the server:**
|
|
```bash
|
|
npm run dev
|
|
```
|
|
6. **API Docs:**
|
|
- Visit [http://localhost:3000/api/v1/docs](http://localhost:3000/api/v1/docs) for Swagger API documentation.
|
|
|
|
---
|
|
|
|
## Authentication & Authorization
|
|
- Uses JWT for authentication.
|
|
- Role-based access: `admin`, `caregiver`, `patient`.
|
|
- Middleware in `src/middlewares/auth.js` protects routes and checks roles.
|
|
|
|
---
|
|
|
|
## Payments (Stripe)
|
|
- Stripe integration for subscriptions, invoices, and webhooks.
|
|
- All logic in `src/services/stripeService.js` and related controllers/routes.
|
|
|
|
---
|
|
|
|
## Real-Time & Notifications
|
|
- Uses Socket.IO for real-time caregiver alerts (`src/sockets/`).
|
|
- Weekly summary emails sent via Nodemailer (`src/services/weeklySummaryService.js`).
|
|
|
|
---
|
|
|
|
## Retell API Encryption
|
|
- All Retell API access is protected by an encrypted key.
|
|
- Use `src/utils/retellEncryption.js` to generate and verify keys (AES-256).
|
|
- Generate a key with:
|
|
```bash
|
|
node src/scripts/generateRetellKey.js '{"userId":123}'
|
|
```
|
|
- Add `RETELL_ENCRYPTION_KEY` (32 bytes) to your `.env`.
|
|
|
|
---
|
|
|
|
## Scripts
|
|
- `npm run dev` — Start in dev mode
|
|
- `npx sequelize-cli db:migrate` — Run migrations
|
|
- `npx sequelize-cli db:seed:all` — Seed test data
|
|
|
|
---
|
|
|
|
## Contributing
|
|
- See `CONTRIBUTING.md` and `CODE_OF_CONDUCT.md` for guidelines.
|
|
- Use Prettier and EditorConfig for code style.
|
|
|
|
---
|
|
|
|
## License
|
|
MIT — see `LICENSE` file. |