# zackha/habit architecture

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

- Interactive diagram: https://gitdiagram.com/zackha/habit
- Repository: https://github.com/zackha/habit

## Overview

##### Main Components

A. Frontend Layer:
- Client-side Application (Nuxt 3)
- Components Structure
- State Management (Pinia)
- UI Components (Nuxt UI)

B. Server Layer:
- SSR Engine
- API Routes
- Authentication Service
- Database Layer

##### Detailed Component Breakdown

Frontend Components (Top Layer):
- Core Components (AppHeader, AppFooter)
- Feature Components (HabitCard, HabitForm, HabitHeatmap)
- State Management Layer (Pinia Store)
- Composables (useHabits, useHeatmap, useConfetti)

API Layer (Middle Layer):
- Auth Routes (/api/auth/github)
- Habit Routes (/api/habits/*)
- Authentication flow with GitHub

Database Layer (Bottom Layer):
- SQLite Database with Drizzle ORM
- Schema representation for:
- Habits table
- User data
- Tracking data

##### Connection Flows

- User authentication flow through GitHub
- Data flow between frontend and API
- Database interactions
- SSR data flow

##### Technical Stack Indicators

Technology labels:
- Nuxt 3
- Drizzle ORM
- SQLite
- Nuxt UI
- Pinia
- nuxt-auth-utils

##### Deployment Flow

A section showing:
- NuxtHub deployment process
- Build and compilation process

Key Recommendations:
##### Authentication flow as a critical path

Remember to maintain a balance between detail and clarity, focusing on the architectural decisions that make this application unique, such as the SSR implementation, GitHub authentication, and the habit tracking functionality.

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Client["Client Application"]
        direction TB
        CoreComp["Core Components"]
        FeatureComp["Feature Components"]
        StateManagement["State Management (Pinia)"]
        Composables["Composables Layer"]
        UIComponents["UI Components"]

        subgraph Core["Core Components"]
            AppHeader["AppHeader"]:::frontend
            AppFooter["AppFooter"]:::frontend
        end

        subgraph Feature["Feature Components"]
            HabitCard["HabitCard"]:::frontend
            HabitForm["HabitForm"]:::frontend
            HabitHeatmap["HabitHeatmap"]:::frontend
            ProfileHeader["ProfileHeader"]:::frontend
            UserProfile["UserProfileInfo"]:::frontend
        end

        subgraph Composable["Composables"]
            UseHabits["useHabits"]:::frontend
            UseHeatmap["useHeatmap"]:::frontend
            UseConfetti["useConfetti"]:::frontend
        end

        subgraph UI["UI Components"]
            Card["Card"]:::frontend
            Container["Container"]:::frontend
            ContentBox["ContentBox"]:::frontend
            Dropdown["Dropdown"]:::frontend
        end
    end

    subgraph API["API Layer"]
        direction TB
        AuthRoutes["Authentication Routes"]:::api
        HabitRoutes["Habit Routes"]:::api
        GitHubAuth["GitHub Auth Handler"]:::auth
    end

    subgraph DB["Database Layer"]
        direction TB
        SQLite["SQLite + Drizzle ORM"]:::database
        Schema["Database Schema"]:::database
        Migrations["Migrations"]:::database
    end

    subgraph Config["Configuration"]
        AppConfig["App Config"]:::config
        NuxtConfig["Nuxt Config"]:::config
        DrizzleConfig["Drizzle Config"]:::config
    end

    GitHub["GitHub OAuth"]:::external

    Client --> API
    AuthRoutes --> GitHubAuth
    GitHubAuth --> GitHub
    API --> DB
    HabitRoutes --> SQLite
    Schema --> SQLite

    %% Click events for components
    click AppHeader "https://github.com/zackha/habit/blob/master/app/components/AppHeader.vue"
    click AppFooter "https://github.com/zackha/habit/blob/master/app/components/AppFooter.vue"
    click HabitCard "https://github.com/zackha/habit/blob/master/app/components/HabitCard.vue"
    click HabitForm "https://github.com/zackha/habit/blob/master/app/components/HabitForm.vue"
    click HabitHeatmap "https://github.com/zackha/habit/blob/master/app/components/HabitHeatmap.vue"
    click ProfileHeader "https://github.com/zackha/habit/blob/master/app/components/ProfileHeader.vue"
    click UserProfile "https://github.com/zackha/habit/blob/master/app/components/UserProfileInfo.vue"
    click UseHabits "https://github.com/zackha/habit/blob/master/app/composables/useHabits.ts"
    click UseHeatmap "https://github.com/zackha/habit/blob/master/app/composables/useHeatmap.ts"
    click UseConfetti "https://github.com/zackha/habit/blob/master/app/composables/useConfetti.ts"
    click GitHubAuth "https://github.com/zackha/habit/blob/master/server/api/auth/github.get.ts"
    click HabitRoutes "https://github.com/zackha/habit/tree/master/server/api/habits"
    click Schema "https://github.com/zackha/habit/blob/master/server/database/schema.ts"
    click SQLite "https://github.com/zackha/habit/blob/master/server/utils/db.ts"
    click Migrations "https://github.com/zackha/habit/blob/master/server/database/migrations/0000_mean_mole_man.sql"
    click AppConfig "https://github.com/zackha/habit/blob/master/app/app.config.ts"
    click NuxtConfig "https://github.com/zackha/habit/blob/master/nuxt.config.ts"
    click DrizzleConfig "https://github.com/zackha/habit/blob/master/drizzle.config.ts"
    click Card "https://github.com/zackha/habit/blob/master/app/components/Card.vue"
    click Container "https://github.com/zackha/habit/blob/master/app/components/Container.vue"
    click ContentBox "https://github.com/zackha/habit/blob/master/app/components/ContentBox.vue"
    click Dropdown "https://github.com/zackha/habit/blob/master/app/components/Dropdown.vue"

    %% Styling
    classDef frontend fill:#3498db,color:white
    classDef api fill:#2ecc71,color:white
    classDef auth fill:#f1c40f,color:black
    classDef database fill:#9b59b6,color:white
    classDef external fill:#95a5a6,color:white
    classDef config fill:#e74c3c,color:white

    %% Legend
    subgraph Legend
        Frontend["Frontend"]:::frontend
        APILayer["API"]:::api
        AuthService["Auth Service"]:::auth
        DatabaseLayer["Database"]:::database
        ExternalService["External Service"]:::external
        Configuration["Configuration"]:::config
    end
```
