API library for the Nexxus backend
npm install @mayhem93/nexxus-api-lib> REST API server for Nexxus - Authentication, device management, subscriptions, and model operations
---
The API package is the main entry point for client applications interacting with Nexxus. It provides RESTful endpoints for user authentication, device registration, subscription management, and CRUD operations on application models.
Key Responsibility: Validate requests and queue operations to worker pipeline (does not write app models directly to database).
---
- Local Strategy: Username/password with JWT tokens
- OAuth: Google authentication
- Optional Mode: Disable authentication for development/testing
- Device-specific Tokens: Each device gets unique JWT for security
- Register devices for receiving real-time updates
- Device information and status tracking
- Multi-device support per user
- Subscribe to channels (filtered or unfiltered)
- Unsubscribe from channels
- List active subscriptions per device
- Create: Queue model creation to Writer Worker
- Read: Direct database queries with FilterQuery support
- Update: Queue updates (JsonPatch) to Writer Worker
- Delete: Queue deletion to Writer Worker
Important: App model writes are queued, not executed directly. Only User model writes happen immediately.
---
```
Client Request
β
API Server (Express)
β
ββββββββββββββββββββββββ
β Authentication β β JWT validation
β Request Validation β β Schema checking
ββββββββββββββββββββββββ
β
ββββββββββββββββββββββββ
β Route Handlers β
β - /user/* β β Direct DB writes
β - /device/* β β Redis operations
β - /subscription/* β β Redis operations
β - /model/:type β β Queue to Writer
ββββββββββββββββββββββββ
β
Message Queue (RabbitMQ)
β
Writer Worker (processes queued operations)
---
- POST /user/register - Create new user accountPOST /user/login
- - Authenticate and get JWT tokenGET /user/profile
- - Get current user informationPATCH /user/profile
- - Update user profileDELETE /user/account
- - Delete user account
- POST /device/register - Register device for push notificationsGET /device/:deviceId
- - Get device informationDELETE /device/:deviceId
- - Unregister device
- POST /subscription - Subscribe to a channelDELETE /subscription/:subscriptionId
- - Unsubscribe from channelGET /subscription/device/:deviceId
- - List device subscriptions
- POST /model/:type - Create model instance (queued)GET /model/:type
- - Search/query model instancesGET /model/:type/:id
- - Get specific model instancePATCH /model/:type/:id
- - Update model instance (queued, JsonPatch)DELETE /model/:type/:id
- - Delete model instance (queued)
---
`typescript``
{
api: {
port: 3000,
auth: {
enabled: true,
strategies: ['local', 'google'],
jwt: {
secret: 'your-secret-key',
expiresIn: '7d'
},
google: {
clientId: 'your-google-client-id',
clientSecret: 'your-google-client-secret',
callbackURL: 'http://localhost:3000/auth/google/callback'
}
}
}
}
---
- Express - HTTP server framework
- Passport - Authentication middleware
- jsonwebtoken - JWT token generation/validation
- @mayhem93/nexxus-core - Shared models, types, FilterQuery
- @mayhem93/nexxus-database - Database operations
- @mayhem93/nexxus-message-queue - Queue operations to workers
- @mayhem93/nexxus-redis - Device and subscription storage
---
π§ Work in Progress - API surface may change as the project evolves.
---
- @mayhem93/nexxus-worker - Processes queued operations from API
- @mayhem93/nexxus-core - Shared types and models
- @mayhem93/nexxus-database - Database abstraction layer
---
MPL-2.0