Skip to content

Commit fc7e3a0

Browse files
MohsinHashmi-DataInnDeveloperclaude
authored
fix: add missing simpleaccounts_db env vars and update documentation (#449)
Issues fixed: - Backend failed to start due to missing SIMPLEACCOUNTS_DB_* environment variables - post-start.sh used wrong hostnames (localhost vs db/redis) - Documentation had outdated npm commands (npm run dev vs npm start) Changes: - Add SIMPLEACCOUNTS_DB_HOST, SIMPLEACCOUNTS_DB_PORT, etc. to .env.example - Add same env vars to Coder template.tf for seamless Coder support - Update post-start.sh to auto-detect Coder vs DevContainer environment - Fix npm commands in CLAUDE.md, AGENTS.md, and other docs - Update README.md architecture diagram to show localhost networking 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Developer <developer@simpleaccounts.io> Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
1 parent da75451 commit fc7e3a0

7 files changed

Lines changed: 162 additions & 33 deletions

File tree

.coder/template.tf

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,11 @@ resource "coder_agent" "main" {
297297
echo "✅ Workspace ready!"
298298
echo ""
299299
echo "Quick start commands:"
300-
echo " Frontend: cd apps/frontend && npm run dev"
300+
echo " Frontend: npm run frontend"
301+
echo " Backend: npm run backend:run"
302+
echo ""
303+
echo "Or from app directories:"
304+
echo " Frontend: cd apps/frontend && npm start"
301305
echo " Backend: cd apps/backend && ./mvnw spring-boot:run"
302306
EOT
303307

@@ -371,12 +375,26 @@ resource "docker_container" "workspace" {
371375
env = [
372376
"CODER_AGENT_TOKEN=${coder_agent.main.token}",
373377
"CODER_AGENT_URL=${data.coder_workspace.me.access_url}",
374-
# Database credentials (auto-generated per workspace)
378+
# Database credentials for PostgreSQL container
375379
"POSTGRES_USER=simpleaccounts",
376380
"POSTGRES_PASSWORD=${random_password.postgres.result}",
377381
"POSTGRES_DB=simpleaccounts",
378382
"POSTGRES_HOST=db",
379383
"POSTGRES_PORT=5432",
384+
# Backend Spring Boot configuration (uses 'db' hostname in Coder network)
385+
"SIMPLEACCOUNTS_DB_HOST=db",
386+
"SIMPLEACCOUNTS_DB_PORT=5432",
387+
"SIMPLEACCOUNTS_DB=simpleaccounts",
388+
"SIMPLEACCOUNTS_DB_USER=simpleaccounts",
389+
"SIMPLEACCOUNTS_DB_PASSWORD=${random_password.postgres.result}",
390+
"SIMPLEACCOUNTS_DB_SSL=false",
391+
"SIMPLEACCOUNTS_DB_SSLMODE=disable",
392+
"SIMPLEACCOUNTS_DB_SSLROOTCERT=",
393+
# Redis configuration
394+
"SPRING_REDIS_HOST=redis",
395+
"SPRING_REDIS_PORT=6379",
396+
# Application host
397+
"SIMPLEACCOUNTS_HOST=http://localhost:8080",
380398
# Application settings
381399
"PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD=1",
382400
"PLAYWRIGHT_CHROMIUM_EXECUTABLE_PATH=/usr/bin/chromium",

.devcontainer/.env.example

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,45 @@
11
# DevContainer Environment Variables
22
# Copy this file to .env and fill in your values
33

4-
# Database Credentials
4+
# =============================================================================
5+
# Database Credentials (for PostgreSQL container)
56
# Note: For Coder workspaces, these are auto-generated per workspace
67
# For local dev, you can customize or leave defaults
8+
# =============================================================================
79
POSTGRES_USER=simpleaccounts
810
POSTGRES_PASSWORD=simpleaccounts_dev
911
POSTGRES_DB=simpleaccounts
1012

13+
# =============================================================================
14+
# Backend Spring Boot Configuration
15+
# These variables are used by application.properties
16+
# Note: Use localhost because all services share network via network_mode: service:db
17+
# =============================================================================
18+
SIMPLEACCOUNTS_DB_HOST=localhost
19+
SIMPLEACCOUNTS_DB_PORT=5432
20+
SIMPLEACCOUNTS_DB=simpleaccounts
21+
SIMPLEACCOUNTS_DB_USER=simpleaccounts
22+
SIMPLEACCOUNTS_DB_PASSWORD=simpleaccounts_dev
23+
SIMPLEACCOUNTS_DB_SSL=false
24+
SIMPLEACCOUNTS_DB_SSLMODE=disable
25+
SIMPLEACCOUNTS_DB_SSLROOTCERT=
26+
27+
# Redis Configuration
28+
SPRING_REDIS_HOST=localhost
29+
SPRING_REDIS_PORT=6379
30+
31+
# Application Host
32+
SIMPLEACCOUNTS_HOST=http://localhost:8080
33+
34+
# =============================================================================
1135
# SonarQube (for MCP)
36+
# =============================================================================
1237
SONARQUBE_URL=
1338
SONARQUBE_TOKEN=
1439

40+
# =============================================================================
1541
# SMTP Configuration
42+
# =============================================================================
1643
SIMPLEACCOUNTS_SMTP_HOST=
1744
SIMPLEACCOUNTS_SMTP_PORT=465
1845
SIMPLEACCOUNTS_SMTP_USER=

.devcontainer/README.md

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,21 @@ code .
2828

2929
## Architecture
3030

31+
All services share the same network namespace via `network_mode: service:db`.
32+
This means all services (devcontainer, postgres, redis) are accessible via `localhost`.
33+
3134
```
3235
┌─────────────────────────────────────────────────────────────┐
33-
Internal Docker Network
34-
│ (user-specific isolation)
36+
Shared Network Namespace (localhost)
37+
│ (network_mode: service:db)
3538
│ │
3639
│ ┌──────────────┐ ┌──────────────┐ ┌──────────────┐ │
37-
│ │ devcontainer │ │ db │ │ redis │ │
38-
│ │ │ │ (postgres) │ │ │ │
39-
│ │ db:5432 ──────► :5432 │ │ │ │
40-
│ │ redis:6379 ───────────────────────► :6379 │ │
40+
│ │ devcontainer │ │ PostgreSQL │ │ Redis │ │
41+
│ │ │ │ │ │ │ │
42+
│ │ localhost:3000 (frontend) │ │
43+
│ │ localhost:8080 (backend) │ │
44+
│ │ │ │ localhost:5432 │ │
45+
│ │ │ │ │ │ localhost:6379 │
4146
│ └──────────────┘ └──────────────┘ └──────────────┘ │
4247
└─────────────────────────────────────────────────────────────┘
4348
```
@@ -46,8 +51,8 @@ code .
4651

4752
| Service | Access From Container |
4853
| ---------- | --------------------- |
49-
| PostgreSQL | `db:5432` |
50-
| Redis | `redis:6379` |
54+
| PostgreSQL | `localhost:5432` |
55+
| Redis | `localhost:6379` |
5156
| Frontend | `localhost:3000` |
5257
| Backend | `localhost:8080` |
5358

@@ -103,11 +108,11 @@ docker compose up -d
103108
### Verify Network Connectivity
104109

105110
```bash
106-
# PostgreSQL (uses internal hostname 'db')
107-
pg_isready -h db -p 5432
111+
# PostgreSQL (all services share localhost via network_mode: service:db)
112+
pg_isready -h localhost -p 5432
108113

109-
# Redis (uses internal hostname 'redis')
110-
redis-cli -h redis ping
114+
# Redis (all services share localhost via network_mode: service:db)
115+
redis-cli -h localhost ping
111116
```
112117

113118
### View Container Logs

.devcontainer/post-create.sh

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -168,12 +168,19 @@ if [ ! -f "apps/backend/src/main/resources/application-local.properties" ]; then
168168
echo "📝 Creating backend application-local.properties..."
169169
cat > apps/backend/src/main/resources/application-local.properties << 'BACKENDEOF'
170170
# Local development configuration
171+
# Uses localhost because all services share network via network_mode: service:db
171172
spring.datasource.url=jdbc:postgresql://localhost:5432/simpleaccounts
172173
spring.datasource.username=simpleaccounts
173174
spring.datasource.password=simpleaccounts_dev
174175
spring.jpa.hibernate.ddl-auto=update
175-
spring.redis.host=localhost
176-
spring.redis.port=6379
176+
177+
# Redis configuration
178+
spring.data.redis.host=localhost
179+
spring.data.redis.port=6379
180+
181+
# Disable Liquibase in local dev (use ddl-auto=update instead)
182+
# Uncomment if you want to use Liquibase migrations
183+
# spring.liquibase.enabled=true
177184
BACKENDEOF
178185
fi
179186

@@ -221,5 +228,9 @@ fi
221228
echo "✅ Development environment setup complete!"
222229
echo ""
223230
echo "Quick start commands:"
224-
echo " Frontend: cd apps/frontend && npm run dev"
231+
echo " Frontend: cd apps/frontend && npm start"
225232
echo " Backend: cd apps/backend && ./mvnw spring-boot:run"
233+
echo ""
234+
echo "Or from repo root:"
235+
echo " Frontend: npm run frontend"
236+
echo " Backend: npm run backend:run"

.devcontainer/post-start.sh

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,25 @@
33

44
echo "🔄 Starting SimpleAccounts-UAE development environment..."
55

6-
# Auto-detect PostgreSQL and Redis hostnames
7-
# Coder uses 'db' and 'redis' on Docker network
8-
# Devcontainer uses 'localhost' via shared network namespace
6+
# =============================================================================
7+
# Detect environment and set hostnames
8+
# - Coder: Uses separate containers with 'db' and 'redis' hostnames
9+
# - Local DevContainer: Uses network_mode: service:db (shared localhost)
10+
# =============================================================================
911
if [ -n "$CODER_AGENT_TOKEN" ]; then
10-
# Running in Coder
12+
# Running in Coder - use container hostnames
1113
POSTGRES_HOST="${POSTGRES_HOST:-db}"
1214
REDIS_HOST="redis"
15+
echo "📦 Detected Coder environment (using db/redis hostnames)"
1316
else
14-
# Running in devcontainer
17+
# Running in local devcontainer - use localhost (network_mode: service:db)
1518
POSTGRES_HOST="localhost"
1619
REDIS_HOST="localhost"
20+
echo "📦 Detected local devcontainer (using localhost)"
1721
fi
1822

1923
# Wait for PostgreSQL to be ready (with timeout)
20-
echo "⏳ Waiting for PostgreSQL..."
24+
echo "⏳ Waiting for PostgreSQL at ${POSTGRES_HOST}:5432..."
2125
TIMEOUT=60
2226
ELAPSED=0
2327
until pg_isready -h "$POSTGRES_HOST" -p 5432 -U simpleaccounts -q; do
@@ -33,7 +37,7 @@ if [ $ELAPSED -lt $TIMEOUT ]; then
3337
fi
3438

3539
# Wait for Redis to be ready (with timeout)
36-
echo "⏳ Waiting for Redis..."
40+
echo "⏳ Waiting for Redis at ${REDIS_HOST}:6379..."
3741
ELAPSED=0
3842
until redis-cli -h "$REDIS_HOST" ping > /dev/null 2>&1; do
3943
sleep 1

AGENTS.md

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,17 @@
44

55
For complete setup instructions including prerequisites, database setup, environment configuration, and running the application, see **[SETUP.md](./SETUP.md)**.
66

7-
**Quick Start:**
7+
**Quick Start (DevContainer - Recommended):**
8+
9+
The devcontainer automatically sets up PostgreSQL, Redis, and all environment variables.
10+
11+
```bash
12+
# From repo root - run in separate terminals
13+
npm run frontend # Terminal 1 - starts Vite dev server (port 3000)
14+
npm run backend:run # Terminal 2 - starts Spring Boot (port 8080)
15+
```
16+
17+
**Quick Start (Manual Setup):**
818

919
```bash
1020
# Prerequisites: Node 20+, Java 21, PostgreSQL 14+
@@ -15,8 +25,15 @@ npm install
1525
# 2. Setup database and create apps/backend/.env (see SETUP.md)
1626

1727
# 3. Run application
18-
npm run backend:run # Terminal 1
19-
npm run frontend # Terminal 2
28+
npm run frontend # Terminal 1 - starts Vite dev server (port 3000)
29+
npm run backend:run # Terminal 2 - starts Spring Boot (port 8080)
30+
```
31+
32+
**Alternative commands (from app directories):**
33+
34+
```bash
35+
cd apps/frontend && npm start # Frontend dev server
36+
cd apps/backend && ./mvnw spring-boot:run # Backend server
2037
```
2138

2239
---

CLAUDE.md

Lines changed: 52 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -367,15 +367,62 @@ apps/frontend/src/
367367

368368
## Development Commands
369369

370+
### DevContainer (Recommended)
371+
372+
When using the devcontainer, PostgreSQL and Redis are automatically started and configured.
373+
Environment variables are pre-configured in `.devcontainer/.env`.
374+
370375
```bash
371-
# Start frontend dev server
372-
cd apps/frontend && npm run dev
376+
# From apps/frontend directory
377+
npm start # Start frontend dev server (port 3000)
378+
379+
# From apps/backend directory
380+
./mvnw spring-boot:run # Start backend server (port 8080)
381+
382+
# Or from repo root (recommended)
383+
npm run frontend # Start frontend dev server
384+
npm run backend:run # Start backend server
385+
```
386+
387+
### Running Frontend and Backend Together
388+
389+
```bash
390+
# Terminal 1 - Frontend
391+
npm run frontend
392+
393+
# Terminal 2 - Backend
394+
npm run backend:run
395+
```
396+
397+
### Available URLs
398+
399+
| Service | URL |
400+
| ----------- | ------------------------------------- |
401+
| Frontend | http://localhost:3000 |
402+
| Backend API | http://localhost:8080 |
403+
| Swagger UI | http://localhost:8080/swagger-ui.html |
404+
405+
### Database Connection (DevContainer)
406+
407+
The devcontainer automatically configures PostgreSQL with these settings:
373408

374-
# Start backend
375-
cd apps/backend && ./mvnw spring-boot:run
409+
- **Host**: localhost (shared network namespace)
410+
- **Port**: 5432
411+
- **Database**: simpleaccounts
412+
- **User**: simpleaccounts
413+
- **Password**: simpleaccounts_dev
376414

377-
# Run tests
415+
### Testing
416+
417+
```bash
418+
# Frontend tests
378419
cd apps/frontend && npm test
420+
421+
# Backend tests
422+
cd apps/backend && ./mvnw test
423+
424+
# E2E tests (Playwright)
425+
cd apps/frontend && npm run test:frontend:e2e
379426
```
380427

381428
## Git Workflow

0 commit comments

Comments
 (0)