Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 43 additions & 33 deletions docs/LOCAL-SETUP.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<table role="presentation" style="border:none;border-radius:18px;background:#0f172a;padding:1.5rem 2rem;box-shadow:0 10px 30px rgba(15,23,42,0.35);color:#f8fafc;width:100%;max-width:1200px;">
<tr>
<td style="vertical-align:middle;padding-right:1.5rem;">
<img src="../web/public/icons/favicon_yellow.svg" alt="CommNG Favicon" width="72">
<img src="../web/public/icons/favicon_yellow.svg" alt="GuardConnect Favicon" width="72">
</td>
<td style="vertical-align:middle;">
<h1 style="margin:0;font-size:2rem;color:#f8fafc;">🛠️ Local Setup</h1>
Expand All @@ -24,7 +24,7 @@

# Local Development Setup

Follow this guide to run the CommNG applications locally for development and testing.
Follow this guide to run the GuardConnect applications locally for development and testing.

## Prerequisites

Expand All @@ -38,80 +38,91 @@ Follow this guide to run the CommNG applications locally for development and tes

```bash
git clone <repository-url>
cd CommNG
cd GuardConnect # Root Repository

# Backend dependencies
cd server && npm install
cd server
npm install

# In another terminal - keep both open
# Frontend dependencies
cd ../web && npm install
cd web
npm install
```

## 2. Configure Environment Variables

1. Copy the example environment files (update values as needed):

```bash
cd server
cp .env.example .env.local
# In /server
cp .env.example .env

cd ../web
cp .env.example .env.local
# In /web
cp .env.example .env
```

2. Populate the environment files with credentials:
- PostgreSQL connection string (`DATABASE_URL`)
- Redis details (`REDIS_HOST`, `REDIS_AUTH`)
- VAPID keys for push notifications (or temporary placeholders for local tests)
- BETTER_AUTH_SECRET
- VAPID keys for push notifications (front end too)
- TWILIO values for SMS

_Locations of all values explained in files._

3. Start Redis (and any other required services) via Docker Compose:
3. Start Docker:

```bash
cd ../
# In /server directory
docker compose up -d

# Add PGVector - insert values in [] from server/.env
docker exec -it commng-postgres psql -U [POSTGRES_USER] -d [POSTGRES_DB] -c "CREATE EXTENSION IF NOT EXISTS vector;"
```

## 3. Start Development Servers

```bash
# Terminal 1 - API server
cd server
# Terminal 1 - DB and API server in /server
npx drizzle-kit push # Apply latest migrations
npm run dev

# Terminal 2 - Next.js web app
cd web
# Terminal 2 - Next.js web app in /web
npm run dev
```

- API available at `http://localhost:3000`
- Web UI available at `http://localhost:3001`

## 4. Database Management

Run these commands from the `server` directory:
Use Drizzle Studio (shown below) or your preferred SQL client to inspect data.

## 4. Add roles and users
```bash
# Apply latest migrations
npx drizzle-kit push
# In a new terminal tab
cd server

# Create roles
npx tsx --env-file=.env scripts/create-roles.ts

# Open Drizzle Studio
npx drizzle-kit studio
# Create your user
# Go to server/scripts/create-user.ts and edit the user info (lines 20-35)
# Then run:
npx tsx --env-file=.env scripts/create-user.ts
```
_NOTE: You may need to go back to the other /server terminal and rerun_ ```npm run dev```

Use Drizzle Studio or your preferred SQL client to inspect data.
### > You should now be able to go to http://localhost:3001/ and sign in with the user you just created.

## 5. Development Scripts

```bash
npm run dev # start dev server
# Frontend and backend
npm run test # run unit tests
npm run lint # lint codebase
npm run format # format code
npm run lintfix # lint + auto-fix issues
```

### Backend-specific Scripts

```bash
npx drizzle-kit push # apply latest migrations
npm run db:studio # open Drizzle Studio UI
Expand All @@ -121,20 +132,19 @@ npm run db:studio # open Drizzle Studio UI

```bash
# Reset Docker services
cd CommNG
# In root directory
docker compose down -v

docker compose up -d
```

Common issues:
- **Ports already in use**: stop conflicting processes or change ports in `.env.local`.
- **Ports already in use**: stop conflicting processes or change ports in `.env`.
- **Missing VAPID keys**: generate temporary keys with `npx web-push generate-vapid-keys --json`.
- **Database connectivity**: ensure PostgreSQL is running and credentials match `.env.local`.
- **Database connectivity**: ensure PostgreSQL is running and credentials match `.env`.

## 7. Next Steps

After local setup, proceed with:
After local setup, proceed with (if not done already):
1. [Secrets configuration](./SECRETS-SETUP.md)
2. [Infrastructure provisioning](./INFRA.md)
3. [Deployment workflows](./QUICK-REFERENCE.md)
Expand Down
4 changes: 2 additions & 2 deletions docs/SECRETS-SETUP.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<table role="presentation" style="border:none;border-radius:18px;background:#0f172a;padding:1.5rem 2rem;box-shadow:0 10px 30px rgba(15,23,42,0.35);color:#f8fafc;width:100%;max-width:1200px;">
<tr>
<td style="vertical-align:middle;padding-right:1.5rem;">
<img src="../web/public/icons/favicon_yellow.svg" alt="CommNG Favicon" width="72">
<img src="../web/public/icons/favicon_yellow.svg" alt="GuardConnect Favicon" width="72">
</td>
<td style="vertical-align:middle;">
<h1 style="margin:0;font-size:2rem;color:#f8fafc;">🔐 Secrets Setup</h1>
Expand All @@ -25,7 +25,7 @@

# Secrets Management Setup Guide

This guide explains how to set up and manage secrets in AWS Secrets Manager for the CommNG application.
This guide explains how to set up and manage secrets in AWS Secrets Manager for the GuardConnect application.

## Overview

Expand Down
47 changes: 21 additions & 26 deletions server/.env.example
Original file line number Diff line number Diff line change
@@ -1,33 +1,28 @@
POSTGRES_HOST=
POSTGRES_DB=comm_ng
POSTGRES_SSL=true
AWS_REGION="us-east-1"
DB_SECRET_ID=
# BASIC VALUES & KEYS
DEV_ENV=true # Ensures values are pulled from .env in dev
BACKEND_URL=http://localhost:3000
PORT=3000
LOG_LEVEL=debug
USE_PRESIGNED_UPLOADS=true
DB_SECRET_REFRESH_INTERVAL_MS=30000
# uncomment if using drizzle studio / if you want to not use secrets manager
# POSTGRES_USER=comm_ng_dev_user
# POSTGRES_PASSWORD=


# local pg (user either these 3, or the above 6, but not both)
# POSTGRES_USER=commng-pg-user
# POSTGRES_PASSWORD=
# POSTGRES_DB=comm_ng
BETTER_AUTH_SECRET= # AWS Secrets Manager dev/guardconnect/better-auth-dev

BETTER_AUTH_SECRET=

S3_BUCKET_NAME=
AWS_REGION=us-east-1
USE_PRESIGNED_UPLOADS=true
# LOCAL POSTGRES
POSTGRES_USER=commng-pg-user
POSTGRES_PASSWORD=localpassword
POSTGRES_DB=comm_ng

BACKEND_URL=http://localhost:3000
# AWS
AWS_REGION="us-east-1"
S3_BUCKET_NAME=dev-comm-ng-files-6c661e9c
# Need IAM permissions in group "guardconnect-dev-s3-upload"

# VAPID - Get from AWS Secrets Manager dev/comm_ng/vapid-keys
VAPID_PUBLIC_KEY=
VAPID_PRIVATE_KEY=
VAPID_CONTACT_EMAIL=mailto:admin@example.com

PORT=3000
LOG_LEVEL=debug
VAPID_CONTACT_EMAIL=

# add this if you don't have aws signed in, if this varible is not added/is set to true, it assumes aws exists and is enabled
EMBEDDINGS_ENABLED=false
# TWILIO - Get from AWS Secrets Manager prod/guardconnect/twilio
TWILIO_ACCOUNT_SID=
TWILIO_AUTH_TOKEN=
TWILIO_PHONE_NUMBER=
21 changes: 2 additions & 19 deletions server/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 12 additions & 4 deletions server/src/service/twilio-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,18 @@ interface BroadcastResult {
const client = new SecretsManagerClient({ region: "us-east-1" });

async function getTwilioSecrets() {
const response = await client.send(
new GetSecretValueCommand({ SecretId: "prod/guardconnect/twilio" }),
);
return JSON.parse(response.SecretString!);
if (process.env.DEV_ENV === "true") {
return {
TWILIO_ACCOUNT_SID: process.env.TWILIO_ACCOUNT_SID,
TWILIO_AUTH_TOKEN: process.env.TWILIO_AUTH_TOKEN,
TWILIO_PHONE_NUMBER: process.env.TWILIO_PHONE_NUMBER,
};
} else {
const response = await client.send(
new GetSecretValueCommand({ SecretId: "prod/guardconnect/twilio" }),
);
return JSON.parse(response.SecretString!);
}
}

export class TwilioSMSService {
Expand Down
Loading
Loading