> For the complete documentation index, see [llms.txt](https://grouple.gitbook.io/docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://grouple.gitbook.io/docs/overview/system-architecture.md).

# System Architecture

### Architecture Overview

Grouple runs across four distinct infrastructure layers: AWS Amplify (frontend), AWS ECS (backend API), Supabase (database + serverless logic), and a dedicated EC2 instance (AI workers).

### Infrastructure Diagram

```
┌─────────────────────────────────────────────────────────────────┐
│  FRONTEND (AWS)                                                  │
│  GitHub → AWS Amplify → React + TypeScript (Vite)               │
│  grouple.pro via Route 53 + CloudFront CDN                       │
└─────────────────────────┬───────────────────────────────────────┘
                          │ API requests + JWT
                          ▼
┌─────────────────────────────────────────────────────────────────┐
│  BACKEND API (AWS)                                               │
│  Route 53 (api.grouple.pro)                                      │
│  → ALB (SSL Termination + ACM Certificate)                       │
│  → ECS Cluster (grouple-api-cluster)                             │
│     └── Auto Scaling Group (EC2 instances)                       │
│         └── ECS Tasks (API Containers via Docker/ECR)            │
│  AWS Secrets Manager → injects credentials                       │
│  CloudWatch Logs + X-Ray → observability                         │
└─────────────────────────┬───────────────────────────────────────┘
                          │ trigger task
                          ▼
┌─────────────────────────────────────────────────────────────────┐
│  AI WORKERS (Single EC2 Instance, PM2)                           │
│  ├── AI Proposal Worker (Node.js)                                │
│  │   └── Amazon Bedrock Claude 4.6 → generates proposals        │
│  └── PDF Extract Worker (Node.js)                                │
│      └── Amazon Bedrock Claude 4.6 → extracts menu/PDF data     │
│  Both workers save results → Supabase PostgreSQL                 │
└─────────────────────────────────────────────────────────────────┘

┌─────────────────────────────────────────────────────────────────┐
│  SUPABASE (Core Backend Logic)                                   │
│  ├── PostgreSQL (primary database, 20+ tables)                   │
│  ├── Auth (GoTrue / JWT)                                         │
│  ├── Email (via Edge Functions)                                  │
│  ├── 14 Database Triggers (automated business logic)             │
│  ├── 40+ RPC Functions (complex queries + operations)            │
│  ├── 6 Edge Functions (serverless compute)                       │
│  └── Storage (venue-images, Logos, venue-brochures)              │
└─────────────────────────────────────────────────────────────────┘
```

### [​](https://grouple.mintlify.app/architecture#key-design-decisions)Key Design Decisions <a href="#key-design-decisions" id="key-design-decisions"></a>

**Why Supabase for backend logic?** Supabase handles most business logic via database triggers and edge functions, keeping the ECS API lean. This means many operations (email sending, currency sync, settlement creation) happen automatically without hitting the API layer.

**Why a separate EC2 for AI workers?** AI proposal generation and PDF extraction are long-running, resource-intensive tasks. Running them on a dedicated EC2 instance with PM2 keeps them isolated from the main API and allows independent scaling.

**Why ECS + EC2 (not Fargate)?** Greater control over instance types and costs for a startup-scale workload.

### Domain Structure

<table><thead><tr><th width="268.85888671875">Domain</th><th>Points To</th></tr></thead><tbody><tr><td><code>grouple.pro</code></td><td>AWS Amplify (frontend)</td></tr><tr><td><code>api.grouple.pro</code></td><td>Application Load Balancer (backend API)</td></tr><tr><td><code>grouple.mintlify.app</code></td><td>This documentation</td></tr></tbody></table>


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://grouple.gitbook.io/docs/overview/system-architecture.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
