133 lines
No EOL
3.3 KiB
Markdown
133 lines
No EOL
3.3 KiB
Markdown
# Bridge Frontend
|
|
|
|
Frontend application for managing communication bridges between various messaging platforms and the CDR Link system.
|
|
|
|
## Overview
|
|
|
|
Bridge Frontend provides a web interface for configuring and managing communication channels including Signal, WhatsApp, Facebook, and Voice integrations. It handles bot registration, webhook configuration, and channel settings.
|
|
|
|
## Features
|
|
|
|
- **Channel Management**: Configure Signal, WhatsApp, Facebook, and Voice channels
|
|
- **Bot Registration**: Register and manage bots for each communication platform
|
|
- **Webhook Configuration**: Set up webhooks for message routing
|
|
- **Settings Management**: Configure channel-specific settings and behaviors
|
|
- **User Authentication**: Secure access with NextAuth.js
|
|
|
|
## Development
|
|
|
|
### Prerequisites
|
|
|
|
- Node.js >= 20
|
|
- npm >= 10
|
|
- PostgreSQL database
|
|
- Running bridge-worker service
|
|
|
|
### Setup
|
|
|
|
```bash
|
|
# Install dependencies
|
|
npm install
|
|
|
|
# Run database migrations
|
|
npm run migrate:latest
|
|
|
|
# Run development server
|
|
npm run dev
|
|
|
|
# Build for production
|
|
npm run build
|
|
|
|
# Start production server
|
|
npm run start
|
|
```
|
|
|
|
### Environment Variables
|
|
|
|
Required environment variables:
|
|
|
|
- `DATABASE_URL` - PostgreSQL connection string
|
|
- `DATABASE_HOST` - Database host
|
|
- `DATABASE_NAME` - Database name
|
|
- `DATABASE_USER` - Database username
|
|
- `DATABASE_PASSWORD` - Database password
|
|
- `NEXTAUTH_URL` - Application URL
|
|
- `NEXTAUTH_SECRET` - NextAuth.js secret
|
|
- `GOOGLE_CLIENT_ID` - Google OAuth client ID
|
|
- `GOOGLE_CLIENT_SECRET` - Google OAuth client secret
|
|
|
|
### Available Scripts
|
|
|
|
- `npm run dev` - Start development server
|
|
- `npm run build` - Build for production
|
|
- `npm run start` - Start production server
|
|
- `npm run lint` - Run ESLint
|
|
- `npm run migrate:latest` - Run all pending migrations
|
|
- `npm run migrate:down` - Rollback last migration
|
|
- `npm run migrate:up` - Run next migration
|
|
- `npm run migrate:make` - Create new migration
|
|
|
|
## Architecture
|
|
|
|
### Database Schema
|
|
|
|
The application manages the following main entities:
|
|
|
|
- **Bots**: Communication channel bot configurations
|
|
- **Webhooks**: Webhook endpoints for external integrations
|
|
- **Settings**: Channel-specific configuration settings
|
|
- **Users**: User accounts with role-based permissions
|
|
|
|
### API Routes
|
|
|
|
- `/api/auth` - Authentication endpoints
|
|
- `/api/[service]/bots` - Bot management for each service
|
|
- `/api/[service]/webhooks` - Webhook configuration
|
|
|
|
### Page Structure
|
|
|
|
- `/` - Dashboard/home page
|
|
- `/login` - Authentication page
|
|
- `/[...segment]` - Dynamic routing for CRUD operations
|
|
- `@create` - Create new entities
|
|
- `@detail` - View entity details
|
|
- `@edit` - Edit existing entities
|
|
|
|
## Integration
|
|
|
|
### Database Access
|
|
|
|
Uses Kysely ORM for type-safe database queries:
|
|
|
|
```typescript
|
|
import { db } from '@link-stack/database'
|
|
|
|
const bots = await db
|
|
.selectFrom('bots')
|
|
.selectAll()
|
|
.execute()
|
|
```
|
|
|
|
### Authentication
|
|
|
|
Integrated with NextAuth.js using database adapter:
|
|
|
|
```typescript
|
|
import { authOptions } from '@link-stack/auth'
|
|
```
|
|
|
|
## Docker Support
|
|
|
|
```bash
|
|
# Build image
|
|
docker build -t link-stack/bridge-frontend .
|
|
|
|
# Run with docker-compose
|
|
docker-compose -f docker/compose/bridge.yml up
|
|
```
|
|
|
|
## Related Services
|
|
|
|
- **bridge-worker**: Processes messages from configured channels
|
|
- **bridge-whatsapp**: WhatsApp-specific integration service
|
|
- **bridge-migrations**: Database schema management |