# michaeldahl7/dashboard architecture

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

- Interactive diagram: https://gitdiagram.com/michaeldahl7/dashboard
- Repository: https://github.com/michaeldahl7/dashboard

## Overview

##### Main Components

a. Client-Side (Frontend):
- React Application Layer
- UI Components (shadcn/ui)
- State Management (Tanstack Query)
- Routing (Tanstack Router)
- Form Handling (Tanstack Form)

b. Server-Side:
- API Layer (Tanstack Start)
- Authentication Service (Better Auth)
- Database Layer (PostgreSQL with DrizzleORM)

c. External Services:
- Social Auth Providers (Google, Discord)

##### Architecture Representation

**[Client Layer]**
- ↑↓
**[API Layer]**
- ↑↓
**[Service Layer]**
- ↑↓
**[Data Layer]**

##### Component Details

Frontend (Client Layer):
- Modular structure reflecting the `/apps/web/app` directory
- Areas:
- Components (/components)
- Routes (/routes)
- Services (/services)
- Hooks (/hooks)

Service Layer:
- Packages structure:
- Auth Package (/packages/auth)
- DB Package (/packages/db)
- UI Package (/packages/ui)

Data Layer:
- Database schemas from /packages/db/src:
- Auth Schema
- House Schema
- Item Schema
- Location Schema

##### Key Flows to Highlight

a. Authentication Flow:
**User → Social Auth → Auth Service → Database**

b. Data Flow:
**Client → API Routes → Services → Database**

##### Important Details

- Monorepo structure (apps/ and packages/)
- Multi-house support architecture
- Authentication boundaries
- API route organization
- Database schema relationships

##### Specific Implementation Notes

- Separation between public and authenticated routes (_public.tsx vs _authed.tsx)
- House-based multi-tenancy
- Demonstrate the inventory tracking system's components
- Theme switching mechanism

This architecture should emphasize the modern full-stack nature of the application while showing how it leverages the monorepo structure to maintain clean separation of concerns between UI components, business logic, and data access layers.

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Client["Client Layer"]
        WebApp["React Application"]:::frontend
        click WebApp "https://github.com/michaeldahl7/dashboard/tree/main/apps/web/app"
        
        subgraph UI["UI Components"]
            Components["UI Library"]:::frontend
            click Components "https://github.com/michaeldahl7/dashboard/tree/main/packages/ui/src/components/ui"
            ThemeProvider["Theme Provider"]:::frontend
            click ThemeProvider "https://github.com/michaeldahl7/dashboard/blob/main/apps/web/app/components/theme-provider.tsx"
            ThemeToggle["Theme Toggle"]:::frontend
            click ThemeToggle "https://github.com/michaeldahl7/dashboard/blob/main/apps/web/app/components/theme-toggle.tsx"
        end
        
        subgraph Layout["Layout Components"]
            AppHeader["App Header"]:::frontend
            click AppHeader "https://github.com/michaeldahl7/dashboard/blob/main/apps/web/app/components/layout/app-header.tsx"
            AppSidebar["App Sidebar"]:::frontend
            click AppSidebar "https://github.com/michaeldahl7/dashboard/blob/main/apps/web/app/components/layout/app-sidebar.tsx"
            PublicHeader["Public Header"]:::frontend
            click PublicHeader "https://github.com/michaeldahl7/dashboard/blob/main/apps/web/app/components/layout/public-header.tsx"
        end
        
        subgraph Routes["Routing System"]
            Router["Root Router"]:::frontend
            click Router "https://github.com/michaeldahl7/dashboard/blob/main/apps/web/app/router.tsx"
            PublicRoutes["Public Routes"]:::frontend
            click PublicRoutes "https://github.com/michaeldahl7/dashboard/tree/main/apps/web/app/routes/_public"
            AuthedRoutes["Authenticated Routes"]:::frontend
            click AuthedRoutes "https://github.com/michaeldahl7/dashboard/tree/main/apps/web/app/routes/_authed"
        end
    end
    
    subgraph API["API Layer"]
        AuthAPI["Auth API Routes"]:::api
        click AuthAPI "https://github.com/michaeldahl7/dashboard/tree/main/apps/web/app/routes/api/auth"
        AuthGuard["Auth Guard"]:::api
        click AuthGuard "https://github.com/michaeldahl7/dashboard/blob/main/apps/web/app/middleware/auth-guard.ts"
    end
    
    subgraph Services["Service Layer"]
        AuthService["Authentication Service"]:::service
        click AuthService "https://github.com/michaeldahl7/dashboard/tree/main/packages/auth"
        HouseService["House Service"]:::service
        click HouseService "https://github.com/michaeldahl7/dashboard/tree/main/apps/web/app/services/house"
        ItemService["Item Service"]:::service
        click ItemService "https://github.com/michaeldahl7/dashboard/tree/main/apps/web/app/services/item"
        LocationService["Location Service"]:::service
        click LocationService "https://github.com/michaeldahl7/dashboard/tree/main/apps/web/app/services/location"
    end
    
    subgraph Data["Data Layer"]
        Database[(PostgreSQL)]:::database
        
        subgraph Schemas["Database Schemas"]
            AuthSchema["Auth Schema"]:::schema
            click AuthSchema "https://github.com/michaeldahl7/dashboard/blob/main/packages/db/src/auth.schema.ts"
            HouseSchema["House Schema"]:::schema
            click HouseSchema "https://github.com/michaeldahl7/dashboard/blob/main/packages/db/src/house.schema.ts"
            ItemSchema["Item Schema"]:::schema
            click ItemSchema "https://github.com/michaeldahl7/dashboard/blob/main/packages/db/src/item.schema.ts"
            LocationSchema["Location Schema"]:::schema
            click LocationSchema "https://github.com/michaeldahl7/dashboard/blob/main/packages/db/src/location.schema.ts"
        end
        
        DrizzleORM["DrizzleORM"]:::database
        click DrizzleORM "https://github.com/michaeldahl7/dashboard/tree/main/packages/db"
    end
    
    subgraph External["External Services"]
        Google["Google Auth"]:::external
        Discord["Discord Auth"]:::external
    end
    
    %% Relationships
    WebApp --> UI
    WebApp --> Layout
    WebApp --> Routes
    Router --> PublicRoutes
    Router --> AuthedRoutes
    AuthedRoutes --> AuthGuard
    AuthGuard --> AuthService
    AuthService --> AuthAPI
    AuthAPI --> DrizzleORM
    DrizzleORM --> Database
    AuthService --> External
    Services --> DrizzleORM
    
    %% Styles
    classDef frontend fill:#3498db,stroke:#2980b9,color:white
    classDef api fill:#2ecc71,stroke:#27ae60,color:white
    classDef service fill:#e74c3c,stroke:#c0392b,color:white
    classDef database fill:#9b59b6,stroke:#8e44ad,color:white
    classDef external fill:#95a5a6,stroke:#7f8c8d,color:white
    classDef schema fill:#f1c40f,stroke:#f39c12,color:black
    
    %% Legend
    subgraph Legend
        Frontend["Frontend Component"]:::frontend
        API["API Component"]:::api
        Service["Service Component"]:::service
        DB["Database Component"]:::database
        Ext["External Service"]:::external
        Sch["Schema"]:::schema
    end
```
