Skip to content

Commit 739dba7

Browse files
committed
docs: add step-by-step setup guide and end-to-end testing guide
- setup-guide.md: linear numbered setup from zero to running across all three modes (dev hot-reload, full Docker, production HTTPS); includes Ubuntu install commands, secret generation, migration, verification checks, and troubleshooting table - testing-guide.md: complete feature-by-feature test checklist covering auth, AWS account connection, scan engine, dashboard, compliance, PDF export (both client and server-side), alert system, and security verification (credential exposure, Swagger disabled, rate limiting, HTTPS redirect); includes pre-test checklist, AWS CLI cross-check commands, pass/fail criteria for every test, cleanup steps, and a sign-off checklist - README.md: add both new docs to documentation index with updated role routing
1 parent 43b9041 commit 739dba7

3 files changed

Lines changed: 890 additions & 7 deletions

File tree

README.md

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -59,16 +59,20 @@ A Cloud Security Posture Management (CSPM) SaaS platform that continuously audit
5959

6060
| Document | Audience | Purpose |
6161
|---|---|---|
62-
| [`docs/architect-delivery-guide.md`](docs/architect-delivery-guide.md) | **Architect / delivery lead** | Non-technical overview: what to configure, how to onboard a client AWS account, how to deliver the service, end-to-end workflow, local Ubuntu testing guide |
63-
| [`docs/user-manual.md`](docs/user-manual.md) | **Operator / power user** | Complete reference for every feature: environment variables, running scans, compliance reports, PDF export, alert system, API endpoints, data model, troubleshooting |
62+
| [`docs/setup-guide.md`](docs/setup-guide.md) | **Everyone** | Step-by-step from zero to running: prerequisites, install, configure, start (dev, Docker, and production modes) |
63+
| [`docs/testing-guide.md`](docs/testing-guide.md) | **Everyone** | Step-by-step end-to-end test of every feature using a real AWS account; includes security verification and sign-off checklist |
64+
| [`docs/architect-delivery-guide.md`](docs/architect-delivery-guide.md) | **Architect / delivery lead** | Non-technical overview: what to configure, how to onboard a client AWS account, how to deliver the service, end-to-end workflow |
65+
| [`docs/user-manual.md`](docs/user-manual.md) | **Operator / power user** | Complete feature reference: environment variables, scanning, compliance, PDF export, alert system, API endpoints, data model, troubleshooting |
6466
| [`docs/technical-concept-document.md`](docs/technical-concept-document.md) | **Developer** | Build phase history, architecture decisions, what was delivered in each phase, and the roadmap for upcoming phases |
65-
| [`docs/architecture.md`](docs/architecture.md) | **Developer** | System architecture diagrams and component interactions |
67+
| [`docs/architecture.md`](docs/architecture.md) | **Developer** | System architecture diagrams, component interactions, security design |
6668
| [`README.md`](README.md) | **Everyone** | Quick start — stack overview, repo layout, local dev commands, Docker stack, API endpoint list |
6769

68-
> **Starting point by role:**
69-
> - Delivering to a client? → Start with `architect-delivery-guide.md`
70-
> - Setting up or operating the platform? → Start with `user-manual.md`
71-
> - Contributing to or extending the code? → Start with `technical-concept-document.md`
70+
> **Start here:**
71+
> - First time setting up? → `setup-guide.md`
72+
> - Verifying features work? → `testing-guide.md`
73+
> - Delivering to a client? → `architect-delivery-guide.md`
74+
> - Looking up a specific feature? → `user-manual.md`
75+
> - Contributing code? → `technical-concept-document.md`
7276
7377
## Prerequisites
7478

docs/setup-guide.md

Lines changed: 342 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,342 @@
1+
# CSPM Platform — Step-by-Step Setup Guide
2+
3+
**Audience:** Anyone setting up this platform for the first time — local developer, tester, or architect doing a local proof-of-concept
4+
**Time required:** 20–30 minutes for local dev; 45–60 minutes for production
5+
**Last updated:** 2026-06-14
6+
7+
---
8+
9+
## Before You Start — Choose Your Mode
10+
11+
| Mode | When to use | What you get |
12+
|---|---|---|
13+
| **A — Local Dev** | Development, debugging, first look | HTTP on port 3000, hot reload, no TLS |
14+
| **B — Full Docker (local)** | Testing the Docker stack without HTTPS | HTTP on port 3000, all services containerised |
15+
| **C — Production** | Real deployment, client delivery | HTTPS on port 443, network isolation, Redis auth |
16+
17+
> **For your first run and AWS scan testing → use Mode A or B.**
18+
> Mode C requires a TLS certificate and domain. See Section 3 for production.
19+
20+
---
21+
22+
## Section 1 — Prerequisites
23+
24+
### 1.1 Install required software (Ubuntu)
25+
26+
```bash
27+
# Docker (includes Docker Compose)
28+
curl -fsSL https://get.docker.com | sh
29+
sudo usermod -aG docker $USER
30+
newgrp docker # apply group without logging out
31+
32+
# Verify Docker
33+
docker --version # expect: Docker version 24+
34+
docker compose version # expect: Docker Compose version v2.20+
35+
36+
# Node.js 20 via nvm
37+
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash
38+
source ~/.bashrc
39+
nvm install 20
40+
nvm use 20
41+
node --version # expect: v20.x.x
42+
43+
# pnpm
44+
npm install -g pnpm@9
45+
pnpm --version # expect: 9.x.x
46+
47+
# Python 3.12
48+
sudo apt update
49+
sudo apt install -y python3.12 python3.12-venv python3-pip
50+
python3.12 --version # expect: Python 3.12.x
51+
```
52+
53+
### 1.2 AWS CLI (needed to create the IAM audit role)
54+
55+
```bash
56+
curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o /tmp/awscliv2.zip
57+
unzip /tmp/awscliv2.zip -d /tmp
58+
sudo /tmp/aws/install
59+
aws --version # expect: aws-cli/2.x.x
60+
61+
# Configure your AWS credentials
62+
aws configure
63+
# Enter: Access Key ID, Secret Access Key, default region (e.g. us-east-1), output format (json)
64+
```
65+
66+
---
67+
68+
## Section 2 — Local Setup (Mode A and B)
69+
70+
### 2.1 Clone the repository
71+
72+
```bash
73+
git clone <repo-url> CSPM-SaaS
74+
cd CSPM-SaaS
75+
```
76+
77+
### 2.2 Install dependencies
78+
79+
```bash
80+
# Web frontend and shared TypeScript package
81+
pnpm install
82+
83+
# Python API
84+
pip install -r apps/api/requirements.txt
85+
```
86+
87+
Expected output for `pnpm install`: packages downloaded, `node_modules` created
88+
Expected output for pip install: all packages installed with no errors
89+
90+
### 2.3 Generate secrets
91+
92+
Run each command and copy the output — you will paste these into `.env` in the next step.
93+
94+
```bash
95+
echo "JWT_SECRET=$(openssl rand -hex 32)"
96+
echo "JWT_REFRESH_SECRET=$(openssl rand -hex 32)"
97+
echo "ENCRYPTION_KEY=$(openssl rand -hex 32)"
98+
```
99+
100+
> **Important:** All three values must be different. Save them somewhere safe.
101+
> If you ever change `ENCRYPTION_KEY` after connecting AWS accounts, all credentials become unreadable.
102+
103+
### 2.4 Configure environment
104+
105+
```bash
106+
cp .env.example .env
107+
```
108+
109+
Open `.env` and replace the placeholder values:
110+
111+
```bash
112+
# Paste the generated secrets from step 2.3
113+
JWT_SECRET=<paste here>
114+
JWT_REFRESH_SECRET=<paste a different value here>
115+
ENCRYPTION_KEY=<paste here>
116+
117+
# These are correct as-is for local Docker setup — do not change them
118+
DATABASE_URL="postgresql://cspm:cspm@localhost:5432/cspm"
119+
REDIS_URL="redis://localhost:6379"
120+
NEXT_PUBLIC_API_URL="http://localhost:4000"
121+
NODE_ENV="development"
122+
```
123+
124+
**Verify:** `.env` has no remaining placeholder text like `replace-with-...`
125+
126+
### 2.5 Start the database and Redis
127+
128+
```bash
129+
docker compose -f infra/docker-compose.yml up -d postgres redis
130+
```
131+
132+
Wait 10 seconds, then verify both containers are healthy:
133+
134+
```bash
135+
docker compose -f infra/docker-compose.yml ps
136+
```
137+
138+
Expected: Both `cspm-postgres` and `cspm-redis` show status `healthy`.
139+
140+
### 2.6 Apply database migrations
141+
142+
```bash
143+
make migrate
144+
```
145+
146+
Expected output: `INFO [alembic.runtime.migration] Running upgrade -> ...`
147+
If you see `alembic upgrade head` complete with no errors, the schema is ready.
148+
149+
### 2.7 Choose how to start
150+
151+
#### Mode A — Development (hot reload)
152+
153+
Open **two terminals** in the project root:
154+
155+
**Terminal 1:**
156+
```bash
157+
make dev
158+
```
159+
Expected: FastAPI starts on port 4000, Next.js starts on port 3000. Both show startup messages.
160+
161+
**Terminal 2:**
162+
```bash
163+
make worker
164+
```
165+
Expected: `celery@... ready.` — worker is waiting for scan jobs.
166+
167+
#### Mode B — Full Docker stack
168+
169+
```bash
170+
make up
171+
```
172+
Expected: All 5 containers (postgres, redis, api, worker, web) start and become healthy.
173+
Check with: `docker compose -f infra/docker-compose.yml ps`
174+
175+
### 2.8 Verify the platform is running
176+
177+
```bash
178+
# API health check
179+
curl http://localhost:4000/health
180+
# Expected: {"status":"ok","service":"cspm-api"}
181+
182+
# Web frontend
183+
curl -s -o /dev/null -w "%{http_code}" http://localhost:3000
184+
# Expected: 200
185+
```
186+
187+
Open `http://localhost:3000` in your browser. You should see the login page.
188+
189+
---
190+
191+
## Section 3 — Production Setup (Mode C)
192+
193+
### 3.1 Prerequisites for production
194+
195+
- A TLS certificate and private key for your domain
196+
- Your domain DNS pointing to the server
197+
- Docker installed on the server (see Section 1.1)
198+
199+
### 3.2 Generate a self-signed certificate (local HTTPS testing only)
200+
201+
Skip this if you have a real certificate (e.g. Let's Encrypt).
202+
203+
```bash
204+
openssl req -x509 -newkey rsa:4096 \
205+
-keyout /tmp/cspm-key.pem \
206+
-out /tmp/cspm-cert.pem \
207+
-days 365 -nodes \
208+
-subj '/CN=localhost'
209+
```
210+
211+
### 3.3 Configure production environment
212+
213+
```bash
214+
cp .env.prod.example .env.prod
215+
```
216+
217+
Fill in `.env.prod`:
218+
219+
```bash
220+
# Generate all secrets
221+
echo "JWT_SECRET=$(openssl rand -hex 32)"
222+
echo "JWT_REFRESH_SECRET=$(openssl rand -hex 32)"
223+
echo "ENCRYPTION_KEY=$(openssl rand -hex 32)"
224+
echo "POSTGRES_PASSWORD=$(openssl rand -hex 16)"
225+
echo "REDIS_PASSWORD=$(openssl rand -hex 16)"
226+
```
227+
228+
Paste the generated values into `.env.prod`. Also set:
229+
230+
```
231+
POSTGRES_USER=cspm
232+
POSTGRES_DB=cspm
233+
API_IMAGE=cspm-api:latest
234+
WEB_IMAGE=cspm-web:latest
235+
NODE_ENV=production
236+
CORS_ORIGIN=https://yourdomain.com # or https://localhost for self-signed testing
237+
NEXT_PUBLIC_API_URL=http://api:4000 # internal — do not change
238+
239+
# Paths to your TLS files
240+
SSL_CERT_PATH=/tmp/cspm-cert.pem # or /etc/letsencrypt/live/yourdomain.com/fullchain.pem
241+
SSL_KEY_PATH=/tmp/cspm-key.pem # or /etc/letsencrypt/live/yourdomain.com/privkey.pem
242+
```
243+
244+
### 3.4 Update nginx domain (optional)
245+
246+
If you have a real domain, edit `infra/nginx/nginx.prod.conf` and replace the two `server_name _;` lines with your domain:
247+
248+
```nginx
249+
server_name cspm.yourdomain.com;
250+
```
251+
252+
For self-signed / IP access, leave `server_name _;` (catch-all).
253+
254+
### 3.5 Build Docker images
255+
256+
```bash
257+
make prod-build
258+
```
259+
260+
Expected: Two Docker images built — `cspm-api:latest` and `cspm-web:latest`.
261+
Build time: 3–8 minutes depending on internet speed and machine.
262+
263+
### 3.6 Start the production stack
264+
265+
```bash
266+
make prod-up
267+
```
268+
269+
Expected: All 6 containers start (postgres, redis, api, worker, web, nginx).
270+
271+
### 3.7 Apply database migrations
272+
273+
```bash
274+
make prod-migrate
275+
```
276+
277+
Expected: Alembic migrations applied. Run only once (or when you update the code).
278+
279+
### 3.8 Verify production is running
280+
281+
```bash
282+
# Health check through nginx
283+
curl -k https://localhost/health
284+
# Expected: healthy
285+
286+
# HTTP → HTTPS redirect
287+
curl -v http://localhost/ 2>&1 | grep "< HTTP\|Location"
288+
# Expected: HTTP/1.1 301 ... Location: https://...
289+
```
290+
291+
Open `https://localhost` in your browser. Accept the self-signed certificate warning if using a test cert.
292+
293+
---
294+
295+
## Section 4 — First Login
296+
297+
1. Open the platform in your browser (`http://localhost:3000` for dev, `https://yourdomain.com` for prod)
298+
2. Click **Register** (or navigate to `/register`)
299+
3. Fill in:
300+
- **Organisation name:** your company name or a test label (e.g. "Test Org")
301+
- **Your name:** your display name
302+
- **Email:** your email address
303+
- **Password:** at least 8 characters
304+
4. Click **Create account**
305+
5. You are automatically logged in and redirected to the Dashboard
306+
307+
> The first user registered becomes the **Admin** of that organisation.
308+
309+
---
310+
311+
## Section 5 — Quick Troubleshooting
312+
313+
| Symptom | Check | Fix |
314+
|---|---|---|
315+
| API won't start — secret error | Error message in terminal | See error table in `docs/user-manual.md` Section 21 |
316+
| `http://localhost:3000` doesn't load | Is `make dev` or `make up` running? | Re-run the start command |
317+
| Dashboard shows no data | No scan run yet | Connect an AWS account and run a scan (see testing guide) |
318+
| Scan stays PENDING | Celery worker not running | Run `make worker` in a separate terminal |
319+
| `alembic upgrade head` fails | Postgres not running | Run `docker compose -f infra/docker-compose.yml up -d postgres` first |
320+
| Docker build fails (web) | pnpm lock mismatch | Run `pnpm install` locally first, then `make prod-build` |
321+
| Port 3000 or 4000 already in use | Another process | `lsof -i :3000` or `lsof -i :4000` to find and kill it |
322+
323+
---
324+
325+
## Section 6 — Stopping the Platform
326+
327+
```bash
328+
# Dev stack
329+
make down
330+
331+
# Production stack
332+
make prod-down
333+
334+
# Stop only databases (keep data)
335+
docker compose -f infra/docker-compose.yml stop postgres redis
336+
```
337+
338+
---
339+
340+
## What's Next
341+
342+
Once the platform is running, follow **`docs/testing-guide.md`** to verify every feature works end-to-end, including a real AWS scan.

0 commit comments

Comments
 (0)