Skip to content

alexinslc/depot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

475 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Depot - Modern Rails 8.1 E-Commerce Application

Testing Linting Security Docker Build

A modern e-commerce application built with Rails 8.1.0 and Ruby 3.3.6, showcasing the latest Rails 8 features including the complete "Solid" stack.

Originally based on the Agile Web Development with Rails 7 book by Sam Ruby, this project has been completely upgraded to Rails 8.1.0 with modern development practices, CI/CD, and containerization.

✨ Key Features

Rails 8 "Solid" Stack (Zero Redis!)

  • πŸš€ Solid Queue - Database-backed background jobs
  • πŸ’Ύ Solid Cache - Database-backed caching
  • πŸ”Œ Solid Cable - Database-backed WebSockets
  • πŸ” Rails 8 Authentication - Modern session-based auth with rate limiting

Modern Development Stack

  • βœ… Ruby 3.3.6 with YJIT enabled
  • βœ… Rails 8.1.0 with all latest features
  • βœ… Tailwind CSS 4.x for styling
  • βœ… Hotwire (Turbo + Stimulus) for interactivity
  • βœ… SQLite3 for database (production-ready with proper configuration)

DevOps & Infrastructure

  • 🐳 Docker support with multi-stage builds
  • 🐳 Docker Compose for local development
  • πŸ€– Complete CI/CD Pipeline with GitHub Actions
  • πŸ”’ Security scanning with Brakeman and Bundler Audit
  • πŸ“Š Code quality enforcement with RuboCop
  • πŸ§ͺ Automated testing on every commit

πŸ“‹ Requirements

  • Ruby: 3.3.6
  • Rails: 8.1.0
  • Node.js: 18.x or later (for Tailwind CSS)
  • Docker & Docker Compose: Latest (optional, for containerized development)

πŸš€ Getting Started

Option 1: Native Development

  1. Install dependencies

    bundle install
  2. Set up databases

    bin/rails db:setup
  3. Run the development server

    bin/dev

    Access at http://localhost:3000

Option 2: Docker Development

  1. Start all services

    docker compose up

    Access at http://localhost:3000

  2. Run commands in container

    docker compose exec web bin/rails console
    docker compose exec web bin/rails test

πŸ§ͺ Testing

Run the full test suite:

bin/rails test

Run specific test types:

bin/rails test:models
bin/rails test:controllers
bin/rails test:system

πŸ” Authentication

The application includes Rails 8's new authentication system:

  • Session-based authentication with secure, httponly cookies
  • Rate limiting (10 attempts per 3 minutes)
  • Password reset via email
  • Multi-session support with session tracking

Login

Visit /session/new to sign in.

Test User

Check test/fixtures/users.yml for test credentials.

πŸ“¦ Database Structure

The application uses SQLite3 with separate databases for isolation:

  • db/development.sqlite3 - Main application data
  • db/queue_development.sqlite3 - Solid Queue jobs
  • db/cache_production.sqlite3 - Solid Cache (production only)
  • db/cable_production.sqlite3 - Solid Cable (production only)

πŸ—οΈ Architecture

Models

  • Product - E-commerce products with validations
  • User - Authenticated users with secure passwords
  • Session - User sessions with IP and user agent tracking

Controllers

  • StoreController - Public storefront (unauthenticated)
  • ProductsController - Product management (unauthenticated for demo)
  • SessionsController - User authentication
  • PasswordsController - Password reset flow

Background Jobs

Background jobs are processed by Solid Queue:

bin/jobs  # Start job workers

🚒 Deployment

Docker Production Build

docker build -t depot:latest .
docker run -p 3000:3000 \
  -e RAILS_ENV=production \
  -e SECRET_KEY_BASE=$(bin/rails secret) \
  depot:latest

Production Considerations

  1. Database: Consider PostgreSQL for high-traffic production use
  2. Assets: Assets are precompiled in Docker image
  3. Background Jobs: Run bin/jobs as a separate process
  4. Environment Variables: Set SECRET_KEY_BASE securely
  5. HTTPS: Use a reverse proxy (nginx, Caddy) for SSL

πŸ”„ CI/CD Pipeline

Automated workflows run on every PR and push to main:

  • Testing - Full test suite with minitest
  • Linting - RuboCop style and quality checks
  • Security - Brakeman and bundler-audit scans
  • Docker - Build and publish images to GHCR

πŸ› οΈ Development Tools

Code Quality

bundle exec rubocop                    # Run linter
bundle exec rubocop --auto-correct-all # Auto-fix issues

Security Scanning

bundle exec brakeman --no-pager        # Rails security scan
bundle exec bundler-audit check        # Dependency vulnerabilities

Database Management

bin/rails db:migrate                   # Run migrations
bin/rails db:rollback                  # Rollback last migration
bin/rails db:seed                      # Seed database
bin/rails db:reset                     # Reset database

πŸ“š Rails 8 Features Used

This application demonstrates many Rails 8 features:

  • βœ… Solid Queue - Background job processing without Redis
  • βœ… Solid Cache - Database-backed caching
  • βœ… Solid Cable - WebSocket pub/sub without Redis
  • βœ… Authentication Generator - Secure session-based auth
  • βœ… Rate Limiting - Built-in request throttling
  • βœ… Kamal 2 Ready - Modern deployment configuration
  • βœ… Propshaft - Modern asset pipeline (via Sprockets for compatibility)
  • βœ… Tailwind CSS 4.x - JIT compilation

πŸ› Troubleshooting

Tests Failing

bin/rails db:test:prepare
bin/rails test

Port Already in Use

# Find and kill process on port 3000
lsof -ti:3000 | xargs kill -9

Docker Issues

docker compose down -v  # Remove volumes
docker compose build    # Rebuild images
docker compose up       # Start fresh

πŸ“– Documentation

🀝 Contributing

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Run tests (bin/rails test)
  4. Run linter (bundle exec rubocop)
  5. Commit changes (git commit -m 'Add amazing feature')
  6. Push to branch (git push origin feature/amazing-feature)
  7. Open a Pull Request

All PRs are automatically tested by CI/CD pipeline.

πŸ“ License

This project is available for educational purposes.

πŸ™ Acknowledgments


Built with ❀️ using Rails 8.1.0 and Ruby 3.3.6

About

E-Commerce Rails App - from Agile Web Development with Rails 7 - but upgraded to 8.1.0

Topics

Resources

Contributing

Security policy

Stars

8 stars

Watchers

1 watching

Forks

Packages

 
 
 

Contributors