# Miracles In Motion - Complete Services and Endpoints Inventory

**Date**: December 26, 2025  
**Status**: ✅ **COMPREHENSIVE REVIEW COMPLETE**

---

## 📊 Deployment Overview

### Containers

| VMID | Hostname | Service Type | IP Address | Status |
|------|----------|--------------|------------|--------|
| 7810 | mim-web-1 | Web Frontend | 192.168.11.19 | ✅ Running |
| 7811 | mim-api-1 | API Backend | 192.168.11.8 | ✅ Running |

---

## 🌐 Public Access (via Cloudflare)

- **Domain**: https://mim4u.org
- **WWW**: https://www.mim4u.org (redirects to mim4u.org)
- **API Base**: https://mim4u.org/api

---

## 🔧 Services Running

### Web Container (7810 - mim-web-1)

| Service | Port | Status | Description |
|---------|------|--------|-------------|
| **Nginx** | 80 | ✅ Active | Web server serving static files and proxying API |
| **Cloudflare Tunnel** | - | ✅ Active | Secure tunnel to Cloudflare (4 connections) |
| **Prometheus Node Exporter** | 9100 | ✅ Active | Metrics exporter for monitoring |
| **SSH** | 22 | ✅ Active | SSH access |
| **DNS Resolver** | 53 | ✅ Active | Systemd-resolved |
| **SMTP** | 25 | ✅ Active | Postfix mail service |
| **Cloudflared Metrics** | 20241 | ✅ Active | Internal metrics endpoint |

### API Container (7811 - mim-api-1)

| Service | Port | Status | Description |
|---------|------|--------|-------------|
| **Azure Functions** | 3001 | ✅ Active | API backend service |
| **SSH** | 22 | ✅ Active | SSH access |
| **DNS Resolver** | 53 | ✅ Active | Systemd-resolved |
| **SMTP** | 25 | ✅ Active | Postfix mail service |

---

## 📍 Frontend Routes (Hash-based Routing)

### Public Pages

| Route | Path | Component | Access |
|-------|------|-----------|--------|
| Home | `/#/` | `HomePage` | Public |
| Donate | `/#/donate` | `DonatePage` | Public |
| Volunteers | `/#/volunteers` | `VolunteerPage` | Public |
| Sponsors | `/#/sponsors` | `SponsorsPage` | Public |
| Stories | `/#/stories` | `StoriesPage` | Public |
| Testimonies | `/#/testimonies` | `TestimoniesPage` | Public |
| Legal | `/#/legal` | `LegalPage` | Public |
| Request Assistance | `/#/request-assistance` | `AssistanceRequestPage` | Public |

### Portal Pages

| Route | Path | Component | Access Level |
|-------|------|-----------|--------------|
| Portals Hub | `/#/portals` | `PortalsPage` | Authenticated |
| Admin Portal | `/#/admin-portal` | `AdminPortalPage` | Admin only |
| Volunteer Portal | `/#/volunteer-portal` | `VolunteerPortalPage` | Volunteer, Admin |
| Resource Portal | `/#/resource-portal` | `ResourcePortalPage` | Resource, Admin |
| Analytics Dashboard | `/#/analytics` | `AnalyticsDashboard` | Admin only |
| AI Portal | `/#/ai-portal` | `AIPortalPage` | Admin, Volunteer |
| Advanced Analytics | `/#/advanced-analytics` | `AdvancedAnalyticsPage` | Admin |
| Mobile Volunteer | `/#/mobile-volunteer` | `MobileVolunteerPage` | Volunteer, Admin |
| Staff Training | `/#/staff-training` | `StaffTrainingPage` | Admin, Staff |

### Alternative Routes (AppNew.tsx)

| Route | Path | Component | Notes |
|-------|------|-----------|-------|
| AI Assistance | `/#/ai-assistance` | `AIAssistancePortal` | Alternative implementation |

---

## 🔌 API Endpoints

### Base URL
- **Internal**: `http://192.168.11.8:3001`
- **Via Proxy**: `http://192.168.11.19/api` or `https://mim4u.org/api`

### Donations API

#### `GET /api/donations`
Get list of donations with pagination and filtering.

**Query Parameters:**
- `page` (optional): Page number (default: 1)
- `limit` (optional): Items per page (default: 10)
- `status` (optional): Filter by status
- `program` (optional): Filter by program

**Response:**
```typescript
{
  success: true,
  data: Donation[],
  pagination: {
    page: number,
    limit: number,
    total: number,
    pages: number
  },
  timestamp: string
}
```

**Example:**
```bash
curl https://mim4u.org/api/donations?page=1&limit=10
```

#### `POST /api/donations`
Create a new donation.

**Request Body:**
```typescript
{
  amount: number,
  donorName: string,
  donorEmail: string,
  donorPhone?: string,
  program?: string,
  currency?: string,
  paymentMethod?: 'stripe' | 'check' | 'cash',
  notes?: string
}
```

**Response:**
```typescript
{
  success: true,
  data: {
    donationId: string,
    amount: number,
    status: 'pending' | 'processing' | 'completed' | 'failed',
    paymentIntentId?: string,
    createdAt: string
  },
  timestamp: string
}
```

**Example:**
```bash
curl -X POST https://mim4u.org/api/donations \
  -H "Content-Type: application/json" \
  -d '{
    "amount": 100,
    "donorName": "John Doe",
    "donorEmail": "john@example.com",
    "program": "general"
  }'
```

### Student Assistance AI API (Documented but may need implementation)

#### `POST /api/student-requests`
Process new student assistance requests through AI matching engine.

**Request Body:**
```typescript
{
  studentId: string,
  description: string,
  category: 'clothing' | 'supplies' | 'food' | 'transportation' | 'emergency',
  urgency: 'low' | 'medium' | 'high' | 'critical',
  constraints: {
    maxBudget?: number,
    timeframe: string,
    geographic?: {
      maxDistance: number,
      preferredAreas?: string[]
    }
  }
}
```

**Response:**
```typescript
{
  requestId: string,
  status: 'pending' | 'processing' | 'matched' | 'completed',
  matches: MatchResult[],
  estimatedCompletion: string,
  aiConfidence: number
}
```

#### `GET /api/requests/{requestId}/status`
Get real-time status of a student request.

#### `POST /api/ai/feedback`
Submit feedback for AI model improvement.

---

## 🔐 Authentication & Authorization

### Access Control (from staticwebapp.config.json)

| Route Pattern | Allowed Roles |
|---------------|---------------|
| `/api/*` | anonymous, authenticated |
| `/admin/*` | Admin |
| `/volunteer/*` | Volunteer, Admin |
| `/resource/*` | Resource, Admin |
| `/portals/*` | authenticated |
| `/analytics/*` | Admin |
| `/ai-portal/*` | Admin, Volunteer |

### Identity Provider
- **Azure Active Directory** (configured in staticwebapp.config.json)
- Client ID: From `AZURE_CLIENT_ID` environment variable
- Client Secret: From `AZURE_CLIENT_SECRET` environment variable

---

## 📡 Nginx Proxy Configuration

### Web Server (Port 80)
- **Root**: `/opt/miracles-in-motion/dist`
- **Index**: `index.html`
- **SPA Routing**: All routes fallback to `/index.html`

### API Proxy
- **Path**: `/api/*`
- **Proxy Target**: `http://192.168.11.8:3001`
- **Headers**: Upgraded for WebSocket support, X-Real-IP, X-Forwarded-For

---

## 🗄️ Backend Services

### Azure Functions (Container 7811)

**Runtime**: Node.js 18+  
**Framework**: Azure Functions v4  
**Port**: 3001  
**Host**: 0.0.0.0

**Functions Registered:**
1. `getDonations` - HTTP GET handler
2. `createDonation` - HTTP POST handler

**Dependencies:**
- Cosmos DB (donations, volunteers, programs containers)
- Azure Key Vault (secrets management)
- Stripe (payment processing)

---

## 📊 Monitoring Endpoints

### Prometheus Metrics
- **Endpoint**: `http://192.168.11.19:9100/metrics`
- **Service**: Prometheus Node Exporter
- **Purpose**: System and container metrics

### Cloudflared Metrics
- **Endpoint**: `http://127.0.0.1:20241/metrics` (internal)
- **Service**: Cloudflare Tunnel
- **Purpose**: Tunnel connection metrics

---

## 🔍 Service Discovery

### Internal Network

| Service | Container | Internal IP | Port | Protocol |
|---------|-----------|-------------|------|----------|
| Web Frontend | 7810 | 192.168.11.19 | 80 | HTTP |
| API Backend | 7811 | 192.168.11.8 | 3001 | HTTP |
| Monitoring | 7810 | 192.168.11.19 | 9100 | HTTP |

### External Access

| Service | Domain | Protocol | Notes |
|---------|--------|----------|-------|
| Web Application | https://mim4u.org | HTTPS | Via Cloudflare Tunnel |
| API Endpoints | https://mim4u.org/api | HTTPS | Proxied through Nginx |

---

## 📝 Configuration Files

### Web Container (7810)
- **Nginx Config**: `/etc/nginx/sites-available/miracles-in-motion`
- **Environment**: `/opt/miracles-in-motion/.env.production`
- **Cloudflare Config**: `/etc/cloudflared/config.yml`
- **Application Build**: `/opt/miracles-in-motion/dist`

### API Container (7811)
- **Service Config**: `/etc/systemd/system/mim-api.service`
- **Host Config**: `/opt/miracles-in-motion-api/host.json`
- **Application**: `/opt/miracles-in-motion-api/src`

---

## 🧪 Testing Endpoints

### Health Checks

```bash
# Web service
curl -I http://192.168.11.19
curl -I https://mim4u.org

# API service
curl http://192.168.11.8:3001/api/donations
curl https://mim4u.org/api/donations

# Monitoring
curl http://192.168.11.19:9100/metrics
```

### API Testing

```bash
# Get donations
curl https://mim4u.org/api/donations

# Create donation
curl -X POST https://mim4u.org/api/donations \
  -H "Content-Type: application/json" \
  -d '{
    "amount": 50,
    "donorName": "Test Donor",
    "donorEmail": "test@example.com"
  }'
```

---

## 📋 Complete Endpoint Summary

### Frontend Routes (15 routes)
- 8 Public pages
- 7 Portal/Authenticated pages

### API Endpoints (2 confirmed, 3 documented)
- 2 Active: `GET /api/donations`, `POST /api/donations`
- 3 Documented: Student assistance AI endpoints (may need implementation)

### Service Endpoints (3)
- Nginx web server (port 80)
- Azure Functions API (port 3001)
- Prometheus metrics (port 9100)

---

## ✅ Verification Status

- [x] All containers identified
- [x] All services documented
- [x] All frontend routes mapped
- [x] All API endpoints identified
- [x] Nginx proxy configuration reviewed
- [x] Monitoring endpoints documented
- [x] Access control rules documented

---

**Last Updated**: December 26, 2025  
**Platform**: Miracles In Motion  
**Domain**: mim4u.org  
**Status**: ✅ **COMPLETE INVENTORY**

