Infrastructure validation web application with secure OAuth-based collaboration
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.
| 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 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
Built with:
- Next.js 15.0.3 (App Router)
- React 18.3.1
- TypeScript 5.6.3
- Tailwind CSS 3.4.14
- Neon PostgreSQL 17.0 (Serverless)
- @neondatabase/serverless 0.10.1
- Google Cloud Run (3 environments: dev, stg, prd)
- Artifact Registry (Docker image storage)
- GitHub Actions (CI/CD)
- Google Secret Manager (Runtime secrets)
- Docker 27.3.1
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
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
- Node.js 22.11.0 LTS
- Docker 27.3.1
- Google Cloud SDK
- Neon account (sign up free)
- GitHub account
1. Clone the repository
git clone https://github.com/danielvm/role-directory.git
cd role-directory2. Install dependencies
npm install3. Set up environment variables
cp .env.example .env.localEdit .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-65535Environment 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 |
development |
Application environment: development, staging, production |
|
PORT |
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 |
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:
import { getConfig } from '@/lib/config';
// Type-safe configuration access
const config = getConfig();
console.log(config.databaseUrl); // string
console.log(config.allowedEmails); // string[]
console.log(config.nodeEnv); // 'development' | 'staging' | 'production'
console.log(config.port); // number4. Set up Neon PostgreSQL
See detailed guide: Neon Infrastructure Setup Guide
5. Run database migrations
Apply schema migrations to set up your database:
# Check migration status
DATABASE_URL="postgresql://..." npm run migrate:status
# Apply all pending migrations
DATABASE_URL="postgresql://..." npm run migrate:upSee detailed guide: Database Migrations Guide
6. Set up Neon Auth (OAuth)
See detailed guide: Neon Auth Setup Guide
7. Load sample data (optional)
The application uses the Neon Periodic Table sample dataset for demonstration. This data is automatically loaded during database migrations (Story 2.4).
Sample data details:
- Table:
periodic_table - Records: 118 elements
- Source: Neon sample datasets
- Size: ~7.2 MB installed
- License: ISC License (Copyright ยฉ 2017, Chris Andrejewski)
The periodic table data is perfect for MVP validation because it:
- โ Small dataset (118 rows) - fast queries
- โ Rich schema (28 columns) - demonstrates data display
- โ No sensitive data - safe for public deployment
- โ Well-known domain - easy to verify correctness
8. Run development server
npm run devOpen http://localhost:3000 to see the app.
Provided by Neon Auth SDK:
POST /api/auth/signin- OAuth sign-in (Google/GitHub)POST /api/auth/signout- Sign outGET /api/auth/callback/*- OAuth callbacks
Health check endpoint
Response (200 OK):
{
"status": "ok",
"timestamp": "2024-11-06T15:30:00.000Z",
"database": "connected"
}Dashboard data query (requires authentication)
Fetches data from the Periodic Table sample dataset.
Response (200 OK):
{
"data": [
{
"AtomicNumber": 1,
"Element": "Hydrogen",
"Symbol": "H",
"AtomicMass": 1.007,
"Phase": "gas",
"Type": "Nonmetal"
},
{
"AtomicNumber": 2,
"Element": "Helium",
"Symbol": "He",
"AtomicMass": 4.002,
"Phase": "gas",
"Type": "Noble Gas"
}
],
"query_time_ms": 45,
"row_count": 10
}Response (401 Unauthorized):
{
"error": "Unauthorized",
"code": "UNAUTHORIZED"
}Full API documentation: Architecture Document
๐งช Testing Strategy
MVP (Phase 1):
- โ
Lint:
npm run lint(ESLint) - โ
Type Check:
npm run type-check(TypeScript) - โ
Build:
npm run build(Next.js) - โ Unit Tests: 38 tests (Vitest) - Configuration, Database, API Routes
- โ E2E Tests: Playwright (Health checks, Landing page, Cloud Run verification)
- โ Database Integration: Real Neon database with Periodic Table sample data
- โ CI/CD: All tests run automatically on every commit
- โ Manual E2E: See Story 4.5 Checklist
Growth Features (Phase 2):
- ๐ API Tests: Vitest (100% API route coverage)
- ๐ Component Tests: React Testing Library (70%+ coverage target)
- ๐ Performance Tests: Load testing and benchmarking
Run current tests:
# Lint code
npm run lint
# Type check
npm run type-check
# Build (validates entire app)
npm run build
# Unit tests - 38 tests (includes database integration)
npm run test:unit
# E2E tests (Playwright)
npm run test:e2e
# All tests together
npm testTest Coverage:
| Category | Tests | Description |
|---|---|---|
| Configuration | 18 tests | Zod schema validation, environment variables |
| Database | 16 tests | Connection, queries, error handling, performance |
| API Routes | 4 tests | Health check endpoint, error responses |
| Total | 38 tests | All tests run in CI/CD with real database |
Database Integration Tests:
All database tests run automatically using a real Neon database with Periodic Table sample data:
# Run database integration tests (included in test:unit)
npm run test:unit tests/unit/db.test.tsWhat's tested:
- โ Database connection and configuration
- โ SQL query execution with parameterized queries
- โ
query()andqueryOne()helper functions - โ Error handling and sanitization
- โ Query performance monitoring (slow query logging)
- โ Periodic Table sample data (118 elements)
- โ Cold start handling (Neon auto-suspend/resume)
CI/CD Integration:
All 38 tests run automatically in GitHub Actions:
- โ Tests use real Neon database (not mocked)
- โ
GitHub Secret
DEV_DATABASE_URLprovides database connection - โ Periodic Table sample data loaded via migration
- โ Tests must pass before deployment to dev environment
- โ Zero additional cost (GitHub Secrets are free)
Security: Database connection strings are encrypted as GitHub Secrets and never exposed in logs.
1. Review Documentation
Start here:
- ๐ Product Brief - Project overview
- ๐ PRD - Requirements (99.6% validated)
- ๐๏ธ Architecture - Technical design (100/100 score)
- ๐ Epic Breakdown - 32 implementable stories
2. Set Up Infrastructure
Follow these guides in order:
- Neon Infrastructure Setup Guide - PostgreSQL databases
- Cloud Run Setup Guide - Cloud Run services
- GitHub Actions Setup Guide - CI/CD pipeline
- Neon Auth Setup Guide - OAuth authentication
3. Implement Stories
Stories are designed for single-session completion:
- Epic 1: Foundation & Deployment Pipeline (11 stories)
- Epic 2: Database Infrastructure (6 stories)
- Epic 3: Authentication & Access Control (8 stories)
- Epic 4: Hello World Dashboard (7 stories)
Start with Story 1.1: Project Initialization
4. Deploy to Cloud Run
# Set variables
export PROJECT_ID=$(gcloud config get-value project)
export REGION="southamerica-east1"
export IMAGE_NAME="${REGION}-docker.pkg.dev/${PROJECT_ID}/role-directory/app"
# Build Docker image
docker build -t ${IMAGE_NAME}:latest .
# Push to Artifact Registry
docker push ${IMAGE_NAME}:latest
# Deploy to dev
gcloud run deploy role-directory-dev \
--image=${IMAGE_NAME}:latest \
--region=${REGION}See Architecture: Deployment Flow and Artifact Registry Migration Guide
1. Request Access
Contact the admin to add your email to the whitelist.
2. Sign In
Visit the application URL and click "Sign in with Google" (or GitHub).
3. View Dashboard
After authentication, you'll see:
- Your profile information
- Database query results (proves full stack works)
- Query performance metrics
Deployment Workflows:
- Release and Deployment Guide - Complete deployment procedures
- Cloud Run Setup Guide - Cloud Run service configuration (all environments)
- GitHub Actions Setup Guide - CI/CD pipeline configuration
Recovery Procedures:
- Rollback Procedures - How to rollback deployments in any environment
- Quick recovery from failed deployments (<3 minutes)
- Zero-downtime rollback via Cloud Run revision management
- Tested procedures for dev, staging, and production
Infrastructure Guides:
- Docker Usage Guide - Containerization and local development
- Neon Infrastructure Setup Guide - PostgreSQL database setup (all environments)
- Neon Auth Setup Guide - OAuth configuration
- Artifact Registry Migration Guide - Container image storage
Deploy to Dev (CI/CD):
# Automatically deploys on push to main
git push origin mainPromote Staging to Production:
# Manually triggered via GitHub Actions
# See: docs/guides/release-and-deployment-guide.mdRollback Production:
# List available revisions
gcloud run revisions list --service=role-directory-production --region=southamerica-east1
# Rollback to previous revision
gcloud run services update-traffic role-directory-production \
--region=southamerica-east1 \
--to-revisions=[PREVIOUS_REVISION]=100
# Verify rollback
curl -f -H "Authorization: Bearer $(gcloud auth print-identity-token)" \
[PRODUCTION_URL]/api/healthSee Rollback Procedures for comprehensive instructions.
Planning & Requirements:
- Product Brief - Vision & goals
- PRD - Product requirements (1,225 lines)
- Epics & Stories - Implementation breakdown (32 stories)
- PRD Validation Report - 99.6% pass rate
Architecture & Design:
- Architecture Document - Technical design (1,913 lines)
- Architecture Validation - 100/100 score
- Implementation Readiness - 98/100 confidence
- Tech Spec Epic 1 - Foundation & deployment
- Tech Spec Epic 2 - Database infrastructure
Setup & Operations:
- Neon Infrastructure Setup Guide - PostgreSQL database setup (all environments)
- Neon Auth Setup Guide - OAuth configuration
- Cloud Run Setup Guide - Cloud Run services (all environments)
- GitHub Actions Setup Guide - CI/CD pipeline configuration
- Docker Usage Guide - Local development and containerization
- Database Migrations Guide - Schema migration management
- Release and Deployment Guide - Deployment procedures and promotions
- Artifact Registry Migration Guide - GCR to Artifact Registry migration
- Playwright CI Debugging Guide - CI test debugging procedures
Project Status:
- Workflow Status - Current phase tracking
- Documentation Audit - Quality assessment (94.2/100)
We welcome contributions! Here's how you can help:
1. Review the Documentation
Before contributing, please read:
- Architecture Document - Implementation patterns
- Epic Breakdown - Story requirements
2. Follow Code Standards
- โ Naming Conventions: See Architecture: Consistency Rules
- โ API Route Pattern: See Architecture: API Route Pattern
- โ Component Pattern: See Architecture: Component Pattern
- โ
Date Format: Always use
YYYY-MM-DD HH:mm:ss(ADR-006)
3. Development Workflow
# Create a feature branch
git checkout -b feature/story-x.x-description
# Make your changes
# Follow story acceptance criteria from epics.md
# Lint and type check
npm run lint
npm run type-check
# Build to verify
npm run build
# Commit with descriptive message
git commit -m "feat: implement Story X.X - Description"
# Push and create pull request
git push origin feature/story-x.x-description4. Pull Request Guidelines
- Reference the story number in your PR title (e.g., "Story 2.3: Database Schema Migration Setup")
- Include acceptance criteria verification in PR description
- Ensure all linting and type checking passes
- Link to relevant documentation sections
- Be respectful and inclusive
- Focus on constructive feedback
- Follow the project's technical standards
- Ask questions if requirements are unclear
Created by: danielvm
Powered by:
- Next.js - React framework
- Neon - Serverless PostgreSQL & Auth
- Google Cloud - Cloud Run hosting
- BMAD Method - Project methodology
Inspiration:
- Infrastructure-first development philosophy
- Cost-optimized serverless architecture
- AI agent-friendly implementation patterns
Special Thanks:
- Neon team for serverless PostgreSQL and auth solutions
- Next.js team for excellent App Router implementation
- BMAD Method for comprehensive project methodology
MIT ยฉ danielvm
MIT License
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
- Discovery - Product brief created
- Planning - PRD defined & Epics defined (99.6% validation)
- Solutioning - Architecture designed (100/100 score)
MVP Goal: ONE feature through 3 environments (dev โ stg โ prd)
Progress:
- Epic 1: Foundation & Deployment Pipeline (11/11 stories) โ
- Epic 2: Database Infrastructure (2/6 stories) ๐
- Epic 3: Authentication & Access Control (0/8 stories)
- Epic 4: Hello World Dashboard (0/7 stories)
Estimated Completion: 4-8 days remaining for MVP (Epic 2-4)
Phase 2: Testing & Quality (Deferred from MVP)
- Unit tests (Vitest, 70%+ coverage)
- API integration tests (100% coverage)
- E2E tests (Playwright, 5-10 scenarios)
Phase 3: Admin Interface
- Admin UI for code generation
- Usage analytics per code
- Access logs dashboard
Phase 4: Additional Dashboard Pages
- Workflow status page
- Sprint status page
Phase 6: Core Application Features
- Role catalog display
- Pricing information by region
- Career track visualization
- Search and filtering
Phase 7: Public Launch
- Remove invitation codes (or make optional)
- Public marketing site
- Full feature set
- Documentation Issues: File an issue with label
documentation - Technical Questions: File an issue with label
question - Bug Reports: File an issue with label
bug
Made with โค๏ธ by danielvm | Documentation Grade: A (94.2/100) | Cost: ~$0-3/month