role-directory
Infrastructure validation web application with secure OAuth-based collaboration
Motivation
When building applications in the cloud, there's a tension between rapid iteration and maintaining confidentiality during development. role-directory solves this by creating an infrastructure validation MVP that proves a complete production-ready deployment pipeline (dev → staging → production) works correctly before investing in complex features.
Why this project exists:
- ✅ Validate full deployment stack early (Next.js + PostgreSQL + Cloud Run + CI/CD)
- ✅ Enable secure collaboration with trusted stakeholders via OAuth
- ✅ Build confidence in infrastructure through practical feature development
- ✅ Stay within free tiers (~$0-3/month) while proving production readiness
The Magic: Infrastructure de-risking through deliberate, incremental validation. Every feature proves a different deployment layer works correctly.
Build Status
| Environment |
Status |
URL |
| Development |
🔄 Ready for Implementation |
TBD |
| Staging |
⏳ Pending |
TBD |
| Production |
⏳ Pending |
TBD |
Current Phase: 🔄 Implementation (Epic 2 - Database Infrastructure)
Documentation Quality: 📚 Grade A+ (Consolidated & Current)
Screenshots
📸 Screenshots will be added after MVP implementation
Planned Features:
- OAuth sign-in page (Google/GitHub)
- Hello World dashboard with database query results
- User profile display with email whitelist
- Query performance metrics
Tech Stack
Built with:
Frontend
Backend
Database
Infrastructure
Code Quality
Features
What makes this project stand out:
🎯 Infrastructure-First Approach
- Validates deployment pipeline BEFORE building complex features
- Proves dev → staging → production promotion workflow works
💰 Cost-Optimized (~$0-3/month)
- Leverages free tiers: Cloud Run + Neon PostgreSQL + GitHub Actions
- Auto-suspends when idle (serverless architecture)
🔐 OAuth Authentication with Email Whitelist
- No custom auth code needed (Neon Auth handles it)
- Server-side email whitelist for access control
- Session management works across Cloud Run instances
📊 Complete Traceability
- 21 functional requirements → 32 implementable stories
- 100% requirement coverage validated
- 7 Architecture Decision Records (ADRs)
🤖 AI Agent Ready
- 50+ consistency rules for parallel development
- Comprehensive implementation patterns
- Type-safe configuration with Zod
Code Example
Configuration Validation (Zod):
// lib/config.ts
import { z } from 'zod';
const configSchema = z.object({
databaseUrl: z.string()
.url('DATABASE_URL must be a valid URL')
.startsWith('postgresql://'),
allowedEmails: z.string()
.transform(str => str.split(',').map(e => e.trim())),
nodeEnv: z.enum(['development', 'staging', 'production']),
});
export const getConfig = () => configSchema.parse(process.env);
Database Query Pattern:
// lib/db.ts - Database module
import { query, queryOne } from '@/lib/db';
// Simple query
const version = await query('SELECT version()');
// Parameterized query (prevents SQL injection)
const users = await query<User>(
'SELECT * FROM users WHERE email = $1',
['user@example.com']
);
// Query periodic table sample data
const elements = await query<Element>(
'SELECT * FROM periodic_table WHERE atomic_number <= $1 ORDER BY atomic_number',
[10]
);
// Single row query
const element = await queryOne<Element>(
'SELECT * FROM periodic_table WHERE symbol = $1',
['Ne']
);
API Route Pattern:
// app/api/dashboard/hello/route.ts
import { getUser } from '@/lib/auth';
import { query } from '@/lib/db';
export async function GET() {
try {
const user = await getUser();
if (!user) return NextResponse.json({ error: 'Unauthorized' }, { status: 401 });
const start = Date.now();
const result = await query('SELECT * FROM periodic_table ORDER BY atomic_number LIMIT 10');
return NextResponse.json({
data: result,
query_time_ms: Date.now() - start
});
} catch (error) {
return NextResponse.json({ error: 'Server error' }, { status: 500 });
}
}
Database Features:
- ✅ HTTP-based connection - Neon serverless driver (no connection pooling needed)
- ✅ Parameterized queries - Prevents SQL injection ($1, $2 placeholders)
- ✅ Slow query logging - Automatically logs queries >200ms
- ✅ Error sanitization - Generic error messages to client, full details server-side
- ✅ Cold start handling - Transparently handles Neon auto-suspend/resume (2-3s)
- ✅ Type safety - Generic type parameter for result rows
Installation
Prerequisites
Step-by-Step Setup
1. Clone the repository
git clone https://github.com/danielvm/role-directory.git
cd role-directory
2. Install dependencies
3. Set up environment variables
cp .env.example .env.local
Edit .env.local with your credentials:
# Database (Neon PostgreSQL) - REQUIRED
DATABASE_URL="postgresql://user:pass@ep-xxx.region.neon.tech/role_directory_dev?sslmode=require"
# Access Control - REQUIRED
ALLOWED_EMAILS="your-email@example.com,collaborator@example.com"
# Authentication (Neon Auth) - REQUIRED for Epic 3
NEON_AUTH_PROJECT_ID="your-project-id"
NEON_AUTH_SECRET_KEY="your-secret-key"
# Environment - OPTIONAL (defaults shown)
NODE_ENV="development" # development | staging | production
PORT="3000" # 1-65535
Environment Variable Details:
| Variable |
Required |
Default |
Description |
DATABASE_URL |
✅ Yes |
None |
PostgreSQL connection string from Neon (must start with postgresql://) |
ALLOWED_EMAILS |
✅ Yes |
None |
Comma-separated list of allowed email addresses |
NODE_ENV |
⚠️ Optional |
development |
Application environment: development, staging, production |
PORT |
⚠️ Optional |
8080 |
Server port number (1-65535) |
NEON_AUTH_PROJECT_ID |
🔮 Epic 3 |
None |
Neon Auth project ID (for OAuth) |
NEON_AUTH_SECRET_KEY |
🔮 Epic 3 |
None |
Neon Auth secret key (for OAuth) |
NEXT_PUBLIC_API_URL |
⚠️ Optional |
None |
Public API URL for client-side requests |
Configuration Validation:
The application uses Zod for runtime validation. If configuration is invalid, the app fails fast with detailed error messages:
# Example: Missing DATABASE_URL
Configuration validation failed:
databaseUrl: Required
Please check your environment variables in .env.local (local) or Cloud Run configuration (production).
Using Configuration in Code: