-
-
Notifications
You must be signed in to change notification settings - Fork 0
Development Workflow
Before starting development, ensure you have the following installed:
-
Node.js: Version 18 or higher
- Check version:
node --version - Download: https://nodejs.org/
- Check version:
-
PostgreSQL: Version 14 or higher
- Check version:
psql --version - Download: https://www.postgresql.org/download/
- Check version:
-
Git: For version control
- Check version:
git --version - Download: https://git-scm.com/downloads
- Check version:
-
npm or yarn: Package manager (npm comes with Node.js)
- PostGIS Extension: For geospatial features
- Prisma Studio: Database GUI (included with Prisma)
- VS Code: Recommended IDE with TypeScript support
- Docker: For containerized PostgreSQL (optional)
git clone https://github.com/benmed00/research-platform.git
cd research-platformnpm installThis will:
- Install all npm packages
- Run
postinstallscript to generate Prisma client
-- Connect to PostgreSQL
psql -U postgres
-- Create database
CREATE DATABASE research_platform;
-- (Optional) Install PostGIS extension
\c research_platform
CREATE EXTENSION IF NOT EXISTS postgis;Create a .env file in the project root:
# Copy example if available, or create new
cp .env.example .env # If example existsEdit .env with your database credentials:
# Database
DATABASE_URL="postgresql://username:password@localhost:5432/research_platform?schema=public"
# NextAuth
NEXTAUTH_URL="http://localhost:3000"
NEXTAUTH_SECRET="your-secret-key-here"Generate NEXTAUTH_SECRET:
openssl rand -base64 32# Generate Prisma client
npm run db:generate
# Push schema to database (creates tables)
npm run db:push
# Seed database with initial data
npm run db:seedDefault Admin Credentials (after seeding):
- Email:
admin@research-platform.ma - Password:
admin123
npm run devThe application will be available at:
- URL: http://localhost:3000
- Hot Reload: Enabled (changes auto-reload)
npm run buildCreates optimized production build in .next/ directory.
npm run startRuns production server (requires npm run build first).
npm run lintRuns ESLint to check code quality and style.
# Generate Prisma client (after schema changes)
npm run db:generate
# Push schema changes to database
npm run db:push
# Create migration (recommended for production)
npm run db:migrate
# Open Prisma Studio (database GUI)
npm run db:studio
# Seed database
npm run db:seed
# Reset database (⚠️ deletes all data)
npm run db:reset
# Check database connection
npm run db:checkDuring Development:
- Modify
prisma/schema.prisma - Run
npm run db:push(quick, for development) - Test changes
For Production:
- Modify
prisma/schema.prisma - Run
npm run db:migrate(creates migration file) - Review migration file
- Apply migration to production database
Before committing, update file metadata headers:
npm run headers:updateThis updates all TypeScript files with current metadata.
npm run git:branch feature/your-feature-nameOr manually:
git checkout -b feature/your-feature-nameAutomated (Recommended):
npm run git:commit-groupedThis automatically groups related changes into logical commits.
Manual:
git add .
git commit -m "feat: add new feature"Follow Conventional Commits:
-
feat:- New feature -
fix:- Bug fix -
docs:- Documentation -
style:- Code style -
refactor:- Refactoring -
test:- Tests -
chore:- Maintenance
npm run git:pushOr manually:
git push -u origin feature/your-feature-namenpm run git:verifyChecks Git configuration and setup.
Development (.env):
DATABASE_URL="postgresql://user:pass@localhost:5432/research_platform"
NEXTAUTH_URL="http://localhost:3000"
NEXTAUTH_SECRET="dev-secret-key"Production (set in hosting platform):
- Use secure, randomly generated secrets
- Use production database URL
- Set
NEXTAUTH_URLto production domain
Location: tsconfig.json
Key Settings:
- Strict mode enabled
- Path aliases:
@/*→./src/* - ES2020 target
- Module resolution: bundler
Usage:
// Use path aliases
import { Button } from "@/components/ui/button"
import { prisma } from "@/lib/prisma"Follow these patterns:
-
API Routes:
src/app/api/[resource]/route.ts -
Pages:
src/app/dashboard/[module]/page.tsx -
Components:
src/components/[feature]/component.tsx -
Utilities:
src/lib/[utility].ts -
Types:
src/types/[types].ts
-
Start development server:
npm run dev - Open browser: http://localhost:3000
- Test features: Navigate and test functionality
- Check console: Browser and terminal for errors
Prisma Studio:
npm run db:studioOpens GUI at http://localhost:5555
Direct Database Access:
psql -U username -d research_platformUsing Browser:
- Navigate to API routes directly
- Check Network tab in DevTools
Using curl:
# Get missions (requires authentication)
curl http://localhost:3000/api/missions \
-H "Cookie: next-auth.session-token=YOUR_TOKEN"-
Create database models in
prisma/schema.prisma -
Run migration:
npm run db:push -
Create API routes:
src/app/api/[module]/route.ts -
Create pages:
src/app/dashboard/[module]/page.tsx -
Create components:
src/components/[module]/ -
Add validation:
src/lib/validations.ts -
Update navigation:
src/components/layout/sidebar.tsx
-
Create route file:
src/app/api/[resource]/route.ts - Implement handlers: GET, POST, PUT, DELETE
-
Add authentication: Use
requireAuth()orrequireAdmin() - Add validation: Use Zod schemas
- Test endpoint: Use browser or API client
-
Create page file:
src/app/dashboard/[module]/page.tsx - Fetch data: Use Prisma in Server Component
-
Create UI: Use components from
src/components/ - Add navigation: Update sidebar if needed
- Test page: Navigate and verify functionality
-
Create component:
src/components/[feature]/component.tsx - Use TypeScript: Define props interface
- Style with Tailwind: Use utility classes
-
Export component:
export default Component - Use in pages: Import and use component
Database Connection Error:
- Check PostgreSQL is running
- Verify
DATABASE_URLin.env - Check database exists
- Verify credentials
Prisma Client Error:
npm run db:generateModule Not Found:
rm -rf node_modules package-lock.json
npm installTypeScript Errors:
- Check
tsconfig.jsonconfiguration - Verify imports use correct paths
- Run
npm run lintfor hints
Build Errors:
- Check for TypeScript errors
- Verify all imports are correct
- Check environment variables are set
Browser DevTools:
- Console for JavaScript errors
- Network tab for API calls
- React DevTools for component inspection
Terminal:
- Next.js shows compilation errors
- Prisma shows database errors
- Check terminal output for details
Prisma Studio:
npm run db:studioVisual database browser for debugging data issues.
Run linter:
npm run lintAuto-fix (when possible):
npm run lint -- --fixFollow these conventions:
- Use 2 spaces for indentation
- Use single quotes for strings
- Add trailing commas
- Use semicolons
- Use TypeScript strict mode
ESLint Configuration: .eslintrc.json
All TypeScript files should include metadata headers:
/**
* @file filename.ts
* @description Brief description
* @author Author name
* @created YYYY-MM-DD
* @updated YYYY-MM-DD
* @updates Count
* @lines Line count
* @size Size in KB
*/Update headers:
npm run headers:update- Fast Refresh: Enabled by default
- Incremental Compilation: TypeScript incremental builds
- SWC Minification: Faster than Babel
- Connection Pooling: Prisma handles automatically
-
Query Optimization: Use
selectto fetch only needed fields - Indexes: Already defined in schema
-
Aggregations: Use
groupByinstead of fetching all records
- Code Splitting: Automatic by Next.js
- Tree Shaking: Automatic
- Image Optimization: Use Next.js Image component
-
Bundle Analysis: Use
@next/bundle-analyzer(if needed)
- All tests pass
- Linter passes (
npm run lint) - Build succeeds (
npm run build) - Environment variables configured
- Database migrations ready
- Default password changed
- Documentation updated
# Build for production
npm run build
# Test production build locally
npm run startSet in hosting platform:
-
DATABASE_URL: Production database -
NEXTAUTH_URL: Production domain -
NEXTAUTH_SECRET: Strong random secret
# Development
npm run dev # Start dev server
npm run build # Build for production
npm run start # Start production server
npm run lint # Run linter
# Database
npm run db:generate # Generate Prisma client
npm run db:push # Push schema to database
npm run db:migrate # Create migration
npm run db:studio # Open Prisma Studio
npm run db:seed # Seed database
npm run db:reset # Reset database
# Git
npm run headers:update # Update file headers
npm run git:branch # Create feature branch
npm run git:commit-grouped # Create grouped commits
npm run git:push # Push branch
npm run git:verify # Verify Git setup-
Project Docs:
/docsdirectory -
Wiki:
/wikidirectory (this documentation) -
README: Root
README.md
- Next.js Docs: https://nextjs.org/docs
- Prisma Docs: https://www.prisma.io/docs
- TypeScript Docs: https://www.typescriptlang.org/docs
- Tailwind Docs: https://tailwindcss.com/docs
- GitHub Issues: Report bugs or request features
- Project Maintainers: Contact for questions
Follow this workflow to ensure consistent, high-quality development practices throughout the project.
Last Updated: January 2025