Skip to content

an e-commerce, scheduling, management website for my cousins equestrian riding and training center.

Notifications You must be signed in to change notification settings

sdirishguy/Hearts4horses

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

20 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Hearts4Horses 🐎

A comprehensive equestrian training and lesson management platform built with Next.js, Node.js, and PostgreSQL.

βœ… Critical Issues Resolved

βœ… FIXED: Main Server Implementation

  • The apps/api/src/server.ts file now properly implements an Express server
  • All middleware, routes, and error handling are properly configured
  • The application can now start and run successfully
  • Comprehensive security measures are in place (CORS, Helmet, Rate Limiting)
  • Proper graceful shutdown handling for database connections

Features

🏠 Public Website

  • Homepage - Compelling hero section with call-to-action
  • Services & Pricing - Dynamic lesson types and package pricing
  • Horse Profiles - Individual horse information and availability
  • Gallery - Photo and video showcase
  • Events - Upcoming camps, shows, and special events
  • Contact - Contact form and location information

πŸ‘¨β€πŸŽ“ Student Portal

  • Registration & Intake - New student onboarding with e-signatures
  • Lesson Booking - Real-time availability calendar
  • Package Management - View and purchase lesson packages
  • Progress Tracking - Instructor notes and skill development
  • Payment History - Transaction records and receipts

🏒 Admin Dashboard

  • Calendar Management - Create recurring lesson templates
  • Horse Management - Horse profiles, health records, availability
  • Student Management - Student profiles, progress tracking
  • Content Management - Upload photos, update pricing, manage testimonials
  • Reports - Revenue, attendance, and utilization analytics

πŸ’³ E-commerce

  • Stripe Integration - Secure payment processing
  • Lesson Packages - Pre-paid lesson bundles
  • Merchandise - Branded products and gear
  • Gift Certificates - Digital gift cards

πŸ”§ Technical Features

  • Responsive Design - Mobile-first approach
  • Real-time Scheduling - Dynamic availability updates
  • Email/SMS Notifications - Automated reminders
  • Weather Integration - Weather-aware scheduling
  • Social Media Integration - Instagram/Facebook feeds

Tech Stack

Frontend

  • Next.js 14 - React framework with App Router
  • TypeScript 5.3.3 - Type-safe development
  • Tailwind CSS 3.4.0 - Utility-first styling
  • Framer Motion 10.16.16 - Smooth animations
  • React Hook Form 7.48.2 - Form management with Zod validation
  • Axios 1.6.2 - HTTP client
  • Lucide React 0.294.0 - Icon library
  • React Calendar 4.6.0 - Calendar components
  • React Dropzone 14.2.3 - File upload handling
  • React Signature Canvas 1.0.6 - Digital signatures

Backend

  • Node.js 18+ - JavaScript runtime
  • Express.js 4.18.2 - Web framework with comprehensive middleware stack
  • TypeScript 5.3.3 - Type-safe development
  • Prisma 5.7.1 - Database ORM with comprehensive schema
  • PostgreSQL - Primary database
  • JWT (jsonwebtoken 9.0.2) - Authentication with role-based access
  • Bcryptjs 2.4.3 - Password hashing
  • Stripe 14.10.0 - Payment processing with webhooks
  • Express Rate Limit 7.1.5 - Rate limiting
  • Helmet 7.1.0 - Security headers
  • CORS 2.8.5 - Cross-origin resource sharing

External Services & Integrations

  • Stripe - Payment processing with webhook handling
  • Twilio 4.19.0 - SMS notifications
  • Cloudinary 1.41.0 - Image/video storage
  • WeatherAPI - Weather data integration
  • Nodemailer 6.9.7 - Email notifications
  • Mailchimp - Email marketing (configured but not implemented)

Infrastructure

  • AWS Lightsail - Hosting platform
  • NGINX - Reverse proxy
  • Let's Encrypt - SSL certificates
  • PM2 - Process manager for Node.js
  • Docker - Containerization (implied by deployment setup)

Development Tools

  • Concurrently 8.2.2 - Run multiple commands
  • Prettier 3.1.0 - Code formatting
  • ESLint 8.56.0 - Code linting
  • Lint-staged 15.2.0 - Pre-commit hooks
  • Husky 8.0.3 - Git hooks
  • TSX 4.6.2 - TypeScript execution

πŸ“‹ Code Review Summary

βœ… Strengths

Frontend Architecture:

  • Well-structured Next.js 14 application with App Router
  • Comprehensive TypeScript implementation with proper type safety
  • Modern React patterns with custom hooks and context providers
  • Excellent component organization and reusability
  • Proper form validation with React Hook Form + Zod
  • Responsive design with Tailwind CSS
  • Good separation of concerns between components and business logic

Backend Architecture:

  • Comprehensive Prisma schema with proper relationships
  • Well-implemented authentication and authorization system
  • Role-based access control with multiple user types
  • Proper input validation with Zod schemas
  • Good error handling and logging patterns
  • Comprehensive activity logging system
  • Proper security middleware (Helmet, CORS, Rate Limiting)

Database Design:

  • Well-normalized schema with proper relationships
  • Comprehensive user management (students, guardians, instructors, admins)
  • Detailed horse management with health records
  • Flexible lesson scheduling system
  • Proper payment and order tracking
  • Good use of indexes for performance

Security Implementation:

  • JWT-based authentication with proper token validation
  • Password hashing with bcrypt
  • Input sanitization and validation
  • Rate limiting on authentication routes
  • Proper CORS configuration
  • Stripe webhook signature verification
  • Activity logging for audit trails

⚠️ Issues Found

Critical Issues:

  1. βœ… RESOLVED: Main Server Implementation - Express server now properly implemented
  2. βœ… RESOLVED: Application Startup - Server can now start and run successfully

High Priority Issues:

  1. Inconsistent Error Handling - Some routes lack proper error handling
  2. Missing Input Validation - Some endpoints don't validate all inputs
  3. Hardcoded Values - Some configuration values are hardcoded
  4. Missing API Documentation - No OpenAPI/Swagger documentation
  5. Incomplete Testing - No test files found in the codebase

Medium Priority Issues:

  1. Code Duplication - Some utility functions are duplicated
  2. Missing Environment Validation - No validation of required environment variables
  3. Incomplete Logging - Some operations lack proper logging
  4. Missing Health Checks - No health check endpoints
  5. Incomplete Error Messages - Some error messages could be more descriptive

Low Priority Issues:

  1. Code Comments - Some complex logic lacks documentation
  2. Type Definitions - Some types could be more specific
  3. Performance Optimization - Some database queries could be optimized

πŸ”§ Recommended Fixes

Immediate (Critical):

  1. βœ… COMPLETED: Express server implemented in apps/api/src/server.ts
  2. βœ… COMPLETED: Middleware stack configured (CORS, Helmet, Rate Limiting, Error Handling)
  3. βœ… COMPLETED: Health check endpoints added
  4. πŸ”„ IN PROGRESS: Configure proper logging and monitoring

Short Term (High Priority):

  1. Add comprehensive input validation to all endpoints
  2. Implement proper error handling middleware
  3. Add API documentation with OpenAPI/Swagger
  4. Create comprehensive test suite
  5. Add environment variable validation

Medium Term:

  1. Optimize database queries and add proper indexing
  2. Implement caching strategy
  3. Add comprehensive logging and monitoring
  4. Implement proper backup and recovery procedures
  5. Add performance monitoring

Long Term:

  1. Implement microservices architecture if needed
  2. Add comprehensive CI/CD pipeline
  3. Implement proper monitoring and alerting
  4. Add comprehensive security auditing
  5. Implement proper disaster recovery procedures

Security Considerations

πŸ”’ Critical Security Measures

  • Environment Variables: Never commit .env files. Use .env.example as templates.
  • JWT Secrets: Use strong, unique JWT secrets. Never use fallback secrets.
  • Database Credentials: Rotate database passwords regularly.
  • API Keys: Store sensitive API keys server-side only.
  • Rate Limiting: Auth routes are rate-limited to prevent brute force attacks.
  • CORS: Configured to allow only trusted origins.
  • Input Validation: All inputs validated with Zod schemas.
  • Error Logging: Sensitive data is sanitized before logging.

πŸ›‘οΈ Authentication & Authorization

  • JWT tokens with secure configuration
  • Role-based access control (RBAC)
  • Server-side route protection
  • Middleware guards for sensitive endpoints

πŸ” Data Protection

  • Password hashing with bcrypt
  • HTTPS enforcement in production
  • Secure cookie configuration
  • Input sanitization and validation

βœ… Server Implementation Complete

The Express server has been successfully implemented and is ready to run!

Current Server Features

The apps/api/src/server.ts file now includes:

  • βœ… Express Server Setup - Proper server initialization with TypeScript
  • βœ… Security Middleware - Helmet, CORS, rate limiting, and CSP headers
  • βœ… Environment Validation - Validates required environment variables on startup
  • βœ… All API Routes - Auth, user, public, student, admin, payment, and webhook routes
  • βœ… Error Handling - Comprehensive error handling middleware
  • βœ… Health Check - /health endpoint for monitoring
  • βœ… Graceful Shutdown - Proper Prisma disconnection on server termination
  • βœ… Production Ready - Environment-aware logging and configuration

Seed File Organization

  • βœ… Correct Location: apps/api/prisma/seed.ts - Properly located and configured
  • βœ… Comprehensive Data: Includes roles, lesson types, packages, forms, and admin user
  • βœ… Duplicate Removed: Cleaned up duplicate seed file from src/scripts/

Quick Start

Prerequisites

  • Node.js 18+
  • PostgreSQL 14+
  • npm or yarn

1. Clone the Repository

git clone <repository-url>
cd hearts4horses

2. Install Dependencies

npm install

3. Set Up Environment Variables

Backend (.env in apps/api/)

# Database
DATABASE_URL="postgresql://username:password@localhost:5432/hearts4horses"

# JWT Secret
JWT_SECRET="your-super-secret-jwt-key-here"

# Stripe Configuration
STRIPE_SECRET_KEY="sk_test_your_stripe_secret_key"
STRIPE_WEBHOOK_SECRET="whsec_your_webhook_secret"

# Frontend URL
FRONTEND_URL="http://localhost:3000"

# Optional Integrations
CLOUDINARY_CLOUD_NAME="your-cloud-name"
CLOUDINARY_API_KEY="your-api-key"
CLOUDINARY_API_SECRET="your-api-secret"
TWILIO_ACCOUNT_SID="your-account-sid"
TWILIO_AUTH_TOKEN="your-auth-token"
MAILCHIMP_API_KEY="your-api-key"
OPENWEATHER_API_KEY="your-api-key"

Frontend (.env.local in apps/web/)

# API Configuration
NEXT_PUBLIC_API_URL="http://localhost:4000"

# Weather API (WeatherAPI.com - HTTPS endpoint)
NEXT_PUBLIC_WEATHERAPI_KEY="your-weatherapi-key-here"

4. Set Up Database

# Generate Prisma client
npm run db:generate

# Run migrations
npm run db:migrate

# Seed database with initial data
npm run db:seed

5. Start Development Servers

# Start both frontend and backend
npm run dev

# Or start individually
npm run dev:web    # Frontend on http://localhost:3000
npm run dev:api    # Backend on http://localhost:4000

Project Structure

hearts4horses/
β”œβ”€β”€ apps/
β”‚   β”œβ”€β”€ web/                 # Next.js frontend
β”‚   β”‚   β”œβ”€β”€ app/            # App Router pages
β”‚   β”‚   β”œβ”€β”€ components/     # React components
β”‚   β”‚   └── lib/           # Utilities and helpers
β”‚   └── api/                # Express.js backend
β”‚       β”œβ”€β”€ src/
β”‚       β”‚   β”œβ”€β”€ routes/     # API routes
β”‚       β”‚   β”œβ”€β”€ middleware/ # Express middleware
β”‚       β”‚   β”œβ”€β”€ lib/        # Database and utilities
β”‚       β”‚   └── scripts/    # Database seeds
β”‚       └── prisma/         # Database schema
β”œβ”€β”€ packages/
β”‚   └── shared/             # Shared TypeScript types
└── package.json            # Root package.json

API Endpoints

Authentication

  • POST /api/v1/auth/register - User registration
  • POST /api/v1/auth/login - User login
  • GET /api/v1/auth/me - Get current user

Public

  • GET /api/v1/public/horses - List horses
  • GET /api/v1/public/services - Lesson types and pricing
  • GET /api/v1/public/gallery - Media gallery
  • GET /api/v1/public/testimonials - Customer testimonials
  • POST /api/v1/public/contact - Contact form submission

Student Portal

  • GET /api/v1/student/slots - Available lesson slots
  • POST /api/v1/student/bookings - Book a lesson
  • GET /api/v1/student/bookings - Student's bookings
  • GET /api/v1/student/packages - Student's packages

Admin

  • GET /api/v1/admin/horses - Manage horses
  • POST /api/v1/admin/templates - Create lesson templates
  • POST /api/v1/admin/slots/generate - Generate availability slots
  • GET /api/v1/admin/students - Manage students
  • POST /api/v1/admin/media/upload - Upload content

Payments

  • POST /api/v1/payments/packages/checkout - Create Stripe checkout
  • POST /api/v1/webhooks/stripe - Stripe webhook handler

Deployment

AWS Lightsail Setup

  1. Create Lightsail Instance

    # Ubuntu 22.04 LTS
    # 2GB RAM, 1 vCPU minimum
  2. Install Dependencies

    sudo apt update && sudo apt upgrade -y
    curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash -
    sudo apt install -y nodejs nginx
    sudo npm i -g pm2
  3. Clone and Build

    cd /var/www
    git clone <repository-url> hearts4horses
    cd hearts4horses
    npm install
    npm run build
  4. Set Up Environment

    # Copy environment files
    cp apps/api/env.example apps/api/.env
    cp apps/web/.env.example apps/web/.env.local
    
    # Edit with your actual values
    nano apps/api/.env
    nano apps/web/.env.local
  5. Database Setup

    npm run db:generate
    npm run db:migrate
    npm run db:seed
  6. Start Services

    # Start API
    cd apps/api
    pm2 start "npm run start" --name hearts-api
    
    # Start Web
    cd ../web
    pm2 start "npm run start" --name hearts-web
    
    pm2 save
    pm2 startup
  7. NGINX Configuration

    # /etc/nginx/sites-available/hearts4horses
    server {
      listen 80;
      server_name hearts4horses.com www.hearts4horses.com;
      
      location / {
        proxy_pass http://127.0.0.1:3000;
        proxy_http_version 1.1;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
      }
    }
    
    server {
      listen 80;
      server_name api.hearts4horses.com;
      
      location / {
        proxy_pass http://127.0.0.1:4000;
        proxy_http_version 1.1;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
      }
    }
  8. SSL Certificate

    sudo apt install certbot python3-certbot-nginx
    sudo certbot --nginx -d hearts4horses.com -d www.hearts4horses.com
    sudo certbot --nginx -d api.hearts4horses.com

Customization

Colors

The color palette is defined in apps/web/tailwind.config.ts:

  • Barn Brown (#4B352A) - Primary color
  • Copper (#CA7842) - Accent color
  • Sage (#B2CD9C) - Muted color
  • Butter (#F0F2BD) - Light accent

Content

  • Update horse information in the admin dashboard
  • Modify lesson types and pricing via the admin interface
  • Upload photos and videos through the media manager
  • Customize testimonials and events

Contributing

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

Support

For technical support or questions:

  • Create an issue in the repository
  • Contact the development team
  • Check the documentation

License

This project is licensed under the MIT License - see the LICENSE file for details.


Hearts4Horses - Making equestrian dreams come true, one lesson at a time. 🐎✨

About

an e-commerce, scheduling, management website for my cousins equestrian riding and training center.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages