# chrismccord/todo_trek architecture

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

- Interactive diagram: https://gitdiagram.com/chrismccord/todo_trek
- Repository: https://github.com/chrismccord/todo_trek

## Overview

##### Project Type & Purpose
- This is a full-stack web application built with the Phoenix Framework using Elixir. It focuses on a trello-like todo board with dynamic form interactions powered by Phoenix LiveView.
- The README highlights dynamic forms, nested form behaviors using Ecto’s newer options (like sort_param and drop_param), and a live dashboard for managing todo items and lists.

##### Key Components
a. Frontend Components:
- Assets: The assets/ directory contains CSS (with Tailwind), JavaScript, and vendor libraries. These set up the client-side behaviors and visual styles.
- LiveView & Templates: The lib/todo_trek_web/live and lib/todo_trek_web/components directories contain the live view modules and components that render dynamic, real-time UI elements (e.g., home dashboard, form components for todos and lists).
- Static Files: The priv/static directory holds static assets (e.g., images, robots.txt) that get served to the client.

b. Web & API Layer:
- Phoenix Endpoint: Located in lib/todo_trek_web/endpoint.ex, this accepts HTTP connections and initializes the request pipeline.
- Router: In lib/todo_trek_web/router.ex, it defines the URL routes that direct requests to controllers or live components.
- Controllers: Under lib/todo_trek_web/controllers (e.g., page_controller.ex and user_session_controller.ex) which handle traditional request/response flows, error handling, and rendering.
- User Authentication: The modules in lib/todo_trek/accounts and lib/todo_trek_web/user_auth.ex manage login, signup, and token-based operations.

c. Business Logic & Domain Layer:
- Domain Modules: The lib/todo_trek directory (subdirectories accounts, todos, activity_log, etc.) encapsulates the core business logic such as user management, todo list operations, and activity logging.
- Dynamic Nested Forms Example: The handling of lists and notifications is embedded here, using Ecto’s cast_assoc and cast_embed capabilities.

d. Data Layer:
- Repository: The lib/todo_trek/repo.ex module manages interactions with the database using Ecto.
- Migrations & Seeds: Found in priv/repo/migrations and priv/repo/seeds.exs, these set up the database schema (tables for users, lists, todos, activity logs, etc.).

e. Configuration & Environment:
- Config Files: The config directory contains environment-specific configurations (dev, prod, test, runtime) which detail database connections, endpoint configurations, and other runtime dependencies.
- Mix Files: mix.exs and mix.lock define the project’s dependencies, build instructions, and overall project settings.

##### Relationships & Data Flow
- A client (web browser) interacts with the Phoenix Endpoint where HTTP requests arrive.
- The Router directs these requests to the appropriate Controllers or LiveView modules.
- live Views (for example, in lib/todo_trek_web/live) then handle dynamic interactions (e.g., sortable lists, form submissions) updating the user interface in real time.
- The Controllers or LiveViews call domain services (in lib/todo_trek/accounts, lib/todo_trek/todos, etc.) to execute business logic.
- These domain modules interact with the Repo for persistent storage, using database migrations and seed data to ensure correct schema and initial data.
- Updates in data trigger front-end changes through LiveView’s real-time feedback loop.

##### Architectural Patterns & Design Principles
- MVC / LiveView: There’s a clear separation between the view layer (Live components & templates), domain logic (modules in lib/todo_trek/*), and the database layer (Ecto Repo and migrations).
- Real-Time Data Flows: The use of Phoenix LiveView supports a reactive, dynamic form experience.
- Modular Separation: The project cleanly segments accounts, todos, and activity logs, each encapsulated in its own directory for maintainability and scalability.

##### Final Steps
- Annotations to each component indicating responsibilities, technologies, and dependencies.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Components
    subgraph "Frontend Components"
        FS["Frontend Assets"]:::frontend
        SF["Static Files"]:::frontend
    end

    %% Web & API Layer
    subgraph "Web & API Layer"
        EP["Phoenix Endpoint"]:::web
        R["Router"]:::web
        C["Controllers"]:::web
        LV["LiveView Modules"]:::web
        WC["Web Components"]:::web
        UAM["User Auth Module"]:::web
        UAA["User Auth Accounts"]:::web
    end

    %% Business Logic & Domain
    subgraph "Business Logic & Domain"
        TD["Todos Domain"]:::domain
        AL["Activity Log"]:::domain
    end

    %% Data Layer
    subgraph "Data Layer"
        REPO["Repository"]:::data
        MIG["Migrations"]:::data
        SEED["Seeds"]:::data
    end

    %% Configuration & Environment
    subgraph "Configuration & Environment"
        CF["Configuration Files"]:::config
        MF["Mix Files"]:::config
        ML["Mix Lock"]:::config
    end

    %% External Client
    CB["Client Browser"]:::frontend

    %% Connections
    SF -->|"serves"| CB
    FS -->|"provides_CSS/JS"| CB

    CB -->|"HTTP_Request"| EP
    EP -->|"Routes"| R
    R -->|"to_Controller"| C
    R -->|"to_LiveView"| LV
    R -->|"to_WebComponents"| WC
    R -->|"to_UserAuth"| UAM
    UAM -->|"uses"| UAA

    C -->|"calls"| TD
    C -->|"calls"| AL
    LV -->|"calls"| TD
    LV -->|"calls"| AL
    WC -->|"renders"| TD
    WC -->|"renders"| AL

    TD -->|"persists"| REPO
    AL -->|"persists"| REPO

    REPO -->|"schema"| MIG
    REPO -->|"init_data"| SEED

    CF -->|"configures"| EP
    MF -->|"builds"| EP
    ML -->|"locks"| EP

    %% Click Events
    click FS "https://github.com/chrismccord/todo_trek/tree/main/assets/"
    click SF "https://github.com/chrismccord/todo_trek/tree/main/priv/static"
    click EP "https://github.com/chrismccord/todo_trek/blob/main/lib/todo_trek_web/endpoint.ex"
    click R "https://github.com/chrismccord/todo_trek/blob/main/lib/todo_trek_web/router.ex"
    click C "https://github.com/chrismccord/todo_trek/tree/main/lib/todo_trek_web/controllers"
    click LV "https://github.com/chrismccord/todo_trek/tree/main/lib/todo_trek_web/live"
    click WC "https://github.com/chrismccord/todo_trek/tree/main/lib/todo_trek_web/components"
    click UAA "https://github.com/chrismccord/todo_trek/tree/main/lib/todo_trek/accounts"
    click UAM "https://github.com/chrismccord/todo_trek/blob/main/lib/todo_trek_web/user_auth.ex"
    click TD "https://github.com/chrismccord/todo_trek/tree/main/lib/todo_trek/todos"
    click AL "https://github.com/chrismccord/todo_trek/tree/main/lib/todo_trek/activity_log"
    click REPO "https://github.com/chrismccord/todo_trek/blob/main/lib/todo_trek/repo.ex"
    click MIG "https://github.com/chrismccord/todo_trek/tree/main/priv/repo/migrations"
    click SEED "https://github.com/chrismccord/todo_trek/blob/main/priv/repo/seeds.exs"
    click CF "https://github.com/chrismccord/todo_trek/tree/main/config/"
    click MF "https://github.com/chrismccord/todo_trek/blob/main/mix.exs"
    click ML "https://github.com/chrismccord/todo_trek/blob/main/mix.lock"

    %% Styles
    classDef frontend fill:#F8A61A,stroke:#333,stroke-width:2px;
    classDef web fill:#0099CC,stroke:#333,stroke-width:2px;
    classDef domain fill:#BADA55,stroke:#333,stroke-width:2px;
    classDef data fill:#FF8C00,stroke:#333,stroke-width:2px;
    classDef config fill:#ADFF2F,stroke:#333,stroke-width:2px;
```
