mirror of
https://github.com/bckelley/cgm-remote-monitor.git
synced 2026-08-24 03:14:12 -05:00
Update project documentation with API details and configuration
Enhance `replit.md` to include comprehensive documentation on API endpoints (v1, v2, v3), authentication methods (API_SECRET, JWT), OpenAPI specs, Socket.IO channels, and environment variables. Replit-Commit-Author: Agent Replit-Commit-Session-Id: 748e831e-92ae-4927-9569-47665f47f29c Replit-Commit-Checkpoint-Type: full_checkpoint Replit-Commit-Event-Id: 759a1536-7b1b-4ce2-9972-168703ba4f7d Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/7ea4278b-5c6c-4065-9cb8-f1013771318d/748e831e-92ae-4927-9569-47665f47f29c/FO8cDm7 Replit-Helium-Checkpoint-Created: true
This commit is contained in:
@@ -1,49 +1,152 @@
|
||||
# Nightscout CGM Remote Monitor
|
||||
|
||||
## Overview
|
||||
Nightscout is a web-based CGM (Continuous Glucose Monitor) system allowing caregivers to remotely view a patient's glucose data in realtime. This is version 15.0.4 of the cgm-remote-monitor project.
|
||||
Nightscout is a web-based CGM (Continuous Glucose Monitor) system allowing caregivers to remotely view a patient's glucose data in realtime. Version 15.0.4 of the cgm-remote-monitor project.
|
||||
|
||||
## Current State
|
||||
- Project is set up and running on Replit
|
||||
- MongoDB is configured locally for development
|
||||
- Server runs on port 5000 with host 0.0.0.0
|
||||
- Running on Replit with MongoDB local development database
|
||||
- Server on port 5000 (0.0.0.0)
|
||||
- Webpack bundling for frontend assets
|
||||
- Three API versions available (v1, v2, v3)
|
||||
|
||||
## Project Structure
|
||||
- `lib/server/server.js` - Main application entry point
|
||||
- `lib/server/app.js` - Express application setup
|
||||
- `lib/server/env.js` - Environment configuration
|
||||
- `lib/api/` - REST API v1 endpoints
|
||||
- `lib/api2/` - REST API v2 endpoints
|
||||
- `lib/api3/` - REST API v3 endpoints
|
||||
- `lib/plugins/` - Nightscout plugins (ar2, basal, bolus, etc.)
|
||||
- `lib/storage/` - MongoDB storage adapters
|
||||
- `lib/client/` - Client-side code
|
||||
- `static/` - Static files (HTML, CSS, frontend assets)
|
||||
- `bundle/` - Webpack bundle source files
|
||||
- `webpack/` - Webpack configuration
|
||||
- `start.sh` - Startup script that launches MongoDB and the app
|
||||
```
|
||||
lib/
|
||||
├── server/ # Server core (server.js, app.js, env.js)
|
||||
├── api/ # REST API v1
|
||||
├── api2/ # REST API v2 (extends v1 + authorization)
|
||||
├── api3/ # REST API v3 (modern, OpenAPI 3.0)
|
||||
├── authorization/ # JWT auth, roles, subjects, permissions
|
||||
├── plugins/ # Feature plugins (ar2, basal, bolus, cob, iob, etc.)
|
||||
├── storage/ # MongoDB storage adapters
|
||||
├── client/ # Client-side code
|
||||
├── data/ # Data loading and processing
|
||||
└── report_plugins/ # Report generation
|
||||
|
||||
static/ # Frontend HTML, CSS, JS, assets
|
||||
bundle/ # Webpack bundle sources
|
||||
webpack/ # Webpack configuration
|
||||
docs/ # Plugin documentation
|
||||
start.sh # Startup script (MongoDB + app)
|
||||
```
|
||||
|
||||
## API Endpoints
|
||||
|
||||
### API v1 (`/api/v1`)
|
||||
| Endpoint | Description |
|
||||
|----------|-------------|
|
||||
| `/entries/*` | CGM entries (sgv, mbg, cal) |
|
||||
| `/treatments/*` | Treatment records |
|
||||
| `/profile/*` | User profiles |
|
||||
| `/devicestatus/*` | Device status |
|
||||
| `/food/*` | Food database |
|
||||
| `/activity/*` | Activity records |
|
||||
| `/notifications/*` | Notifications |
|
||||
| `/status/*` | Server status |
|
||||
| `/alexa/*` | Alexa integration |
|
||||
| `/googlehome/*` | Google Home integration |
|
||||
|
||||
### API v2 (`/api/v2`)
|
||||
Extends v1 with:
|
||||
| Endpoint | Description |
|
||||
|----------|-------------|
|
||||
| `/authorization/request/{token}` | Get JWT token |
|
||||
| `/authorization/subjects` | Manage subjects (CRUD) |
|
||||
| `/authorization/roles` | Manage roles (CRUD) |
|
||||
| `/authorization/permissions` | List permissions |
|
||||
| `/properties` | System properties |
|
||||
| `/ddata` | Data endpoints |
|
||||
| `/summary` | Summary data |
|
||||
|
||||
### API v3 (`/api/v3`)
|
||||
Modern REST API with OpenAPI 3.0 spec.
|
||||
|
||||
| Endpoint | Methods | Description |
|
||||
|----------|---------|-------------|
|
||||
| `/{collection}` | GET, POST | Search/create documents |
|
||||
| `/{collection}/{id}` | GET, PUT, PATCH, DELETE | CRUD by identifier |
|
||||
| `/{collection}/history/{lastModified}` | GET | Changes since timestamp |
|
||||
| `/version` | GET | API version |
|
||||
| `/status` | GET | API status |
|
||||
| `/lastModified` | GET | Last modification times |
|
||||
|
||||
**Collections:** entries, treatments, devicestatus, food, profile, settings
|
||||
|
||||
**Swagger UI:** Available at `/api3-docs`
|
||||
|
||||
## Authentication
|
||||
|
||||
### API v1
|
||||
- `API_SECRET` as SHA1 hash in header: `api-secret: <sha1-hash>`
|
||||
- Or token parameter: `?token=<sha1-hash>`
|
||||
|
||||
### API v2/v3 (JWT)
|
||||
1. Create subjects/roles in Admin Tools
|
||||
2. Get JWT: `GET /api/v2/authorization/request/{accessToken}`
|
||||
3. Use in header: `Authorization: Bearer <jwt>`
|
||||
|
||||
**Permissions format:** `api:<collection>:<action>`
|
||||
- Examples: `api:entries:read`, `api:treatments:create`, `api:*:*`
|
||||
|
||||
## Real-time Data (Socket.IO)
|
||||
|
||||
| Namespace | Purpose | Auth |
|
||||
|-----------|---------|------|
|
||||
| `/storage` | Data updates for collections | accessToken required |
|
||||
| `/alarm` | Alarm notifications | accessToken required |
|
||||
|
||||
## OpenAPI Specifications
|
||||
| File | Version |
|
||||
|------|---------|
|
||||
| `lib/server/swagger.yaml` | API v1 (14.2.3) |
|
||||
| `lib/api3/swagger.yaml` | API v3 (3.0.4) |
|
||||
|
||||
## Environment Variables
|
||||
- `PORT` - Server port (set to 5000)
|
||||
- `HOSTNAME` - Bind address (set to 0.0.0.0)
|
||||
- `MONGO_CONNECTION` - MongoDB connection string
|
||||
- `API_SECRET` - API authentication secret (minimum 12 characters)
|
||||
- `INSECURE_USE_HTTP` - Set to true for Replit proxy compatibility
|
||||
|
||||
## Running the Project
|
||||
The workflow automatically:
|
||||
1. Starts MongoDB with data stored in `/home/runner/data/db`
|
||||
2. Launches the Node.js server on port 5000
|
||||
### Core
|
||||
| Variable | Description | Default |
|
||||
|----------|-------------|---------|
|
||||
| `PORT` | Server port | 1337 |
|
||||
| `HOSTNAME` | Bind address | null |
|
||||
| `MONGO_CONNECTION` | MongoDB URI | - |
|
||||
| `API_SECRET` | Auth secret (min 12 chars) | - |
|
||||
| `INSECURE_USE_HTTP` | Allow HTTP (for proxies) | false |
|
||||
|
||||
### API v3
|
||||
| Variable | Description | Default |
|
||||
|----------|-------------|---------|
|
||||
| `API3_SECURITY_ENABLE` | Enable auth | true |
|
||||
| `API3_MAX_LIMIT` | Max docs per query | 1000 |
|
||||
| `API3_DEDUP_FALLBACK_ENABLED` | Dedup for legacy docs | true |
|
||||
|
||||
### Display
|
||||
| Variable | Description | Default |
|
||||
|----------|-------------|---------|
|
||||
| `DISPLAY_UNITS` | mg/dl or mmol | mg/dl |
|
||||
| `ENABLE` | Enabled plugins | - |
|
||||
|
||||
## Replit Configuration
|
||||
- `PORT=5000`, `HOSTNAME=0.0.0.0`
|
||||
- `INSECURE_USE_HTTP=true` (required for Replit proxy)
|
||||
- MongoDB at `mongodb://localhost:27017/nightscout`
|
||||
- Data stored in `/home/runner/data/db`
|
||||
|
||||
## NPM Scripts
|
||||
- `npm start` - Start production server
|
||||
- `npm run bundle` - Build webpack bundles
|
||||
- `npm run dev` - Start development server with nodemon
|
||||
- `npm test` - Run tests
|
||||
| Script | Description |
|
||||
|--------|-------------|
|
||||
| `npm start` | Production server |
|
||||
| `npm run bundle` | Webpack build |
|
||||
| `npm run dev` | Dev server with nodemon |
|
||||
| `npm test` | Run tests |
|
||||
|
||||
## Security Documentation
|
||||
- `lib/api3/doc/security.md` - Auth model
|
||||
- `lib/api3/doc/socket.md` - Storage socket
|
||||
- `lib/api3/doc/alarmsockets.md` - Alarm socket
|
||||
- `lib/api3/doc/tutorial.md` - API tutorial
|
||||
|
||||
## Recent Changes
|
||||
- 2025-12-31: Updated to version 15.0.4 (dev branch)
|
||||
- Configured for Replit environment with INSECURE_USE_HTTP=true
|
||||
- Uses MongoDB 3.6.x driver
|
||||
- Webpack bundling for frontend assets
|
||||
- Configured for Replit with INSECURE_USE_HTTP=true
|
||||
- MongoDB 3.6.x driver
|
||||
- Webpack bundling for frontend
|
||||
|
||||
Reference in New Issue
Block a user