2.9 KiB
2.9 KiB
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
- Clone the repo:
git clone <repo-url> cd guardian-ai - Install dependencies:
npm install - Configure environment:
- Copy
.env.exampleto.envand fill in your values.
- Copy
- Run migrations & seeders:
npx sequelize-cli db:migrate npx sequelize-cli db:seed:all - Start the server:
npm run dev - API Docs:
- Visit 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.jsprotects routes and checks roles.
Payments (Stripe)
- Stripe integration for subscriptions, invoices, and webhooks.
- All logic in
src/services/stripeService.jsand 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.jsto generate and verify keys (AES-256). - Generate a key with:
node src/scripts/generateRetellKey.js '{"userId":123}' - Add
RETELL_ENCRYPTION_KEY(32 bytes) to your.env.
Scripts
npm run dev— Start in dev modenpx sequelize-cli db:migrate— Run migrationsnpx sequelize-cli db:seed:all— Seed test data
Contributing
- See
CONTRIBUTING.mdandCODE_OF_CONDUCT.mdfor guidelines. - Use Prettier and EditorConfig for code style.
License
MIT — see LICENSE file.