# arrowstyle0/goal architecture

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

- Interactive diagram: https://gitdiagram.com/arrowstyle0/goal
- Repository: https://github.com/arrowstyle0/goal

## Overview

This is a **full-stack “Goal Tracker” web application**:
- **Frontend**: React (Vite) SPA with pages for Landing/Dashboard/Goals/Todos and reusable UI/layout components.
- **Backend**: Node.js + Express API exposing `/api/goals`, `/api/todos`, `/api/dashboard/*`.
- **Database**: MongoDB via Mongoose models (`Goal`, `Todo`).
- **Runtime config**: `.env` provides `MONGODB_URI` + `PORT`.

##### Read the file tree as architecture hints (what to include)
Key structure signals from the repo:

##### Frontend (Vite + React)
- `index.html`, `vite.config.js`, `src/main.jsx` (Vite entry), `src/App.jsx`
- `src/pages/*` (route-level screens / containers):
- `LandingPage.jsx`, `Dashboard.jsx`, `DashboardOverview.jsx`, `Goals.jsx`, `Todos.jsx`
- `src/components/*` (UI decomposition):
- `components/dashboard/*`: `AddGoal`, `GoalChart`, `GoalList`, `TodoList`, `StatsCard`
- `components/layout/*`: `Navbar`, `Sidebar`, `Hero`
- `components/ui/*`: `UserOnboarding` (implies username capture; no auth service visible)
- `public/` static assets
- CSS: `src/index.css`, `src/App.css`

##### Backend (Express + Mongoose)
- Two likely entrypoints: `server.js` (root) and `server/index.js`
- This usually indicates either:
- one file starts the express app and one exports/configures it, or
- one is production entry and one is dev entry.
- `server/models/Goal.js`, `server/models/Todo.js` (Mongoose schemas)
- `.env` indicates external config + environment separation.

##### React SPA (Vite build)
- Runs in browser
##### Express API Server (Node.js)
- Hosts REST endpoints:
- `/api/goals`
- `/api/todos`
- `/api/dashboard/stats`
- `/api/dashboard/history`
- Uses middleware: `cors`, `express.json`, `dotenv`
##### MongoDB
- Collections corresponding to `Goal` and `Todo`

Optional container (only if it’s real in your setup):
- **Static asset hosting**
- If `server.js` serves the built React bundle in production, show “Express serves static React build”.
- If not, show it as “Vite dev server” only in a “Dev-only” annotation.

- React SPA → Express API: JSON REST
- Express API → MongoDB: CRUD via Mongoose
- Express API → React SPA: JSON responses

##### Frontend component breakdown (from `src/`)
- **Entry / App Shell**
- `src/main.jsx` → mounts React
- `src/App.jsx` → top-level composition + routing (implied by `pages/`)
- **Pages (route-level)**
- `LandingPage`
- `Dashboard` / `DashboardOverview`
- `Goals`
- `Todos`
- **Dashboard Components**
- `AddGoal` (POST/PUT goals)
- `GoalList` (GET/DELETE goals)
- `TodoList` (GET/POST/PUT/DELETE todos)
- `GoalChart` (visualization; consumes dashboard history/stats)
- `StatsCard` (consumes dashboard stats)
- **Layout**
- `Navbar`, `Sidebar`, `Hero`
- **UI**
- `UserOnboarding` (captures username; drives `?username=` queries)

- Pages → Components (composition)
- API calls → Express endpoints

##### Backend component breakdown (from `server/`)

- **Express App**
- middleware: `cors`, `dotenv`, JSON body parser
- **Route Handlers / Controllers** (logical)
- Goals controller: GET/POST/PUT/DELETE
- Todos controller: GET/POST/PUT/DELETE
- Dashboard controller:
- stats aggregation
- 7-day history computation
- **Data Access Layer**
- Mongoose models:
- `Goal` (`server/models/Goal.js`)
- `Todo` (`server/models/Todo.js`)
- **MongoDB**
- persisted goal/todo documents

- Express routes → controller logic → Mongoose models → MongoDB
- MongoDB → Mongoose → controller → JSON response

- Many endpoints filter by `username` (`?username={username}`), so include that as a label on the read paths.

##### Goals CRUD
- React `GoalList` / `AddGoal` → `GET/POST/PUT/DELETE /api/goals`
- Express → `Goal` model → MongoDB

##### Todos CRUD
- React `TodoList` → `GET/POST/PUT/DELETE /api/todos`
- Express → `Todo` model → MongoDB

##### Dashboard analytics
- React `StatsCard` → `GET /api/dashboard/stats?username=...`
- React `GoalChart` → `GET /api/dashboard/history?username=...`
- Express dashboard controller → reads Goals + Todos (likely) → computes aggregates → returns JSON

- “Dashboard stats/history are derived (computed) views over Goals and Todos collections.”

- **SPA + REST**: Client-side rendered UI calling RESTful JSON endpoints.
- **Mongoose ODM**: Models define schema + DB access.
- **Layering** (even if not physically separated): UI → API → Model → DB.
- **User identity is lightweight**: username passed via query/body (no clear auth service present). If `dotenv` is mistakenly described as JWT in README, avoid claiming JWT is implemented unless you confirm it in code—just note “dotenv used for config”.

##### Labels
- **port** and **env vars** on containers: `PORT`, `MONGODB_URI`.
- **endpoint groups** on the API container.

##### System Context: User → Goal Tracker App → MongoDB.
- Browser (React SPA)
- Express API (Node)
- MongoDB
- (Optional) Vite dev server / static hosting annotation
- Pages + dashboard/layout/ui components
- Logical API client
- Mapping of components to endpoint groups
- Express middleware
- Controllers per resource (Goals/Todos/Dashboard)
- Mongoose models
- MongoDB collections
- “Mark todo completed” or “Create goal”:
- UI event → API call → DB write → response → UI state update.

This set is detailed, maps directly to the file tree, and makes data flow unambiguous without inventing components that aren’t present.

## Diagram (Mermaid)

```mermaid
flowchart TD
  %% =========================
  %% Level 1: System Context
  %% =========================
  subgraph "Level 1 — System Context"
    U["User\n(Web Browser)"]:::external
    APP["Goal Tracker Web App"]:::container
    MDB[("MongoDB\n(Local or Atlas)")]:::database

    U <-->|"HTTPS\n(username-based identity)"| APP
    APP <-->|"Mongo wire protocol\n(via Mongoose)"| MDB
  end

  %% =========================
  %% Level 2: Container Diagram
  %% =========================
  subgraph "Level 2 — Containers"
    direction TB

    subgraph "Client (Browser Runtime)"
      direction TB
      SPA["React SPA\n(Vite build output)\nPages + Components"]:::container
      ONB["UserOnboarding\n(captures username)"]:::component
      SPA -->|"provides username\nfor queries/body"| ONB
    end

    subgraph "Server (Node.js Runtime)"
      direction TB
      API["Express API Server\n(Node.js)\nUses: cors, express.json, dotenv\nConfig: PORT, MONGODB_URI\nEndpoints:\n- /api/goals\n- /api/todos\n- /api/dashboard/stats\n- /api/dashboard/history"]:::container
    end

    subgraph "Data Store"
      direction TB
      DB[("MongoDB\nCollections:\n- goals\n- todos")]:::database
    end

    SPA <-->|"HTTP/JSON\nREST request/response"| API
    API -->|"CRUD + aggregations\nMongoose queries"| DB
    DB -->|"documents"| API
  end

  %% =========================
  %% Level 3A: Frontend Components
  %% =========================
  subgraph "Level 3A — Frontend (src/)"
    direction TB

    subgraph "Entry & App Shell"
      direction TB
      HTML["index.html\n(Vite HTML entry)"]:::file
      VCFG["vite.config.js\n(Vite config)"]:::file
      MAIN["src/main.jsx\n(mount React)"]:::file
      APPX["src/App.jsx\n(app shell + routing)"]:::file
      CSS1["src/index.css\n(global styles)"]:::file
      CSS2["src/App.css\n(app styles)"]:::file
      PUB["public/\n(static assets)"]:::folder

      HTML -->|"loads bundle"| MAIN
      VCFG -.->|"build/dev config"| MAIN
      MAIN -->|"renders"| APPX
      CSS1 -.->|"styles"| APPX
      CSS2 -.->|"styles"| APPX
      PUB -.->|"assets"| APPX
    end

    subgraph "Pages (route-level)"
      direction TB
      P0["LandingPage"]:::component
      P1["Dashboard"]:::component
      P2["DashboardOverview"]:::component
      P3["Goals"]:::component
      P4["Todos"]:::component
    end

    subgraph "Layout Components"
      direction TB
      NAV["Navbar"]:::component
      SIDE["Sidebar"]:::component
      HERO["Hero"]:::component
    end

    subgraph "Dashboard Components"
      direction TB
      ADDG["AddGoal"]:::component
      GLIST["GoalList"]:::component
      TLIST["TodoList"]:::component
      GCHART["GoalChart"]:::component
      STATS["StatsCard"]:::component
    end

    subgraph "UI Components"
      direction TB
      UONB["UserOnboarding\n(username capture)"]:::component
    end

    subgraph "Logical Client-Side Service"
      direction TB
      APIC["API Client (logical)\nfetch/axios over HTTP/JSON"]:::service
    end

    APPX -->|"routes to"| P0
    APPX -->|"routes to"| P1
    APPX -->|"routes to"| P3
    APPX -->|"routes to"| P4

    P0 -->|"uses"| HERO
    P0 -->|"uses"| UONB

    P1 -->|"composes"| NAV
    P1 -->|"composes"| SIDE
    P1 -->|"shows"| P2

    P2 -->|"uses"| ADDG
    P2 -->|"uses"| GLIST
    P2 -->|"uses"| TLIST
    P2 -->|"uses"| GCHART
    P2 -->|"uses"| STATS

    P3 -->|"uses"| ADDG
    P3 -->|"uses"| GLIST

    P4 -->|"uses"| TLIST

    UONB -->|"stores username\n(drives ?username=...)"| APIC

    ADDG -->|"POST/PUT\n/api/goals"| APIC
    GLIST -->|"GET/DELETE\n/api/goals?username=..."| APIC
    TLIST -->|"GET/POST/PUT/DELETE\n/api/todos?username=..."| APIC
    STATS -->|"GET\n/api/dashboard/stats?username=..."| APIC
    GCHART -->|"GET\n/api/dashboard/history?username=..."| APIC
  end

  %% =========================
  %% Level 3B: Backend Components
  %% =========================
  subgraph "Level 3B — Backend (server/)"
    direction TB

    subgraph "Entrypoints"
      direction TB
      SROOT["server.js\n(Express API entry)"]:::file
      SIDX["server/index.js\n(Express API entry)"]:::file
      ENV[".env\n(PORT, MONGODB_URI)"]:::file
    end

    subgraph "Express App"
      direction TB
      MW["Middleware\n- dotenv\n- cors\n- express.json"]:::component
      ROUTER["Routes\n/api/goals\n/api/todos\n/api/dashboard/*"]:::component
    end

    subgraph "Controllers (logical)"
      direction TB
      CG["Goals Controller\nCRUD (filters by username)"]:::service
      CT["Todos Controller\nCRUD (filters by username)"]:::service
      CD["Dashboard Controller\nstats + 7-day history\n(derived views)"]:::service
    end

    subgraph "Data Access Layer"
      direction TB
      MGO["Goal Model\n(Mongoose schema)"]:::component
      MTO["Todo Model\n(Mongoose schema)"]:::component
    end

    SROOT -->|"bootstraps"| MW
    SIDX -->|"bootstraps"| MW
    ENV -.->|"provides config"| MW

    MW -->|"registers"| ROUTER
    ROUTER -->|"handles /api/goals"| CG
    ROUTER -->|"handles /api/todos"| CT
    ROUTER -->|"handles /api/dashboard/stats\n/api/dashboard/history"| CD

    CG -->|"Mongoose CRUD"| MGO
    CT -->|"Mongoose CRUD"| MTO
    CD -->|"reads goals + todos\naggregate/compute"| MGO
    CD -->|"reads goals + todos\naggregate/compute"| MTO
  end

  %% Cross-level connections (vertical)
  APIC <-->|"HTTP/JSON"| API
  API -->|"invokes routes/controllers"| ROUTER
  MGO -->|"queries"| DB
  MTO -->|"queries"| DB

  %% =========================
  %% Click events (from component_mapping)
  %% =========================
  click ENV "https://github.com/arrowstyle0/goal/blob/master/.env"
  click MAIN "https://github.com/arrowstyle0/goal/blob/master/src/main.jsx"
  click APPX "https://github.com/arrowstyle0/goal/blob/master/src/App.jsx"
  click CSS1 "https://github.com/arrowstyle0/goal/blob/master/src/index.css"
  click CSS2 "https://github.com/arrowstyle0/goal/blob/master/src/App.css"
  click HTML "https://github.com/arrowstyle0/goal/blob/master/index.html"
  click VCFG "https://github.com/arrowstyle0/goal/blob/master/vite.config.js"
  click PUB "https://github.com/arrowstyle0/goal/tree/master/public/"

  click P0 "https://github.com/arrowstyle0/goal/blob/master/src/pages/LandingPage.jsx"
  click P1 "https://github.com/arrowstyle0/goal/blob/master/src/pages/Dashboard.jsx"
  click P2 "https://github.com/arrowstyle0/goal/blob/master/src/pages/DashboardOverview.jsx"
  click P3 "https://github.com/arrowstyle0/goal/blob/master/src/pages/Goals.jsx"
  click P4 "https://github.com/arrowstyle0/goal/blob/master/src/pages/Todos.jsx"

  click UONB "https://github.com/arrowstyle0/goal/blob/master/src/components/ui/UserOnboarding.jsx"
  click ADDG "https://github.com/arrowstyle0/goal/blob/master/src/components/dashboard/AddGoal.jsx"
  click GLIST "https://github.com/arrowstyle0/goal/blob/master/src/components/dashboard/GoalList.jsx"
  click TLIST "https://github.com/arrowstyle0/goal/blob/master/src/components/dashboard/TodoList.jsx"
  click GCHART "https://github.com/arrowstyle0/goal/blob/master/src/components/dashboard/GoalChart.jsx"
  click STATS "https://github.com/arrowstyle0/goal/blob/master/src/components/dashboard/StatsCard.jsx"

  click NAV "https://github.com/arrowstyle0/goal/blob/master/src/components/layout/Navbar.jsx"
  click SIDE "https://github.com/arrowstyle0/goal/blob/master/src/components/layout/Sidebar.jsx"
  click HERO "https://github.com/arrowstyle0/goal/blob/master/src/components/layout/Hero.jsx"

  click SROOT "https://github.com/arrowstyle0/goal/blob/master/server.js"
  click SIDX "https://github.com/arrowstyle0/goal/blob/master/server/index.js"
  click MGO "https://github.com/arrowstyle0/goal/blob/master/server/models/Goal.js"
  click MTO "https://github.com/arrowstyle0/goal/blob/master/server/models/Todo.js"

  %% Directory clicks
  click APIC "https://github.com/arrowstyle0/goal/tree/master/src/components/"
  click SPA "https://github.com/arrowstyle0/goal/tree/master/src/"
  click ROUTER "https://github.com/arrowstyle0/goal/tree/master/server/"
  click MW "https://github.com/arrowstyle0/goal/tree/master/server/"
  click DB "https://github.com/arrowstyle0/goal/tree/master/server/models/"

  %% =========================
  %% Styles
  %% =========================
  classDef external fill:#F3F4F6,stroke:#6B7280,stroke-width:1px,color:#111827
  classDef container fill:#DBEAFE,stroke:#1D4ED8,stroke-width:1.5px,color:#0B1B3A
  classDef database fill:#DCFCE7,stroke:#16A34A,stroke-width:1.5px,color:#052E12
  classDef component fill:#E5E7EB,stroke:#374151,stroke-width:1px,color:#111827
  classDef service fill:#EDE9FE,stroke:#6D28D9,stroke-width:1.2px,color:#2E1065
  classDef file fill:#FEF3C7,stroke:#D97706,stroke-width:1px,color:#3B2F0B
  classDef folder fill:#FFEDD5,stroke:#C2410C,stroke-width:1px,color:#3B1D0A
```
