Platform Architecture
A technical deep-dive into how AMS Platform is built โ from the multi-tenant database design to the queue system, caching strategy, and security model.
High-Level Architecture
React / Tailwind / App Router
iOS & Android / Expo
Webhooks / Zapier / API
Primary DB
Cache + Queues
File Storage
Email Delivery
Technology Stack
| Layer | Technology | Version | Purpose |
|---|---|---|---|
| Backend API | Laravel | 11.x | REST API, auth, business logic, queues |
| Frontend (Web) | Next.js + React | 15.x / 19.x | SPA + SSR, App Router, server components |
| Docs (Static) | Plain HTML + Tailwind CDN | โ | Documentation portal (this site) |
| Database | MySQL | 8.0+ | Primary relational data store |
| Cache / Queue | Redis | 7.x | Session cache, pub/sub, job queues |
| Web Server | Nginx | 1.18+ | Reverse proxy, SSL, static files |
| PHP Runtime | PHP-FPM | 8.2+ | Laravel application server |
| Auth | Laravel Sanctum | 3.x | SPA cookies + API tokens |
| Real-time | Laravel Echo + Pusher/Soketi | โ | WebSocket for chat & notifications |
| Storage | AWS S3 / MinIO / Local | โ | File uploads, avatars, documents |
| Payments | Stripe | v3 API | Dues, invoices, ticket sales |
| AWS SES / SendGrid / SMTP | โ | Transactional + bulk email | |
| AI | OpenAI GPT-4o | โ | AI Copilot, text generation |
| SMS | Twilio | โ | SMS campaigns and OTPs |
Multi-Tenant Database Design
AMS uses a shared database, shared schema multi-tenancy model. All tenants share the same MySQL database and tables. Every table that contains tenant-specific data has a tenant_id column.
Tenant isolation is enforced at the application level through a Global Query Scope that automatically appends WHERE tenant_id = ? to every Eloquent query. This scope is set at request boot time after the tenant is resolved from the incoming request.
-- Every tenant-scoped table follows this pattern: CREATE TABLE members ( id BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY, tenant_id VARCHAR(36) NOT NULL, -- Tenant isolation key ulid VARCHAR(26) NOT NULL UNIQUE, -- Public-facing ID email VARCHAR(255) NOT NULL, status ENUM('active','inactive','suspended') DEFAULT 'active', created_at TIMESTAMP, updated_at TIMESTAMP, INDEX idx_tenant_status (tenant_id, status), INDEX idx_tenant_email (tenant_id, email) );
DB::statement()), the global scope does NOT apply. Always include WHERE tenant_id = ? manually in raw queries, or use the Eloquent ORM.Frontend Architecture
The AMS web application is built with Next.js 15 using the App Router. It uses a hybrid rendering strategy:
- Server Components โ Data-heavy pages (member directory, reports) render on the server for performance
- Client Components โ Interactive UI (chat, forms, real-time updates) use client-side rendering
- Static HTML โ The documentation site (this site) is served as plain HTML for maximum speed and zero JS overhead
- API Route Handlers โ Next.js API routes proxy requests to the Laravel backend, hiding the API URL from the browser
API Design
The AMS REST API follows these conventions:
- Base URL:
https://yourdomain.ams.hkus1.s4s.host/api/v1/ - Versioning: URI versioning (
/v1/,/v2/). Breaking changes increment the version. - Auth: Bearer token (Sanctum) for all endpoints except
/auth/loginand/auth/register - Format: JSON request/response. Always set
Accept: application/json - Pagination: Cursor-based for large sets, offset for admin lists. Default page size: 25
- Errors: RFC 7807 Problem Details format with
type,title,status,detail
Caching Strategy
| Data | Cache Driver | TTL | Invalidation |
|---|---|---|---|
| User permissions | Redis | 15 min | On role change or logout |
| Tenant config | Redis | 60 min | On settings save |
| Member directory | Redis | 5 min | On member create/update/delete |
| Dashboard stats | Redis | 10 min | Scheduled refresh every 10 min |
| API responses | HTTP Cache-Control | Varies | ETags + Last-Modified headers |
| Session data | Redis | 2 hours | On logout or session expiry |
File Storage
AMS supports two storage backends configured via FILESYSTEM_DISK environment variable:
- Local โ Files stored on the server filesystem under
/storage/app/public/. Symlinked to/public/storage/viaphp artisan storage:link. Suitable for development and small deployments. - S3 โ Files stored in AWS S3 or any S3-compatible service (MinIO, Cloudflare R2). Files are served via pre-signed URLs with a 1-hour expiry. Recommended for production.
All uploaded files are stored with a path pattern of {tenant_id}/{type}/{uuid}.{ext} to maintain tenant isolation at the storage level.
Queue System
Long-running tasks are processed asynchronously via Laravel Queues backed by Redis. This keeps API responses fast and ensures reliability.
| Queue | Priority | Jobs Processed |
|---|---|---|
| high | Highest | Webhook delivery, payment confirmation, OTP SMS |
| default | Normal | Email sending, member import processing, PDF generation |
| low | Lowest | Report generation, bulk exports, analytics aggregation |
Queue workers are managed by Supervisor on the server, configured to restart automatically on failure. Failed jobs are stored in the failed_jobs table and can be retried via php artisan queue:retry all.
Security Overview
- TLS 1.3 enforced on all connections โ no HTTP downgrade
- CSRF protection on all stateful (web) routes via Laravel's CSRF middleware
- Rate limiting โ 60 req/min for authenticated users, 10 req/min for guests
- SQL injection prevention โ All queries use PDO prepared statements via Eloquent
- XSS prevention โ All output escaped via Blade templates; CSP headers enforced
- Secrets management โ All credentials in
.env, never committed to source control