Development Guide
Development Guide
Section titled “Development Guide”This guide provides comprehensive instructions for setting up the development environment, running the project locally, and contributing to the 8531 TeamSite.
🏗️ Project Structure
Section titled “🏗️ Project Structure”/srv/team.8531.ca/├── .dev/ # Development documentation├── src/│ ├── components/ # Astro components│ │ ├── AuthButton.astro # Authentication UI component│ │ └── GoogleDriveFolder.astro # Reusable Google Drive folder display│ ├── content/ # Documentation content│ │ ├── docs/ # All documentation pages│ │ │ ├── public/ # Publicly accessible content│ │ │ ├── protected/ # Member+ restricted content│ │ │ └── admin/ # Admin only content│ │ └── config.ts # Content schema and configuration│ ├── lib/ # Core utilities and services│ │ ├── auth.ts # JWT verification and auth utilities│ │ ├── auth-client.ts # Client-side authentication helpers│ │ ├── config.ts # Environment detection and configuration│ │ ├── nav.ts # Navigation generation│ │ ├── google-drive.ts # Google Drive integration service│ │ ├── folder-utils.ts # Folder utility functions│ │ └── README-google-drive.md # Google Drive documentation│ ├── data/ # Data and configuration│ │ └── pdfs.ts # PDF metadata management│ ├── pages/ # Astro pages and API routes│ │ ├── api/│ │ │ ├── auth/│ │ │ │ ├── login.ts # OAuth login endpoint│ │ │ │ ├── callback.ts # OAuth callback handler│ │ │ │ └── logout.ts # Logout endpoint│ │ │ ├── pdfs-dev/ # PDF file access endpoints│ │ │ │ ├── index.ts # PDF listing and search│ │ │ │ └── [fileId].ts # PDF download endpoint│ │ │ └── test/ # Testing endpoints│ │ │ └── drive-test.ts # Google Drive testing│ │ ├── session.ts # Session verification endpoint│ │ └── index.astro # Homepage│ ├── layouts/Layout.astro # Main site layout│ ├── route-middleware.ts # Authentication middleware│ └── styles/global.css # Global styles├── astro.config.mjs # Astro configuration├── package.json # Dependencies and scripts├── vercel.json # Deployment configuration├── .env.example # Environment variables template└── README.md # Main project README🛠️ Technology Stack
Section titled “🛠️ Technology Stack”- Framework: Astro 5.15.3 with Starlight
- Styling: Tailwind CSS 4.1.16
- Authentication: JWT with RS256 encryption
- File Storage: Google Drive API v3
- Deployment: Vercel with serverless functions
- Content: Markdown-based with frontmatter
- Language: TypeScript
📦 Installation & Setup
Section titled “📦 Installation & Setup”Prerequisites
Section titled “Prerequisites”- Node.js 18+ (recommend using Node.js 20+)
- npm or yarn package manager
- Git
Quick Start
Section titled “Quick Start”-
Clone the repository
Terminal window git clone <repository-url>cd team.8531.ca -
Install dependencies
Terminal window npm install -
Set up environment variables
Terminal window cp .env.example .env.local -
Configure environment variables Edit
.env.localwith your configuration (see Environment Configuration) -
Start development server
Terminal window npm run dev -
Open your browser Navigate to
http://localhost:4321
🧞 Development Commands
Section titled “🧞 Development Commands”| Command | Action |
|---|---|
npm install | Install dependencies |
npm run dev | Start local development server at localhost:4321 |
npm run build | Build production site to ./dist/ |
npm run preview | Preview build locally before deployment |
npm run astro | Run Astro CLI commands |
Development Server Options
Section titled “Development Server Options”The development server supports additional options:
# Start on specific portnpm run dev -- --port 4322
# Start with specific hostnpm run dev -- --host 0.0.0.0
# Open browser automaticallynpm run dev -- --open🔧 Environment Configuration
Section titled “🔧 Environment Configuration”Required Environment Variables
Section titled “Required Environment Variables”Create a .env.local file with the following variables:
# Site ConfigurationNODE_ENV=developmentSITE_URL=http://localhost:4321
# AuthenticationAUTH_GATEWAY_URL=https://auth.8531.caJWT_SECRET=your-jwt-secret-that-is-at-least-32-characters-longJWT_ISSUER=https://auth.8531.caJWT_AUDIENCE=8531-apps
# Google Drive (optional - see Google Drive Integration guide)GOOGLE_PRIVATE_KEY="-----BEGIN PRIVATE KEY-----\nYour-private-key\n-----END PRIVATE KEY-----"Environment-Specific Settings
Section titled “Environment-Specific Settings”The application automatically detects its environment:
Development (NODE_ENV=development)
Section titled “Development (NODE_ENV=development)”- Detailed error messages
- Source maps enabled
- Authentication testing modes available
- Live reload enabled
Production (NODE_ENV=production)
Section titled “Production (NODE_ENV=production)”- Optimized build
- Minified assets
- Production authentication flows
- Error reporting simplified
Testing (NODE_ENV=test)
Section titled “Testing (NODE_ENV=test)”- Test-specific configurations
- Mock authentication available
- Database connections disabled
🧪 Testing
Section titled “🧪 Testing”Local Testing
Section titled “Local Testing”Testing Authentication
Section titled “Testing Authentication”Test different user roles with query parameters:
# Test as Guest (default)http://localhost:4321
# Test as Memberhttp://localhost:4321?test_role=Member
# Test as Core Teamhttp://localhost:4321?test_role=CoreTeam
# Test as Adminhttp://localhost:4321?test_role=AdminTesting Content Status
Section titled “Testing Content Status”Test content visibility with status overrides:
# Show all content regardless of statushttp://localhost:4321?show_status=true
# Combine role and status testinghttp://localhost:4321?test_role=CoreTeam&show_status=trueTesting Google Drive Integration
Section titled “Testing Google Drive Integration”# Test Google Drive connectioncurl "http://localhost:4321/api/test/drive-test?action=list"
# Test file accesscurl "http://localhost:4321/api/test/drive-test?action=download&fileId=YOUR_FILE_ID"Component Testing
Section titled “Component Testing”When creating new components:
- Create test pages in development directories
- Test with different authentication states
- Verify responsive design
- Check accessibility features
API Testing
Section titled “API Testing”Use tools like curl or Postman to test API endpoints:
# Test authentication endpointcurl -X GET "http://localhost:4321/api/auth/login"
# Test session verificationcurl -X GET "http://localhost:4321/api/session"
# Test PDF endpoint with foldercurl "http://localhost:4321/api/pdfs-dev?folderId=YOUR_FOLDER_ID"🎨 Working with Styles
Section titled “🎨 Working with Styles”Global Styles
Section titled “Global Styles”Global styles are defined in src/styles/global.css:
- CSS custom properties (variables)
- Base styles
- Utility classes
Component Styles
Section titled “Component Styles”Components can include scoped styles:
---// Your component logic here---
<style> .my-component { color: var(--sl-color-text); }</style>Tailwind CSS
Section titled “Tailwind CSS”Tailwind is configured with:
- Custom color scheme matching Starlight
- Responsive utilities
- Dark mode support
🔌 Adding New Features
Section titled “🔌 Adding New Features”Creating API Endpoints
Section titled “Creating API Endpoints”- Create a new file in
src/pages/api/ - Export a
GET(or other HTTP method) function - Handle authentication if needed
- Return proper responses
Example:
import type { APIRoute } from 'astro';
export const GET: APIRoute = async ({ request }) => { // Your API logic here return new Response(JSON.stringify({ success: true }), { status: 200, headers: { 'Content-Type': 'application/json' } });};Creating Components
Section titled “Creating Components”- Create
.astrofiles insrc/components/ - Use TypeScript for type safety
- Include props validation when needed
- Add responsive design
Example:
---export interface Props { title: string; subtitle?: string;}
const { title, subtitle } = Astro.props;---
<div class="my-component"> <h1>{title}</h1> {subtitle && <p>{subtitle}</p>} <slot /></div>
<style> .my-component { padding: 1rem; border: 1px solid var(--sl-color-gray-6); border-radius: 8px; }</style>Adding Content
Section titled “Adding Content”- Create
.mdfiles in appropriate content directories - Include proper frontmatter
- Follow the content creation workflow
- Test with different roles
🔄 Hot Module Replacement
Section titled “🔄 Hot Module Replacement”The development server supports:
- Live reload for file changes
- Hot module replacement for styles
- Fast refresh for components
- Content updates without full page reload
🐛 Debugging
Section titled “🐛 Debugging”Common Issues
Section titled “Common Issues”-
Port Already in Use
Terminal window # Find process using port 4321lsof -ti:4321# Kill the processkill -9 $(lsof -ti:4321)# Or use different portnpm run dev -- --port 4322 -
Authentication Not Working
- Check environment variables
- Verify AUTH_GATEWAY_URL is correct
- Check browser console for errors
-
Build Errors
- Check TypeScript errors
- Verify all dependencies are installed
- Clean and reinstall if needed
-
Content Not Showing
- Verify file permissions (644)
- Check frontmatter syntax
- Test with different roles
Debug Mode
Section titled “Debug Mode”Enable debug logging:
# Set debug environment variableDEBUG=* npm run devBrowser DevTools
Section titled “Browser DevTools”Use browser developer tools to:
- Inspect network requests
- Check console for errors
- Examine local storage/cookies
- Debug JavaScript issues
📝 Code Style Guide
Section titled “📝 Code Style Guide”TypeScript
Section titled “TypeScript”- Use TypeScript for all new code
- Define interfaces for complex objects
- Use proper typing for functions
- Enable strict mode in tsconfig.json
- Use
.astrofor components - Keep logic in the frontmatter
- Use slots for flexible content
- Follow Astro best practices
Markdown
Section titled “Markdown”- Use standard Markdown syntax
- Include proper frontmatter
- Use relative links for internal content
- Add alt text for images
🤝 Contributing
Section titled “🤝 Contributing”Before Contributing
Section titled “Before Contributing”- Fork the repository
- Create a feature branch
- Make your changes
- Test thoroughly
- Submit a pull request
Code Review Process
Section titled “Code Review Process”- All changes require review
- Automated tests must pass
- Documentation must be updated
- Follow coding standards
- Test with different user roles
Commit Messages
Section titled “Commit Messages”Use conventional commit messages:
feat:for new featuresfix:for bug fixesdocs:for documentationrefactor:for code refactoringtest:for adding testschore:for maintenance
📚 Additional Resources
Section titled “📚 Additional Resources”Documentation
Section titled “Documentation”- VS Code Extensions
- Astro
- Tailwind CSS IntelliSense
- TypeScript Importer
- Markdown All in One
Helpful Scripts
Section titled “Helpful Scripts”Create custom npm scripts in package.json:
{ "scripts": { "dev": "astro dev", "build": "astro build", "preview": "astro preview", "clean": "rm -rf dist node_modules/.astro", "type-check": "tsc --noEmit", "lint": "eslint src --ext .ts,.astro", "format": "prettier --write src/**/*.{ts,astro,md}" }}🚀 Deployment
Section titled “🚀 Deployment”Building for Production
Section titled “Building for Production”# Build optimized versionnpm run build
# Preview before deploymentnpm run previewVercel Deployment
Section titled “Vercel Deployment”The project is configured for Vercel deployment:
- Connect repository to Vercel
- Configure environment variables
- Automatic deployment on push to main branch
- Preview deployments for pull requests
Environment Variables for Production
Section titled “Environment Variables for Production”Configure these in Vercel:
NODE_ENV=productionSITE_URL=https://team.8531.caAUTH_GATEWAY_URL=https://auth.8531.caJWT_SECRET(generate a secure random string)- All Google Drive variables if using file storage