# michaelholley/habitkit architecture

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

- Interactive diagram: https://gitdiagram.com/michaelholley/habitkit
- Repository: https://github.com/michaelholley/habitkit

## Overview

##### Main Components

A. Frontend Layer:
- SvelteKit Application (Client-side)
- Authentication UI (/auth)
- Main Application UI (/(app))
- Habit Management Interface (/[id])
- Habit Creation Interface (/create)

B. Backend Layer:
- SvelteKit Server-side
- Authentication Service (auth.ts)
- Habit Management Service (habit.ts)
- User Management Service (user.ts)

C. Data Layer:
- MySQL Database
- Prisma ORM as database interface

##### Component Relationships

- Client Browser → SvelteKit Frontend
- SvelteKit Frontend ↔ SvelteKit Server-side (Server Routes)
- Server-side Components ↔ Prisma Client
- Prisma Client ↔ MySQL Database

##### Architectural Patterns to Highlight

- SvelteKit's file-based routing structure
- Server-side rendering capabilities
- Component-based architecture in the frontend
- Service-based organization in the backend
- Database migration system

**┌─ Client Layer ─────────────────────┐**
- Browser / User Interface           │
- ┬───────────────────┘
- ↓
**┌─ Application Layer ────────────────┐**
- ┌─ Frontend ─┐    ┌─ Backend ───┐ │
- SvelteKit  │←→  │ Server-side │ │
- Components │    │ Routes      │ │
- ┘    └─────┬───────┘ │
- ┬───────────┘
- ↓
**┌─ Data Access Layer ──────────────┐**
- ┌─────────┐    ┌─────────────┐  │
- Prisma  │←→  │   MySQL     │  │
- Client  │    │  Database   │  │
- ┘    └─────────────┘  │
- ┘

##### Important Details

A. Frontend Components:
- Auth Module
- Habit Management Module
- Habit Creation Flow
- Activity Tracking Interface

B. Backend Services:
- Authentication & Authorization
- Habit CRUD Operations
- User Management
- Data Validation Layer

C. Data Store:
- MySQL Database Schema
- Prisma Migration System
- Data Models

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph Client["Client Layer"]
        Browser["Web Browser"]
    end

    subgraph AppLayer["Application Layer"]
        subgraph Frontend["Frontend Components"]
            AuthUI["Authentication UI"]:::frontend
            MainApp["Main Application UI"]:::frontend
            HabitMgmtUI["Habit Management Interface"]:::frontend
            HabitCreateUI["Habit Creation Interface"]:::frontend
            HabitComponents["Habit UI Components"]:::frontend
            ActivityHistory["Habit Activity Components"]:::frontend
            Overview["Habit Overview Components"]:::frontend
        end

        subgraph Backend["Backend Services"]
            ServerHooks["Server Hooks"]:::backend
            AuthService["Authentication Service"]:::backend
            HabitService["Habit Management Service"]:::backend
            UserService["User Management Service"]:::backend
            LayoutLogic["Server-side Layout Logic"]:::backend
            AuthPages["Authentication Pages"]:::backend
        end
    end

    subgraph DataLayer["Data Access Layer"]
        PrismaClient["Prisma Client"]:::data
        MySQL["MySQL Database"]:::database
        DBSchema["Database Schema & Migrations"]:::data
    end

    %% Connections
    Browser --> AuthUI
    Browser --> MainApp
    
    AuthUI --> AuthService
    MainApp --> HabitService
    HabitMgmtUI --> HabitService
    HabitCreateUI --> HabitService
    
    AuthService --> PrismaClient
    HabitService --> PrismaClient
    UserService --> PrismaClient
    
    PrismaClient --> MySQL
    
    %% Click events
    click AuthUI "https://github.com/MichaelHolley/HabitKit/tree/main/src/routes/auth"
    click MainApp "https://github.com/MichaelHolley/HabitKit/tree/main/src/routes/(app)"
    click HabitMgmtUI "https://github.com/MichaelHolley/HabitKit/tree/main/src/routes/(app)/[id]"
    click HabitCreateUI "https://github.com/MichaelHolley/HabitKit/tree/main/src/routes/(app)/create"
    click AuthService "https://github.com/MichaelHolley/HabitKit/blob/main/src/lib/server/auth.ts"
    click HabitService "https://github.com/MichaelHolley/HabitKit/blob/main/src/lib/server/habit.ts"
    click UserService "https://github.com/MichaelHolley/HabitKit/blob/main/src/lib/server/user.ts"
    click PrismaClient "https://github.com/MichaelHolley/HabitKit/blob/main/src/lib/server/prisma.ts"
    click DBSchema "https://github.com/MichaelHolley/HabitKit/tree/main/prisma"
    click HabitComponents "https://github.com/MichaelHolley/HabitKit/tree/main/src/lib/components/Habit"
    click LayoutLogic "https://github.com/MichaelHolley/HabitKit/blob/main/src/routes/(app)/+layout.server.ts"
    click AuthPages "https://github.com/MichaelHolley/HabitKit/blob/main/src/routes/auth/+page.server.ts"
    click ActivityHistory "https://github.com/MichaelHolley/HabitKit/blob/main/src/lib/components/Habit/HabitActivityHistory.svelte"
    click Overview "https://github.com/MichaelHolley/HabitKit/blob/main/src/lib/components/Habit/HabitOverviewItem.svelte"
    click ServerHooks "https://github.com/MichaelHolley/HabitKit/blob/main/src/hooks.server.ts"

    %% Styling
    classDef frontend fill:#2563eb,color:white
    classDef backend fill:#16a34a,color:white
    classDef data fill:#ca8a04,color:white
    classDef database fill:#6b7280,color:white

    %% Legend
    subgraph Legend
        Frontend["Frontend Component"]:::frontend
        Backend["Backend Service"]:::backend
        Data["Data Access"]:::data
        DB["Database"]:::database
    end
```
