How datnguyennnx/central works
Main Components
• Backend Core (domain/business logic): This is found primarily under lib/central. It includes the main application module (central/application.ex), mailing functions (mailer.ex), market data services (market_data/server.ex), and database repository interactions (central/repo.ex). These modules handle the core domain concerns and business logic.
• Web Interface: Located under lib/central_web. This module contains:
• Controllers – like page_controller.ex and error controllers for both HTML and JSON formats.
• Live Views – e.g., chart_live.ex shows real-time interactive aspects.
• Components – a series of reusable UI components such as buttons, dialogs, layout templates (app.html.heex, root.html.heex), and custom hooks for interactive behavior.
• Router and Endpoint – these files (router.ex and endpoint.ex) define the request routing and are the entry point for HTTP requests.
• Assets and Frontend: The assets directory holds CSS and JavaScript files including custom hooks (flickering_grid.js, theme-switcher.js, tradingview_chart.js), Tailwind configuration, and other vendor assets.
• Database & Persistence: Evident from the priv/repo directory (migrations and seeds scripts) and repo module in lib/central, this represents the project’s connection to its database.
• Configurations & Environment: The config folder (config.exs, dev.exs, prod.exs, test.exs, and runtime.exs) provides a view into how the project handles environments and system configuration details.
Relationships and Interactions
• The HTTP layer starts at the Endpoint (central_web/endpoint.ex) that receives web requests.
• The Router (central_web/router.ex) directs these requests to the appropriate Controllers (for page rendering, error handling, or backend responses).
• Controllers interact with the Backend Core (lib/central) to execute business logic, fetch data from the repo (database), send emails via the mailer, or retrieve market data.
• LiveView components and UI components in lib/central_web enhance the dynamic user interaction on the frontend, utilizing the assets contained in the assets folder.
• The assets (JS, CSS) in the assets directory work closely with the front-facing components provided by the central_web module. Custom hooks in JS add dynamic behaviors (e.g., interactive charts, theme switching, grid flickering).
• Configuration files determine environmental parameters for connecting to databases, deploying the application, and handling other integrations.
Architectural Patterns and Design Principles
• MVC Pattern: Controllers, Views (templates and components), and Models (business logic and database interactions) are clearly separated.
• Modularization: Clear separation between the core backend (lib/central) and the frontend/web layer (lib/central_web) maximizes maintainability.
• LiveView Integration: Real-time data update capabilities are encapsulated in LiveView modules for interactive user experiences.
• Asset Bundling & Frontend Configuration: Assets are organized to reflect modern frontend practices using Tailwind and JavaScript hooks.
• Branch out from the Endpoint to the Router, then split paths into different controllers (page, error, changelog, etc.).
• Out integrations with the backend core (lib/central) showing the flow from controller to business logic and then to the database.
• Assets folder components (JS/CSS static files) and illustrate how they integrate with the dynamic web layer.