# agile-growth-hackers/agile-productions architecture

> Architecture diagram of the GitHub repository agile-growth-hackers/agile-productions, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-04-09). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/agile-growth-hackers/agile-productions
- Repository: https://github.com/agile-growth-hackers/agile-productions

## Overview

1. **Top-level shape**
   - This repo is a two-part application: a **React frontend** in `frontend/` and a **Cloudflare Workers backend** in `workers/`.
   - The frontend is deployed to **Cloudflare Pages**; the backend is deployed to the **Cloudflare edge** as an API.

2. **Frontend boundary**
   - The frontend is a single SPA built with **React + Vite**.
   - It contains both the **public website** and the **admin dashboard** in the same client app, separated by routing and protected admin routes.
   - Public UI is composed from page sections like `Hero`, `About`, `Services`, `Gallery`, `Clients`, `Navbar`, and `Footer`.

3. **Admin UI subsystem**
   - Admin functionality lives under `frontend/src/admin/`.
   - It includes content editors and management panels for sliders, galleries, logos, page content, services, team members, section images, regions, users, profile, and activity logs.
   - The admin area uses reusable modals, drag-and-drop cards, a rich text editor, and a region switcher to manage region-specific content.

4. **Client-side data flow**
   - The frontend talks to the backend through a dedicated API layer in `frontend/src/services/api.js`.
   - State is coordinated through React contexts such as `AuthContext`, `RegionContext`, and `ToastContext`.
   - Hooks like `usePageContent` and `useSectionImages` fetch CMS-style content for the public pages, while the admin UI performs authenticated writes.

5. **Backend API boundary**
   - The backend is organized as a set of **resource routes** in `workers/src/routes/`.
   - Route groups map closely to the domain model: `auth`, `slider`, `gallery`, `logos`, `storage`, `users`, `activity-logs`, `page-content`, `services`, `team`, `section-images`, `regions`, and `profile`.
   - This makes the API the main boundary between public content delivery and administrative content management.

6. **Backend request pipeline**
   - Requests pass through layered middleware for **CORS, CSRF, HTTPS enforcement, rate limiting, request size limits, RBAC, auth, region handling, validation, and security headers**.
   - This indicates a security-first edge API, with separate controls for public read endpoints and admin write endpoints.
   - JWT-based authentication is used for admin sessions.

7. **Persistence and storage**
   - Structured data is stored in **Cloudflare D1 (SQLite)**.
   - The schema is centered around content and admin entities: slider images, gallery images, logos, page content, services, team members, section images, regions, admins, users, and activity logs.
   - Media files are stored in **Cloudflare R2**, which serves as the binary asset layer for uploaded images and profile pictures.

8. **Region-aware content model**
   - Multi-region support is a first-class architectural concern.
   - The frontend has a region switcher, and the backend has region config and region middleware.
   - Content tables and API endpoints are region-scoped, so the same site can serve different content sets for domains like India and UAE without changing the app structure.

9. **Media processing and content safety**
   - Image handling is not just upload/download; the backend includes utilities for file validation, MIME checking, WebP conversion, and optional TinyPNG compression.
   - Rich text content is sanitized before rendering, and the frontend also uses DOMPurify for safe HTML output.
   - This creates a clear trust boundary around user-generated content and media uploads.

10. **Operational and audit layer**
   - Admin actions are recorded through an activity logging subsystem, which is exposed to super admins.
   - There is also profile management and user management, with role-based access separating normal admins from super admins.
   - This means the system tracks both content changes and administrative accountability.

11. **Public runtime concerns**
   - The frontend includes PWA support, update/install prompts, error boundary handling, and monitoring hooks such as Sentry and web vitals.
   - These pieces support a production-facing experience with offline/installability and client-side resilience.

12. **CI/CD and maintenance**
   - GitHub Actions provide separate pipelines for frontend, backend, and database backup.
   - Database migrations live under `workers/migrations/`, and utility scripts support seeding, local admin creation, deployment verification, and test users.
   - Testing is split by layer: Playwright for frontend E2E and Vitest for backend utilities.

13. **How to draw the architecture**
   - A good diagram would show: **browser → React SPA → Cloudflare Workers API → D1/R2**, with a separate admin path overlaying the same frontend and API.
   - The main trust boundaries are **public vs authenticated admin routes**, and **client UI vs edge API vs persistent storage**.

Main entry points: [`frontend/src/App.jsx`](https://github.com/agile-growth-hackers/agile-productions/blob/main/frontend/src/App.jsx) (React SPA), [`workers/src/middleware`](https://github.com/agile-growth-hackers/agile-productions/tree/main/workers/src/middleware) (Middleware Stack), [`workers/src/routes`](https://github.com/agile-growth-hackers/agile-productions/tree/main/workers/src/routes) (Content Routes), [`workers/migrations`](https://github.com/agile-growth-hackers/agile-productions/tree/main/workers/migrations) (D1 Schema)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["Frontend"]
  node_spa["React SPA<br/>frontend shell<br/>[App.jsx]"]
  node_public_ui["Public Site<br/>ui"]
  node_admin_ui["Admin Console<br/>ui"]
  node_auth_ctx["Auth Context<br/>state<br/>[AuthContext.jsx]"]
  node_region_ctx["Region Context<br/>state<br/>[RegionContext.jsx]"]
  node_toast_ctx["Toast Context<br/>state<br/>[ToastContext.jsx]"]
  node_api_client["API Client<br/>http layer<br/>[api.js]"]
  node_public_hooks["Content Hooks<br/>data hooks"]
  node_rich_ui["Admin Widgets<br/>editor components"]
end

subgraph group_backend["Backend"]
  node_edge_api["Workers API<br/>edge app<br/>[index.js]"]
  node_middleware["Middleware Stack<br/>request pipeline"]
  node_auth_routes["Auth Routes<br/>route group<br/>[auth.js]"]
  node_content_routes["Content Routes<br/>route group"]
  node_admin_routes["Admin Routes<br/>route group"]
  node_storage_routes["Storage Routes<br/>route group<br/>[storage.js]"]
  node_media_utils["Media Safety<br/>validation + transform"]
  node_content_safety["Sanitization<br/>security utils<br/>[sanitize.js]"]
end

subgraph group_data["Data Layer"]
  node_content_db[("D1 Schema<br/>sqlite db")]
  node_media_store[("R2 Bucket<br/>object storage<br/>[r2.js]")]
end

subgraph group_ops["Operations"]
  node_ci_cd["CI/CD<br/>automation<br/>[workflows]"]
  node_migrations_scripts["Ops Scripts<br/>maintenance"]
end

node_browser(("Browser<br/>client"))

node_browser -->|"loads"| node_spa
node_spa -->|"renders"| node_public_ui
node_spa -->|"routes to"| node_admin_ui
node_spa -->|"uses"| node_auth_ctx
node_spa -->|"uses"| node_region_ctx
node_spa -->|"uses"| node_toast_ctx
node_spa -->|"calls"| node_api_client
node_public_ui -->|"fetches"| node_public_hooks
node_admin_ui -->|"composes"| node_rich_ui
node_api_client -->|"requests"| node_edge_api
node_edge_api -->|"passes through"| node_middleware
node_middleware -->|"protects"| node_auth_routes
node_middleware -->|"protects"| node_content_routes
node_middleware -->|"protects"| node_admin_routes
node_middleware -->|"protects"| node_storage_routes
node_auth_routes -->|"reads/writes"| node_content_db
node_content_routes -->|"reads/writes"| node_content_db
node_admin_routes -->|"reads/writes"| node_content_db
node_storage_routes -->|"validates"| node_media_utils
node_storage_routes -->|"stores"| node_media_store
node_content_routes -->|"sanitizes"| node_content_safety
node_content_routes -->|"processes"| node_media_utils
node_admin_routes -->|"sanitizes"| node_content_safety
node_ci_cd -->|"builds/tests"| node_spa
node_ci_cd -->|"builds/tests"| node_edge_api
node_migrations_scripts -->|"initializes"| node_content_db

click node_spa "https://github.com/agile-growth-hackers/agile-productions/blob/main/frontend/src/App.jsx"
click node_public_ui "https://github.com/agile-growth-hackers/agile-productions/tree/main/frontend/src/components"
click node_admin_ui "https://github.com/agile-growth-hackers/agile-productions/tree/main/frontend/src/admin"
click node_auth_ctx "https://github.com/agile-growth-hackers/agile-productions/blob/main/frontend/src/context/AuthContext.jsx"
click node_region_ctx "https://github.com/agile-growth-hackers/agile-productions/blob/main/frontend/src/context/RegionContext.jsx"
click node_toast_ctx "https://github.com/agile-growth-hackers/agile-productions/blob/main/frontend/src/context/ToastContext.jsx"
click node_api_client "https://github.com/agile-growth-hackers/agile-productions/blob/main/frontend/src/services/api.js"
click node_public_hooks "https://github.com/agile-growth-hackers/agile-productions/tree/main/frontend/src/hooks"
click node_rich_ui "https://github.com/agile-growth-hackers/agile-productions/tree/main/frontend/src/admin/components"
click node_edge_api "https://github.com/agile-growth-hackers/agile-productions/blob/main/workers/src/index.js"
click node_middleware "https://github.com/agile-growth-hackers/agile-productions/tree/main/workers/src/middleware"
click node_auth_routes "https://github.com/agile-growth-hackers/agile-productions/blob/main/workers/src/routes/auth.js"
click node_content_routes "https://github.com/agile-growth-hackers/agile-productions/tree/main/workers/src/routes"
click node_admin_routes "https://github.com/agile-growth-hackers/agile-productions/tree/main/workers/src/routes"
click node_storage_routes "https://github.com/agile-growth-hackers/agile-productions/blob/main/workers/src/routes/storage.js"
click node_content_db "https://github.com/agile-growth-hackers/agile-productions/tree/main/workers/migrations"
click node_media_store "https://github.com/agile-growth-hackers/agile-productions/blob/main/workers/src/utils/r2.js"
click node_media_utils "https://github.com/agile-growth-hackers/agile-productions/tree/main/workers/src/utils"
click node_content_safety "https://github.com/agile-growth-hackers/agile-productions/blob/main/workers/src/utils/sanitize.js"
click node_ci_cd "https://github.com/agile-growth-hackers/agile-productions/blob/main/.github/workflows"
click node_migrations_scripts "https://github.com/agile-growth-hackers/agile-productions/tree/main/workers/scripts"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_spa,node_public_ui,node_admin_ui,node_auth_ctx,node_region_ctx,node_toast_ctx,node_api_client,node_public_hooks,node_rich_ui toneBlue
class node_edge_api,node_middleware,node_auth_routes,node_content_routes,node_admin_routes,node_storage_routes,node_media_utils,node_content_safety toneAmber
class node_content_db,node_media_store toneMint
class node_ci_cd,node_migrations_scripts toneRose
class node_browser toneNeutral
```

## Components

### Frontend

React + Vite SPA deployed to Cloudflare Pages

- [React SPA](https://github.com/agile-growth-hackers/agile-productions/blob/main/frontend/src/App.jsx): frontend shell · Single-page app bootstrap and routing · `frontend/src/App.jsx`
- [Public Site](https://github.com/agile-growth-hackers/agile-productions/tree/main/frontend/src/components): ui · Hero, About, Services, Gallery, Clients, Navbar, Footer · `frontend/src/components`
- [Admin Console](https://github.com/agile-growth-hackers/agile-productions/tree/main/frontend/src/admin): ui · Protected dashboard for content and user management · `frontend/src/admin`
- [Auth Context](https://github.com/agile-growth-hackers/agile-productions/blob/main/frontend/src/context/AuthContext.jsx): state · Session and auth state for protected routes · `frontend/src/context/AuthContext.jsx`
- [Region Context](https://github.com/agile-growth-hackers/agile-productions/blob/main/frontend/src/context/RegionContext.jsx): state · Region selection and region-scoped content state · `frontend/src/context/RegionContext.jsx`
- [Toast Context](https://github.com/agile-growth-hackers/agile-productions/blob/main/frontend/src/context/ToastContext.jsx): state · Shared UI notifications · `frontend/src/context/ToastContext.jsx`
- [API Client](https://github.com/agile-growth-hackers/agile-productions/blob/main/frontend/src/services/api.js): http layer · Frontend data access layer for CMS and admin operations · `frontend/src/services/api.js`
- [Content Hooks](https://github.com/agile-growth-hackers/agile-productions/tree/main/frontend/src/hooks): data hooks · Fetches page content and section images for public pages · `frontend/src/hooks`
- [Admin Widgets](https://github.com/agile-growth-hackers/agile-productions/tree/main/frontend/src/admin/components): editor components · Modals, drag-and-drop cards, rich text editor, and region switcher · `frontend/src/admin/components`

### Backend

Cloudflare Workers API at the edge

- [Workers API](https://github.com/agile-growth-hackers/agile-productions/blob/main/workers/src/index.js): edge app · Cloudflare Workers application entry and route assembly · `workers/src/index.js`
- [Middleware Stack](https://github.com/agile-growth-hackers/agile-productions/tree/main/workers/src/middleware): request pipeline · CORS, CSRF, HTTPS, rate limits, RBAC, auth, region, validation, and security headers · `workers/src/middleware`
- [Auth Routes](https://github.com/agile-growth-hackers/agile-productions/blob/main/workers/src/routes/auth.js): route group · Login, session, and JWT-based admin auth · `workers/src/routes/auth.js`
- [Content Routes](https://github.com/agile-growth-hackers/agile-productions/tree/main/workers/src/routes): route group · Page content, services, sliders, galleries, logos, section images, and team · `workers/src/routes`
- [Admin Routes](https://github.com/agile-growth-hackers/agile-productions/tree/main/workers/src/routes): route group · Users, profile, activity logs, regions, and usage/account management · `workers/src/routes`
- [Storage Routes](https://github.com/agile-growth-hackers/agile-productions/blob/main/workers/src/routes/storage.js): route group · Upload and media asset handling · `workers/src/routes/storage.js`
- [Media Safety](https://github.com/agile-growth-hackers/agile-productions/tree/main/workers/src/utils): validation + transform · File validation, MIME checks, WebP conversion, and optional TinyPNG compression · `workers/src/utils`
- [Sanitization](https://github.com/agile-growth-hackers/agile-productions/blob/main/workers/src/utils/sanitize.js): security utils · HTML sanitization and password validation helpers · `workers/src/utils/sanitize.js`

### Data Layer

Persistent storage and media assets

- [D1 Schema](https://github.com/agile-growth-hackers/agile-productions/tree/main/workers/migrations): sqlite db · Region-aware content, admins, users, and audit tables · `workers/migrations`
- [R2 Bucket](https://github.com/agile-growth-hackers/agile-productions/blob/main/workers/src/utils/r2.js): object storage · Binary media storage for uploads and profile images · `workers/src/utils/r2.js`

### Operations

CI, migrations, and maintenance scripts

- [CI/CD](https://github.com/agile-growth-hackers/agile-productions/blob/main/.github/workflows): automation · Frontend, backend, and database backup workflows · `.github/workflows`
- [Ops Scripts](https://github.com/agile-growth-hackers/agile-productions/tree/main/workers/scripts): maintenance · Seeding, local admin creation, deployment verification, and test users · `workers/scripts`

### Other components

- **Browser**: client · End-user entry point for the site and admin UI

## Connections

- Browser → React SPA: loads · Browser loads the SPA bundle
- React SPA → Public Site: renders · Public pages are composed from reusable site sections
- React SPA → Admin Console: routes to · Same client app also hosts the protected admin area
- React SPA → Auth Context: uses · Auth state gates protected routes and admin actions
- React SPA → Region Context: uses · Region selection affects which content set is shown
- React SPA → Toast Context: uses · Shared notification layer across the app
- React SPA → API Client: calls · All backend interactions flow through the API layer
- Public Site → Content Hooks: fetches · Public pages hydrate CMS-style content through hooks
- Admin Console → Admin Widgets: composes · Editors and management panels reuse modals and drag-drop widgets
- API Client → Workers API: requests · Frontend sends reads and authenticated writes to Workers
- Workers API → Middleware Stack: passes through · All API traffic is filtered by layered security and request controls
- Middleware Stack → Auth Routes: protects · Auth endpoints handle login and session issuance
- Middleware Stack → Content Routes: protects · Content endpoints serve region-scoped public data and admin writes
- Middleware Stack → Admin Routes: protects · Administrative endpoints require RBAC and auth checks
- Middleware Stack → Storage Routes: protects · Upload endpoints enforce request and security policies
- Auth Routes → D1 Schema: reads/writes · Admin identity and session data live in D1
- Content Routes → D1 Schema: reads/writes · CMS content is stored in the SQLite schema
- Admin Routes → D1 Schema: reads/writes · Users, regions, profiles, and activity logs persist in D1
- Storage Routes → Media Safety: validates · Uploads are checked and transformed before persistence
- Storage Routes → R2 Bucket: stores · Binary assets are placed in R2
- Content Routes → Sanitization: sanitizes · Rich text and user content are cleaned before use
- Content Routes → Media Safety: processes · Media-related content uses validation and conversion helpers
- Admin Routes → Sanitization: sanitizes · Administrative text inputs and profile data are validated
- CI/CD → React SPA: builds/tests · Frontend pipeline covers client build and E2E checks
- CI/CD → Workers API: builds/tests · Backend pipeline covers Workers code and utility tests
- Ops Scripts → D1 Schema: initializes · Scripts seed and maintain the D1 schema and test data
