# amtsh/routine architecture

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

- Interactive diagram: https://gitdiagram.com/amtsh/routine
- Repository: https://github.com/amtsh/routine

## Overview

##### Project type and purpose
- This is a React-based, Next.js “app-directory” web application for managing habits.
- It’s primarily front-end (no API routes directory), using Next.js for routing, SSR/SSG, and client hydration.
- The app offers pages to add, edit, reorder, clear cache, and get suggestions for habits.

##### File structure
- **app/** – Next.js “App Router” pages and layouts (server components by default, with client components when needed).
- Subfolders: clearcache, edit/[id], home, new, reorder, suggestions – each with a page.tsx and helper components.
- **components/** – Shared React UI components (PillMenu, SelectEmoji, theme-provider).
- **components/ui/** – Primitive UI elements (button, input, dialog, dropdown, etc.), likely based on shadcn/ui.
- **lib/** – Application logic & types.
- context/SavedHabitsContext.tsx – React context for persisting habits (probably in localStorage).
- utils.ts, types.ts – helpers and type definitions.
- Config & build: next.config.ts, tsconfig.json, tailwind.config.ts, postcss.config.mjs.

##### Key insights from README
- Bootstrapped with create-next-app; uses next/font and TailwindCSS.
- Deploys seamlessly to Vercel.
- No serverless API routes present, so data stays on client (local storage) or could integrate external services later.

a. **Main components**
- Browser Client (User’s device)
- Next.js Application Server (or Vercel Edge)
- Static Asset Store / CDN (for public/ folder, optimized fonts)
- React Context / Local Storage (client-side persistence)
- UI Library (components/ui)
b. **Relationships & data flows**
- Browser → Next.js Server: HTTP GET page requests → SSR/SSG → HTML + JS sent back.
- Next.js Client-side: React hydrates, routes between app/** pages.
- Client Components use SavedHabitsContext to read/write browser localStorage.
c. **Architectural patterns & principles**
- App Router: Server Components vs. “use client” for interactive parts.
- Context API for global state (habit list).
- Component-driven UI with shared primitives (shadcn ui pattern).
- CSS utility approach (TailwindCSS).
d. **Key technologies**
- Next.js (App Router, SSR/SSG, next/font)
- React 18 (Server & Client Components)
- TailwindCSS + PostCSS
- shadcn/ui primitives (components/ui)
- TypeScript

##### Detailed breakdown
- Inside Next.js App Server:
[App Router]
– Layouts (app/layout.tsx)
– Pages (add, edit, reorder, suggestions, clearcache)
– “use client” React components for interactivity
- To the side: “components/ui” & “components” (shared UI primitives)
- Below: Build & Deploy tools (TailwindCSS, next/font, Vercel)

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Nodes
    Browser["User Browser"]:::external
    CDN["CDN / Public Assets"]:::static
    Storage["Browser LocalStorage"]:::storage

    subgraph "Next.js App Server (Vercel Edge)" 
        direction TB
        AppRouter["App Router"]:::server
        Layout["Layout (app/layout.tsx)"]:::server
        RootPage["Root Page (app/page.tsx)"]:::server
        ClearCachePage["Clear Cache Page"]:::server
        EditPage["Edit Habit Page"]:::server
        HomePage["Home Page"]:::server
        NewPage["New Habit Page"]:::server
        ReorderPage["Reorder Page"]:::server
        SuggestionsPage["Suggestions Page"]:::server
    end

    subgraph "Client Components & UI Library"
        direction TB
        SharedUI["Shared UI Primitives (components/ui/)"]:::client
        PillMenu["PillMenu"]:::client
        SelectEmoji["SelectEmoji"]:::client
        ThemeProvider["Theme Provider"]:::client
        EditHabitComp["EditHabit Component"]:::client
        ButtonsUI["Home Buttons UI"]:::client
        MenuDrawer["Home Menu Drawer UI"]:::client
        AddHabitComp["AddHabit Component"]:::client
        IntervalDropdown["Habit Interval Choice Dropdown"]:::client
        IntervalRadio["Habit Interval Choice Radio Group"]:::client
        ReorderUI["Reorder UI Component"]:::client
        DragHandle["Habit Row Drag Handle"]:::client
        HabitSuggestionsComp["Habit Suggestions Component"]:::client
        Context["SavedHabitsContext"]:::client
    end

    subgraph "Build & Deployment"
        direction TB
        Tailwind["TailwindCSS"]:::external
        FontOpt["next/font"]:::external
        Vercel["Vercel"]:::external
    end

    %% Relationships
    Browser -->|"HTTP GET pages"| AppRouter
    AppRouter -->|renders| Layout
    Layout --> RootPage
    Layout --> ClearCachePage
    Layout --> EditPage
    Layout --> HomePage
    Layout --> NewPage
    Layout --> ReorderPage
    Layout --> SuggestionsPage

    Browser -->|"Fetch assets"| CDN
    Browser -->|hydration| SharedUI

    RootPage -->|uses| ThemeProvider
    ClearCachePage -->|client component| Context
    ClearCachePage -->|uses| ThemeProvider
    EditPage -->|client component| EditHabitComp
    EditHabitComp -->|state| Context
    HomePage -->|client component| ButtonsUI
    HomePage -->|client component| MenuDrawer
    NewPage -->|client component| AddHabitComp
    AddHabitComp -->|uses| IntervalDropdown
    AddHabitComp -->|uses| IntervalRadio
    ReorderPage -->|client component| ReorderUI
    ReorderUI -->|uses| DragHandle
    SuggestionsPage -->|client component| HabitSuggestionsComp
    AllClientComp(("all client comps")) -->|read/write| Context
    Context -->|persists| Storage

    SharedUI -->|provides primitives| AllClientComp

    Tailwind -->|styles| SharedUI
    FontOpt -->|fonts| SharedUI
    Vercel -->|deploy| AppRouter

    %% Click Events
    click Layout "https://github.com/amtsh/routine/blob/main/app/layout.tsx"
    click RootPage "https://github.com/amtsh/routine/blob/main/app/page.tsx"
    click ClearCachePage "https://github.com/amtsh/routine/blob/main/app/clearcache/page.tsx"
    click EditPage "https://github.com/amtsh/routine/blob/main/app/edit/[id]/page.tsx"
    click EditHabitComp "https://github.com/amtsh/routine/blob/main/app/edit/[id]/EditHabit.tsx"
    click HomePage "https://github.com/amtsh/routine/blob/main/app/home/home.tsx"
    click ButtonsUI "https://github.com/amtsh/routine/blob/main/app/home/Buttons.tsx"
    click MenuDrawer "https://github.com/amtsh/routine/blob/main/app/home/MenuDrawer.tsx"
    click NewPage "https://github.com/amtsh/routine/blob/main/app/new/page.tsx"
    click AddHabitComp "https://github.com/amtsh/routine/blob/main/app/new/AddHabit.tsx"
    click IntervalDropdown "https://github.com/amtsh/routine/blob/main/app/new/HabitIntervalChoiceDropdown.tsx"
    click IntervalRadio "https://github.com/amtsh/routine/blob/main/app/new/HabitIntervalChoiceRadio.tsx"
    click ReorderPage "https://github.com/amtsh/routine/blob/main/app/reorder/page.tsx"
    click ReorderUI "https://github.com/amtsh/routine/blob/main/app/reorder/Reorder.tsx"
    click DragHandle "https://github.com/amtsh/routine/blob/main/app/reorder/HabitRowToDrag.tsx"
    click SuggestionsPage "https://github.com/amtsh/routine/blob/main/app/suggestions/page.tsx"
    click HabitSuggestionsComp "https://github.com/amtsh/routine/blob/main/app/suggestions/HabitSuggestions.tsx"
    click SharedUI "https://github.com/amtsh/routine/tree/main/components/ui/"
    click PillMenu "https://github.com/amtsh/routine/blob/main/components/PillMenu.tsx"
    click SelectEmoji "https://github.com/amtsh/routine/blob/main/components/SelectEmoji.tsx"
    click ThemeProvider "https://github.com/amtsh/routine/blob/main/components/theme-provider.tsx"
    click Context "https://github.com/amtsh/routine/blob/main/lib/context/SavedHabitsContext.tsx"
    click utils "https://github.com/amtsh/routine/blob/main/lib/utils.ts"
    click types "https://github.com/amtsh/routine/blob/main/lib/types.ts"
    click Emojidata "https://github.com/amtsh/routine/blob/main/public/emojidata.json"
    click Icons "https://github.com/amtsh/routine/tree/main/public/icons/"
    click Tailwind "https://github.com/amtsh/routine/blob/main/tailwind.config.ts"
    click FontOpt "https://github.com/amtsh/routine/tree/main/app/fonts/"
    click nextConfig "https://github.com/amtsh/routine/blob/main/next.config.ts"
    click tsconfig "https://github.com/amtsh/routine/blob/main/tsconfig.json"
    click postcss "https://github.com/amtsh/routine/blob/main/postcss.config.mjs"

    %% Styles
    classDef server fill:#D0E6FF,stroke:#0366D6,color:#0366D6;
    classDef client fill:#E6FFEA,stroke:#28A745,color:#28A745;
    classDef static fill:#F0F0F0,stroke:#A0A0A0,color:#606060;
    classDef external fill:#FFF4D6,stroke:#D69E2E,color:#B36C00;
    classDef storage fill:#FFECEC,stroke:#D93A3A,color:#A12A2A;
```
