210 lines
3.9 KiB
Markdown
210 lines
3.9 KiB
Markdown
# SpurrinAI Backend
|
|
|
|
A Node.js backend application for SpurrinAI platform.
|
|
|
|
## Project Structure
|
|
|
|
```
|
|
project-root/
|
|
├── src/ # Source code
|
|
│ ├── app.js # App entry point
|
|
│ ├── config/ # Configuration files
|
|
│ ├── controllers/ # Route controllers
|
|
│ ├── middleware/ # Custom middleware
|
|
│ ├── migrations/ # Database migrations
|
|
│ ├── routes/ # Route definitions
|
|
│ ├── services/ # Business logic
|
|
│ └── utils/ # Utility functions
|
|
├── docs/ # Documentation
|
|
├── logs/ # Application logs
|
|
├── scripts/ # Build and setup scripts
|
|
├── tests/ # Test files
|
|
└── uploads/ # User uploads
|
|
```
|
|
|
|
## Prerequisites
|
|
|
|
- Node.js >= 14.0.0
|
|
- MySQL >= 5.7
|
|
- npm >= 6.0.0
|
|
|
|
## Installation
|
|
|
|
1. Clone the repository:
|
|
```bash
|
|
git clone https://git.tech4biz.wiki/rohit/spurrin-cleaned-backend-dev.git
|
|
cd spurrinai-backend
|
|
```
|
|
|
|
2. Install dependencies:
|
|
```bash
|
|
npm install
|
|
```
|
|
|
|
3. Set up environment variables:
|
|
```bash
|
|
cp .env.example .env
|
|
# Edit .env with your configuration
|
|
```
|
|
|
|
4. Run the setup script:
|
|
```bash
|
|
npm run setup
|
|
```
|
|
|
|
## Development Mode
|
|
|
|
1. Start the development server with hot-reload:
|
|
```bash
|
|
npm run dev
|
|
```
|
|
|
|
2. Run tests:
|
|
```bash
|
|
# Run all tests
|
|
npm test
|
|
|
|
# Run unit tests only
|
|
npm run test:unit
|
|
|
|
# Run integration tests only
|
|
npm run test:integration
|
|
```
|
|
|
|
3. Code Quality:
|
|
```bash
|
|
# Lint code
|
|
npm run lint
|
|
|
|
# Fix linting issues
|
|
npm run lint:fix
|
|
|
|
# Format code
|
|
npm run format
|
|
```
|
|
|
|
## Production Mode
|
|
|
|
1. Build the application:
|
|
```bash
|
|
npm run build
|
|
```
|
|
|
|
2. Start the production server:
|
|
```bash
|
|
npm start
|
|
```
|
|
|
|
3. For production deployment, ensure:
|
|
- Set `NODE_ENV=production` in `.env`
|
|
- Configure proper database credentials
|
|
- Set up SSL/TLS certificates
|
|
- Configure proper logging
|
|
- Set up process manager (PM2 recommended)
|
|
|
|
### Using PM2 (Recommended for Production)
|
|
|
|
1. Install PM2 globally:
|
|
```bash
|
|
npm install -g pm2
|
|
```
|
|
|
|
2. Start the application with PM2:
|
|
```bash
|
|
pm2 start src/app.js --name spurrinai-backend
|
|
```
|
|
|
|
3. Other useful PM2 commands:
|
|
```bash
|
|
# Monitor application
|
|
pm2 monit
|
|
|
|
# View logs
|
|
pm2 logs spurrinai-backend
|
|
|
|
# Restart application
|
|
pm2 restart spurrinai-backend
|
|
|
|
# Stop application
|
|
pm2 stop spurrinai-backend
|
|
|
|
# Flush logs
|
|
pm2 flush
|
|
|
|
# Delete all logs
|
|
pm2 flush spurrinai-backend
|
|
|
|
# Reload application with zero downtime
|
|
pm2 reload spurrinai-backend
|
|
```
|
|
|
|
## Database Migrations
|
|
|
|
```bash
|
|
# Create new migration
|
|
npm run migrate:create
|
|
|
|
# Run all migrations
|
|
npm run migrate
|
|
|
|
# Run migrations up
|
|
npm run migrate:up
|
|
|
|
# Run migrations down
|
|
npm run migrate:down
|
|
```
|
|
|
|
## API Documentation
|
|
|
|
Detailed API documentation can be found in the [docs/API.md](docs/API.md) file.
|
|
|
|
## Environment Variables
|
|
|
|
Required environment variables in `.env`:
|
|
|
|
```env
|
|
# Server Configuration
|
|
PORT=3000
|
|
NODE_ENV=development
|
|
|
|
# Database Configuration
|
|
DB_HOST=localhost
|
|
DB_USER=root
|
|
DB_PASSWORD=Admin@123
|
|
DB_NAME=spurrintest
|
|
|
|
# JWT Configuration
|
|
JWT_ACCESS_TOKEN_SECRET=jN4!pY9*d#T2@x$L7wq&Z8^gFc%X5@K#m
|
|
JWT_REFRESH_TOKEN_SECRET=Lx$Z7#T2^d&n9!Y4%K8@Fcg*m#qX5p@wL
|
|
JWT_ACCESS_TOKEN_EXPIRY=5h
|
|
JWT_REFRESH_TOKEN_EXPIRY=7d
|
|
|
|
# Email Configuration
|
|
EMAIL_HOST="smtp.zoho.com"
|
|
SENDER_PORT = 465
|
|
SENDER_SECURITY = true
|
|
EMAIL_USER="kavya.j@tech4biz.io"
|
|
EMAIL_PASS="8pQfkBw8gbrz"
|
|
|
|
# File Upload Configuration
|
|
UPLOAD_DIR=uploads
|
|
MAX_FILE_SIZE=5242880 # 5MB
|
|
```
|
|
|
|
# urls and certificates
|
|
BACK_URL = http://localhost:3000/
|
|
DOMAIN_url = http://localhost:3000/
|
|
FLASK_BASE_URL = http://localhost:5000/
|
|
|
|
SSL_CERT = "/home/ubuntu/spurrin-cleaned-node/certificates/fullchain.pem"
|
|
SSL_KEY = "/home/ubuntu/spurrinai-backend-node/certificates/privkey.pem"
|
|
|
|
## Support
|
|
|
|
For support, please contact:
|
|
- Email: contact@tech4biz.io
|
|
- Issue Tracker: GitHub Issues
|
|
|
|
## License
|
|
|
|
UNLICENSED - All rights reserved by Tech4biz Solutions |