# datnguyennnx/central architecture

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

- Interactive diagram: https://gitdiagram.com/datnguyennnx/central
- Repository: https://github.com/datnguyennnx/central

## Overview

##### 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.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client Layer
    subgraph "Client Browser"
        B["Browser"]:::client
    end

    %% Web Interface Layer
    subgraph "Web Interface"
        E["Phoenix Endpoint"]:::web
        R["Phoenix Router"]:::web
        C["Controllers"]:::web
        L["LiveView Components"]:::web
        U["UI Components"]:::web
    end

    %% Backend Core Layer
    subgraph "Backend Core"
        A["Application Module"]:::backend
        M["Mailer Functions"]:::backend
        MD["Market Data Service"]:::backend
        RP["Database Repository"]:::backend
    end

    %% Assets and Frontend Layer
    subgraph "Assets and Frontend"
        JS["JS Assets & Custom Hooks"]:::frontend
        CSS["CSS Assets"]:::frontend
        TW["Tailwind Configuration"]:::frontend
    end

    %% Database & Persistence Layer
    subgraph "Database & Persistence"
        DB["Database (Migrations & Seeds)"]:::database
    end

    %% Configurations & Environment Layer
    subgraph "Configurations"
        CF["System Config Files"]:::config
    end

    %% Connections
    B -->|"HTTP_Request"| E
    E -->|"Routes_Request"| R
    R -->|"Dispatch"| C
    C -->|"Executes_Business_Logic"| A
    C -->|"Sends_Emails"| M
    C -->|"Fetches_Market_Data"| MD
    C -->|"DB_Operations"| RP
    RP -->|"Queries"| DB
    MD -->|"Real_time_Updates"| L
    L -->|"Render_Updates"| U
    U -->|"Integrates_JS"| JS
    U -->|"Integrates_CSS"| CSS
    U -->|"Integrates_Tailwind"| TW
    CF -->|"Configures_Core"| A
    CF -->|"Configures_Repo"| RP

    %% Click Events
    click A "https://github.com/datnguyennnx/central/blob/master/lib/central/application.ex"
    click M "https://github.com/datnguyennnx/central/blob/master/lib/central/mailer.ex"
    click MD "https://github.com/datnguyennnx/central/blob/master/lib/central/market_data/server.ex"
    click RP "https://github.com/datnguyennnx/central/blob/master/lib/central/repo.ex"
    click C "https://github.com/datnguyennnx/central/tree/master/lib/central_web/controllers"
    click L "https://github.com/datnguyennnx/central/blob/master/lib/central_web/live/chart_live.ex"
    click U "https://github.com/datnguyennnx/central/tree/master/lib/central_web/components"
    click R "https://github.com/datnguyennnx/central/blob/master/lib/central_web/router.ex"
    click E "https://github.com/datnguyennnx/central/blob/master/lib/central_web/endpoint.ex"
    click JS "https://github.com/datnguyennnx/central/tree/master/assets/js"
    click CSS "https://github.com/datnguyennnx/central/blob/master/assets/css/app.css"
    click TW "https://github.com/datnguyennnx/central/blob/master/assets/tailwind.config.js"
    click DB "https://github.com/datnguyennnx/central/tree/master/priv/repo"
    click CF "https://github.com/datnguyennnx/central/tree/master/config"

    %% Styles
    classDef client fill:#ffe0b2,stroke:#bf360c,stroke-width:2px;
    classDef web fill:#bbdefb,stroke:#0d47a1,stroke-width:2px;
    classDef backend fill:#c8e6c9,stroke:#1b5e20,stroke-width:2px;
    classDef frontend fill:#f0f4c3,stroke:#827717,stroke-width:2px;
    classDef database fill:#ffcdd2,stroke:#b71c1c,stroke-width:2px;
    classDef config fill:#d1c4e9,stroke:#4a148c,stroke-width:2px;
```
