How chaychoong/jjx works
Project type and purpose
• Jjx is a full-stack Phoenix (Elixir) web application.
• It serves dynamic pages via controllers and LiveView, manages data via Ecto, sends emails, interacts with a local file system, and includes a native Erlang NIF implemented in Rust.
File structure
• Top-level Phoenix conventions:
• assets/ (JavaScript, CSS, vendor) – the frontend static pipeline
• config/ – environment-specific settings
• lib/jjx/ – core application code (business logic, file system, mailer, repo)
• lib/jjx_web/ – web interface (controllers, views, LiveView, router, endpoint)
• priv/ – migration scripts, static assets, gettext
• test/ – unit and integration tests
• Native extension:
• native/jj_nif/ – Rust code compiled as an Erlang NIF, invoked from lib/jj/nif.ex
• Build & orchestration:
• mix.exs – Elixir build/dependency config
• Cargo.toml (root & native/) – Rust build config
README for additional insights
• Standard Phoenix startup instructions (mix setup, mix phx.server)
• Deployment guide link indicates a typical Phoenix release pattern
a. Main components
• Client Browser (HTTP & WebSocket)
• Phoenix Endpoint (HTTP server & socket transport)
• jjx_web layer:
• Router → Controllers & LiveViews → Templates/Components
• jjx core application:
• Business Logic modules (e.g., file_system/local, mailer)
• Ecto Repo → Database (PostgreSQL or configured adapter)
• Native NIF module (Rust library invoked via nif.ex)
• External services: SMTP server, third-party API, file storage (if any)
b. Relationships & interactions
• Browser ↔ Phoenix Endpoint: HTTP requests & LiveView WebSocket messages
• Endpoint → Router → Controller/LiveView: request routing
• Controllers/LiveViews → Business Logic & Ecto Repo: data operations
• Business Logic → Native NIF: heavy-compute offload
• Ecto Repo ↔ Database: SQL transactions
• Mailer → SMTP or email service API
• FileSystem modules → Local disk or external storage
c. Architectural patterns & design principles
• MVC (Router → Controllers/Views) augmented by LiveView (real-time at server)
• Supervision Tree: Endpoint, Repo, PubSub, Telemetry, custom supervisors
• Bounded contexts: separation between web interface (jjx_web) and domain logic (jjx)
• NIF for performance-critical modules, isolating unsafe native code
d. Key technologies & frameworks
• Elixir & Phoenix (Endpoint, Router, Controllers, LiveView)
• Ecto (Database interactions, Migrations)
• Rust NIF (native/jj_nif)
• JavaScript/CSS asset pipeline (esbuild or Webpack via assets/)
• Telemetry & Logger for observability
• Client Browser
• Phoenix Endpoint
• Web Layer (Router, Controllers, LiveViews, Templates)
• Domain Layer (Business Logic, FileSystem, Mailer)
• Persistence Layer (Ecto Repo → Database)
• Native Layer (Rust NIF)
• External Services (SMTP, third-party APIs)
• Web layer: light blue rectangles
• Business logic: green rectangles
• Annotations:
• “mix setup → compile assets → compile Elixir & Rust code”
• Supervision tree overview in a sidebar