How takuma123-type/history-server works
Project type and purpose
• This is a Ruby on Rails monolith serving both:
– A JSON API (“app/controllers/api/…”, jbuilder views)
– A simple PWA front-end (in “app/views/pwa” with manifest & service-worker)
• It exposes resources (CoreStacks, Histories, Infrastructures, Positions, Scales, Sessions) via REST.
• It uses JWT for auth, ActiveRecord + MySQL, Docker+Compose for local/dev/prod, RSpec/tests, CI via GitHub Actions.
File structure & architectural patterns
• MVC Layers:
– Controllers (API): HTTP entry points
– Models: ActiveRecord entities
– Views: JSON builders + PWA assets
• Service & Use-Case Layers:
– “app/usecases” implements application business logic, decoupling controllers from models.
– “app/services/jwt_service.rb” handles token creation/validation.
• Background Jobs: “app/jobs” (ActiveJob), Mailers.
• Configuration: Puma web server, CORS, credentials, Dockerfiles, Compose.
Main components & boundaries
A. Client Layer
– Browser/PWA or external API clients
B. Web Tier
– Reverse proxy/load-balancer (optional NGINX in production)
– Puma app server running Rails
C. Application Layer (Rails monolith)
– Controllers → Use-Case layer → Service layer → Models
– Views (JSON via Jbuilder, PWA assets via asset-pipeline)
– ActiveJob for background processing
– Mailers for notifications
D. Data Layer
– MySQL (configured via config/database.yml, Dockerfile.mysql)
– ActiveStorage/local file storage
E. Dev/Ops & CI
– Docker Compose (compose.yml, Dockerfile.dev/prod)
– GitHub Actions (CI workflow)
– Utilities: RuboCop, Brakeman, RSpec
Relationships & data flow
1. Client → HTTP(S) → NGINX/load-balancer → Puma → Rails Router
2. Rails Router dispatches to API Controllers or PWA Routes
3. Controller calls a Use-Case (e.g., LogInUsecase → JwtService → Session model)
4. Use-Case interacts with ActiveRecord models (CRUD in MySQL)
5. Controller renders JSON via Jbuilder
6. For background tasks: Controller or Use-Case enqueues an ActiveJob → Job Adapter → Worker
7. Assets (CSS/JS/images) served via asset pipeline or CDN
8. Docker Compose ties Rails container, MySQL container, possibly Redis (if used) together
Architectural patterns & principles
• Layered / Onion / Hexagonal style:
– Controllers (adapters/entry)
– Use-Cases (application core)
– Services (domain utilities)
– Models (ORM / persistence)
• Single codebase monolith: all layers in one Rails app
• Use of Docker for environment parity
Essential details to capture
• Authentication flow via JWTService
• UseCase layer encapsulating business rules
• Asset pipeline/PWA service-worker serving static content
• Docker Compose as the orchestration point in dev/prod
• CI pipeline triggering tests, linting, builds