# neco3coffee/exit_cheat_bs architecture

> Architecture diagram of the GitHub repository neco3coffee/exit_cheat_bs, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-11-02). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/neco3coffee/exit_cheat_bs
- Repository: https://github.com/neco3coffee/exit_cheat_bs

## Overview

##### Main components
- Frontend layer
- Next.js App Router (React)
- Next API Routes (server-side middleware)
- Backend layer
- Ruby on Rails “API” application (app/controllers/api/v1, services, jobs, mailers)
- Background-job system (ActiveJob with configured adapter via config/queue.yml)
- Storage adapter (ActiveStorage → AWS S3 via config/storage.yml)
- Data layer
- MySQL database (defined in backend/config/database.yml)
- Infrastructure & orchestration
- Docker Compose (frontend, backend, mysql containers)
- Kamal hooks for build/deploy lifecycle
- GitHub Actions (ci.yml, deploy.yml, playwright.yml)
- Testing & monitoring
- Playwright E2E tests (in e2e/)
- RSpec & Rails tests (backend/spec/)

##### Relationships & data flows
- Browser → Next.js frontend over HTTPS (port 3001 locally)
- Static assets, SSR pages, client components
- Calls Next.js API routes (app/api/v1/…) for session/auth, player lookup, reports, stats
- Next.js API Routes → Rails API over HTTP (port 3000 locally)
- JSON requests/responses between web and backend
- Rails API → MySQL
- CRUD via ActiveRecord migrations/models/controllers
- Rails API → S3
- Uploading user-submitted game videos via ActiveStorage
- Rails API → Background queue
- Enqueue jobs (e.g. SavePlayerJob, UpdatePlayerNamesJob)
- Background workers → MySQL (read/write updates)
- GitHub Actions → Docker Compose & Deploy hooks
- CI: run linters, tests, build images
- CD: push containers, trigger Kamal deploy scripts
- Local E2E runner (Playwright) → Next.js / Rails endpoints

##### Architectural patterns & design principles
- MVC pattern in Rails (models, controllers, services)
- Server-side rendering + client components in Next.js (app router, React)
- API-first approach: clear separation between UI (Next) and data services (Rails)
- Container-driven dev/test/prod parity via Docker Compose
- Hook-based deployment lifecycle (Kamal) for repeatable deploys
- Background processing for I/O-bound tasks (ActiveJob)

##### Deployment & CI/CD
- “GitHub” → “GitHub Actions”
- Actions → “Docker Hub / Container Registry” → “Kamal deploy hooks”
- Environments: dev, staging, prod

## Diagram (Mermaid)

```mermaid
flowchart TD
  Browser["Browser (React)"]:::frontend
  Browser -->|"HTTPS"| Pages

  subgraph "Next.js Container"
    direction TB
    Pages["Pages & Client Components"]:::frontend
    APIRoutes["Next.js API Routes"]:::frontend
    Pages --> APIRoutes
  end

  APIRoutes -->|"HTTP JSON"| Controllers

  subgraph "Rails API Container"
    direction TB
    Controllers["API Controllers"]:::backend
    Models["Models & ActiveRecord"]:::backend
    Services["Services"]:::backend
    Jobs["Background Jobs"]:::backend
    Mailers["Mailers"]:::backend
    Controllers --> Models
    Controllers --> Services
    Services --> Jobs
    Services --> Mailers
  end

  Controllers -->|"CRUD"| MySQL
  Jobs -->|"Read/Write"| MySQL
  Services -->|"Upload"| S3
  Controllers -->|"Enqueue"| Queue

  MySQL[(MySQL Database)]:::db
  S3["AWS S3 (ActiveStorage)"]:::storage
  Queue["Background Queue"]:::queue

  subgraph "Docker Compose"
    direction TB
    FrontendContainer["Frontend Service"]:::cicd
    BackendContainer["Backend Service"]:::cicd
    MySQLContainer["MySQL Service"]:::cicd
  end

  FrontendContainer --> Pages
  BackendContainer --> Controllers
  MySQLContainer --> MySQL

  GitHub["GitHub"]:::cicd
  GitHubActions["GitHub Actions"]:::cicd
  GitHub --> GitHubActions
  GitHubActions -->|"CI/CD"| DockerCompose
  DockerCompose -->|"Deploy via Kamal"| KamalHooks

  KamalHooks["Kamal Hooks"]:::cicd

  subgraph "Testing & Monitoring"
    direction TB
    Playwright["Playwright E2E Tests"]:::testing
    RSpec["RSpec & Rails Tests"]:::testing
  end

  Playwright --> Pages
  Playwright --> Controllers
  RSpec --> Controllers

  subgraph "Config & Infra Files"
    direction TB
    Routes["Rails Routes (routes.rb)"]:::backend
    QueueConfig["Queue Config (queue.yml)"]:::backend
    StorageConfig["Storage Config (storage.yml)"]:::backend
    DBConfig["DB Config (database.yml)"]:::db
    NextIntl["Next Intl Config"]:::frontend
  end

  classDef frontend fill:#D0E8FF,stroke:#005B96
  classDef backend fill:#DFF2DD,stroke:#257A1B
  classDef db fill:#FFE2B3,stroke:#C97800
  classDef storage fill:#F0F0F0,stroke:#999999
  classDef queue fill:#E8D0FF,stroke:#6A0091
  classDef cicd fill:#C0C0C0,stroke:#333333
  classDef testing fill:#FFF0F0,stroke:#D90000

  click Pages "https://github.com/neco3coffee/exit_cheat_bs/tree/main/frontend/app"
  click APIRoutes "https://github.com/neco3coffee/exit_cheat_bs/tree/main/frontend/app/api/v1"
  click Controllers "https://github.com/neco3coffee/exit_cheat_bs/tree/main/backend/app/controllers/api/v1"
  click Models "https://github.com/neco3coffee/exit_cheat_bs/tree/main/backend/app/models"
  click Services "https://github.com/neco3coffee/exit_cheat_bs/tree/main/backend/app/services"
  click Jobs "https://github.com/neco3coffee/exit_cheat_bs/tree/main/backend/app/jobs"
  click Mailers "https://github.com/neco3coffee/exit_cheat_bs/tree/main/backend/app/mailers"
  click QueueConfig "https://github.com/neco3coffee/exit_cheat_bs/blob/main/backend/config/queue.yml"
  click StorageConfig "https://github.com/neco3coffee/exit_cheat_bs/blob/main/backend/config/storage.yml"
  click MySQL "https://github.com/neco3coffee/exit_cheat_bs/blob/main/backend/config/database.yml"
  click Routes "https://github.com/neco3coffee/exit_cheat_bs/blob/main/backend/config/routes.rb"
  click FrontendContainer "https://github.com/neco3coffee/exit_cheat_bs/tree/main/frontend/Dockerfile"
  click BackendContainer "https://github.com/neco3coffee/exit_cheat_bs/tree/main/backend/Dockerfile"
  click DockerCompose "https://github.com/neco3coffee/exit_cheat_bs/blob/main/docker-compose.yml"
  click DockerCompose "https://github.com/neco3coffee/exit_cheat_bs/blob/main/docker-compose.override.yml"
  click KamalHooks "https://github.com/neco3coffee/exit_cheat_bs/tree/main/backend/.kamal/hooks"
  click GitHubActions "https://github.com/neco3coffee/exit_cheat_bs/blob/main/ .github/workflows/ci.yml"
  click GitHubActions "https://github.com/neco3coffee/exit_cheat_bs/blob/main/ .github/workflows/deploy.yml"
  click GitHubActions "https://github.com/neco3coffee/exit_cheat_bs/blob/main/ .github/workflows/playwright.yml"
  click Playwright "https://github.com/neco3coffee/exit_cheat_bs/tree/main/e2e/"
  click RSpec "https://github.com/neco3coffee/exit_cheat_bs/tree/main/backend/spec/"
```
