Back to Admin

Architecture

Project identity, tech stack, directory structure, and key conventions for RFS Hub.

This reference enables developers and AI agents to understand and work on the project. Treat it as the source of truth for architecture and file locations.

Project Identity

FieldValue
NameRFS Hub (RedFlag Security Hub)
CompanyRedFlag Security (one word, never "Red Flag")
LocationOttawa, Ontario, Canada
BusinessAlarm systems, CCTV cameras, access control, intercom systems
Package namerfs-hub
Repogeorgesfahd/redflag-chatbot (GitHub)
Node requirement≥ 18
HostingVercel (Hobby plan — no cron jobs)

Tech Stack

LayerTechnologyVersion
FrameworkNext.js (App Router)16.1.6
UIReact19
LanguageTypeScript5.7
DatabaseSupabase (PostgreSQL + Auth + SSR)@supabase/supabase-js 2.47
AIGoogle Gemini@google/generative-ai 0.21
StylingTailwind CSS 4 + CVA4.0
UI ComponentsRadix UI (shadcn-style) + cmdkMultiple
Iconslucide-react0.460
LintingESLint 9 + eslint-config-next9.16

Getting Started

npm install
cp .env.example .env.local   # Fill in all required keys
npm run dev                   # http://localhost:3000 (Turbopack)

Scripts: dev (Turbopack), build, start, lint, db:schema-dump.

Directory Structure

src/
├── app/           # Next.js App Router (admin, api, portal, tech, estimate, etc.)
├── components/    # admin, chat, estimate, tech, ui (Radix/shadcn)
├── lib/           # estimate/, email-monitor/, qbo/, supabase/, config, gemini, gmail, rate-limit
├── types/         # database.ts (TABLES, BOTS), estimate.ts
├── hooks/
└── proxy.ts  # Auth (edge)

Key Patterns

  • Database: Always use TABLES.xxx and BOTS.xxx from src/types/database.ts. Use createServiceClient() for server-side DB; createServerClient() for auth checks.
  • API: Rate limiting on public endpoints via rateLimitCheck(). Admin APIs check Supabase session. Streaming uses text/plain and X-* headers.
  • AI: Tags in HTML comments: ANSWER, CHIPS, QTY_SELECTOR, etc. Default model: gemini-2.0-flash. Integration in src/lib/gemini.ts.
  • Business: HST 13%; estimate numbers EST-XXXXXXXX; ticket refs TKT-XXXXXX.
  • UI: shadcn-style Radix primitives in src/components/ui/; icons from lucide-react only.