GITHUB REPO

Complete Developer Onboarding & Development Guide

🎯 Quick Start (5-minute setup)

gh repo clone Min11Benja/alertagas-twilio-sms
cd alertagas-twilio-sms
npm install
cp .env.example .env.local
# Fill environment variables (ask team lead)
npm run dev

📖 Table of Contents


🏗️ Architecture Overview

Tech Stack

  • Frontend: Next.js 14+ (TypeScript) + Tailwind CSS

  • Backend: Next.js API Routes + Server Components

  • Database: Supabase (PostgreSQL) with Row Level Security

  • SMS: Twilio Programmable SMS

  • Auth: Supabase Authentication

  • Deployment: Google Cloud Run + GitHub Actions

Data Flow

Core Features

  • ✅ Secure Twilio webhook validation with signature verification

  • ✅ SMS parsing and automatic sensor/client linking

  • ✅ Real-time dashboard with gas level monitoring

  • ✅ Multi-channel notifications (SMS + Email)

  • ✅ Multi-tenant architecture with RLS

  • ✅ Automated CI/CD with quality gates


⚙️ Prerequisites

Required Tools

  • Node.js 18+ (nvm use automatically selects correct version)

  • npm or pnpm (project uses npm by default)

  • Git + GitHub CLI (recommended)

  • VS Code with extensions:

    • ESLint, Prettier, TypeScript Hero

    • Tailwind CSS IntelliSense

    • Thunder Client (API testing)

Accounts Needed

  • Twilio Account with SMS-capable phone number

  • Supabase Project for database and auth

  • Google Cloud Project for deployment (production)


🔧 Environment Setup

1. Clone & Install

2. Environment Configuration

Copy the environment template and fill with your credentials:

Required Variables (get these from your team lead):

🔒 Security Note: Never commit .env.local or expose service role keys in client code.


🗃️ Database Setup

Automated Schema Setup

  1. Go to your Supabase project → SQL Editor

  2. Run the complete schema script from the expanded section below

  3. Verify setup with the provided validation query

chevron-right📋 Click to view complete SQL schemahashtag

Post-Setup Verification

Enable Real-time (Optional)

For live SMS updates in the dashboard:

  1. Supabase Dashboard → Database → Replication

  2. Enable Realtime for public.sms_messages table


📞 Twilio Configuration

1. Get Twilio Credentials

2. Buy a Phone Number

  • In Twilio Console: Phone Numbers → Manage → Buy a Number

  • Choose an SMS-capable number in your target region

3. Configure Webhook in Development

Twilio Webhook Setup:

  • Phone Numbers → Manage Numbers → [Your Number]

  • A message comes in: POSThttps://your-ngrok-url.ngrok.io/api/receive-sms

  • Status callback: (Optional) Same URL


🛠️ Development Workflow

Starting Development

Code Quality & Git Hooks

The project uses automated quality checks:

Pre-commit (automatically runs):

  • ESLint on staged files

  • TypeScript type checking

  • Prettier code formatting

  • Environment variable validation

Pre-push (automatically runs):

  • Full test suite

  • Build verification

CI/CD Pipeline (on every PR):

  • Full linting and type checking

  • Test suite execution

  • Build verification

  • Schema consistency checks

Branch & Commit Convention

Testing Your Setup

  1. Start services: npm run dev + ngrok http 3000

  2. Update Twilio with new ngrok URL

  3. Send test SMS to your Twilio number

  4. Verify:

    • SMS appears in Supabase sms_messages table

    • Message displays on http://localhost:3000

    • (If enabled) Real-time updates work automatically


🌐 API Reference

Core Endpoints

Endpoint
Method
Auth
Purpose

POST /api/receive-sms

POST

Twilio Signature

Receive & process inbound SMS

POST /api/send-sms

POST

Service Role

Send outbound SMS

GET /api/clients

GET

Browser (RLS)

List user's clients

GET /api/sensors

GET

Browser (RLS)

List sensors with search

GET /api/sms/messages

GET

Browser (RLS)

View SMS history

GET /api/gas_readings

GET

Browser (RLS)

Gas level time series

GET /api/settings

GET

Browser (RLS)

Get global settings

PATCH /api/settings

PATCH

Browser (RLS)

Update global settings

PATCH /api/alerts/:id

PATCH

Browser (RLS)

Resolve an alert

Webhook Example

Client-Side Query Example


📧 Notifications System

Multi-Channel Alerts

Alertagas supports multiple notification channels for low tank alerts:

  • SMS (Twilio) - Enabled by default

  • Email (Resend) - Optional

  • In-App (Real-time toasts) - Always enabled

Email Setup (Optional)

  1. Create an API key

  2. Add to .env.local:

  1. Enable email in Settings: /dashboard/settings/globales

Settings Configuration

Configure notifications at /dashboard/settings/globales:

  • Enable/disable SMS and email notifications

  • Set default alert threshold (default: 20%)

  • Configure email from address

  • Enable auto-resolution of alerts

Documentation

See docs/alertagas-context/007-notifications-system.mdarrow-up-right for complete documentation.


🚀 Deployment

Production Deployment (Google Cloud Run)

Prerequisites:

  • GCP Project with Cloud Run, Artifact Registry, and IAM APIs enabled

  • Service account with Cloud Run Admin and Service Account User roles

  • Workload Identity Federation configured for GitHub Actions

GitHub Secrets Required:

Deployment Process:

  • Automatic on push to main branch

  • Manual trigger via GitHub Actions UI

  • Health checks and rollback on failure

Getting Service URL


🐛 Troubleshooting

Common Issues & Solutions

Problem
Solution

Twilio 403 Signature Invalid

Verify TWILIO_AUTH_TOKEN matches Twilio console, check ngrok URL

SMS Not Saving to Database

Check service role key, verify API route uses admin client

No Real-time Updates

Enable replication on sms_messages table in Supabase

Environment Variables Not Loading

Restart dev server after editing .env.local

RLS Blocking Data Access

Verify user has profile with client_id, check policy conditions

Debug Tools

Getting Help

  1. Check application logs in browser console and terminal

  2. Examine Supabase logs in dashboard

  3. Use ngrok inspector to see webhook requests

Documentation

👉 Commander's Manual: How to Instruct Agentsarrow-up-right (Start Here!)

For full documentation, see docs/README.mdarrow-up-right.


🔒 Security Notes

  • Service Role Key: Never use in browser code - API routes only

  • Twilio Signatures: Always validate in webhook endpoints

  • RLS Policies: All tables have row-level security enabled

  • Environment Variables: Keep secure variables in .env.local only


📞 Support & Resources

Project Maintainer: Jossue Benjamin Martínez Juárez 📧 Email: [email protected]envelope 🐙 GitHub: @min11benjaarrow-up-right

Useful Links:


📄 License

MIT License - See LICENSE file for details.


🎯 Quick Reference

Last updated