A Ruby on Rails API-only microservice with the following specifications:
- Rails 7.2.1
- Ruby 3.3.0
- MySQL 8.0.40
- Redis 7.0
This project is configured to work with GitHub Codespaces, which provides a complete development environment in the cloud.
- Click on the "Code" button in your GitHub repository
- Select the "Codespaces" tab
- Click "Create codespace on main"
The codespace will automatically:
- Set up a development container with Ruby 3.3.0
- Install Rails 7.2.1
- Set up MySQL 8.0.40 and Redis 7.0
- Install all the necessary extensions for VS Code
- Run
bundle installto install all dependencies - Create the development database
The devcontainer comes with these pre-installed extensions:
- GitLens
- Ruby LSP
- Solargraph
- Ruby
- Endwise
- Ruby Rubocop
- YAML
- Rainbow CSV
- Docker
- ESLint
- Prettier
- Once the Codespace is started, you can run Rails commands in the terminal:
# Setup .env file
cp .env.sample .env
# Start the Rails server
rails s
# Run a console
rails c
# Generate components with rails (examples)
rails generate migration create_users
rails generate model user username:string name:string
rails generate controller Api::V1::Users-
The following ports are forwarded:
- 3000: Rails server
- 3306: MySQL
- 6379: Redis
-
Database commands:
# Create the database, load schema, and seed data
rails db:setup- MySQL: Available at
db:3306with default usernamerootand default passwordpassword - Redis: Available at
redis:6379
This is an API-only Rails application. The main existing components are:
app/controllers/api: Contains API controllersapp/models: Data modelsapp/services: Service objects for business logicapp/jobs: Sidekiq background jobs
This project uses RSpec for testing:
# Run all tests
rspec
# Run specific tests
rspec spec/models/user_spec.rbAPI documentation is generated using RSwag:
# Generate API documentation
rails rswag:specs:swaggerizeAfter generating, the API documentation is available at /api-docs once the server is started.
- Simple token-based login & authentication features are ready to use.
- User passwords are already hashed using BCrypt.
- API documentation for existing endpoints are available through Swagger.
- Logging with JSON format is enabled with lograge.