# daya0576/beaverhabits architecture

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

- Interactive diagram: https://gitdiagram.com/daya0576/beaverhabits
- Repository: https://github.com/daya0576/beaverhabits

## Overview

##### Main Components

a. Frontend Layer:
- Web Interface (Progressive Web App)
- Pages (Index, Habit List, Calendar, Import/Export)
- Components and Layout
- Static Assets (images, PWA manifest, service worker)

b. Backend Layer:
- API Routes and Views
- Authentication System
- CRUD Operations
- Middleware
- Configuration Management

c. Storage Layer:
- Multiple Storage Implementations:
- SQLite Database
- File-based Storage (JSON)
- Session Storage

**[Client Layer]**
- ↑↓
**[Application Layer]**
- ↑↓
**[Storage Layer]**

##### Detailed Component Breakdown

a. Client Layer (Top):
- Sub-components:
- Frontend Pages (from frontend/ directory)
- Static Assets
- Service Worker
- PWA Manifest

b. Application Layer (Middle):
- Core Application Components:
- API Routes (/api.py)
- Authentication (/app/auth.py)
- CRUD Operations (/app/crud.py)
- Middleware (/app/middlewares.py)
- Schema Validation (/app/schemas.py)

c. Storage Layer (Bottom):
- SQLite Database
- User File Storage
- Session File Storage

##### Important Connections to Highlight

- RESTful API endpoints connecting frontend to backend
- Authentication flow between layers
- Storage abstraction layer (storage/meta.py) connecting to different storage implementations
- User session management flow

##### Additional Elements

- A section for CI/CD pipeline (GitHub Actions)
- Docker container boundary
- Environment variable configuration points
- Integration points for derivatives (Home Assistant, Stream Deck)

##### Technical Details

- Python-based backend (FastAPI/Flask based on the structure)
- File-based storage options
- Docker containerization
- Environment variable configuration points
- Authentication flow
- API endpoints

This system design should help developers understand how to deploy, maintain, and extend the application while maintaining its core architectural principles.

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Client
        PWA["Progressive Web App"]
        FPages["Frontend Pages"]:::frontend
        FComps["Frontend Components"]:::frontend
        FLayout["Frontend Layout"]:::frontend
        Assets["Static Assets"]:::frontend
        SW["Service Worker"]:::frontend
        Manifest["PWA Manifest"]:::frontend

        PWA --> FPages
        PWA --> FComps
        PWA --> FLayout
        PWA --> Assets
        PWA --> SW
        PWA --> Manifest

        subgraph Pages
            Index["Index Page"]:::frontend
            Calendar["Calendar View"]:::frontend
            Import["Import Page"]:::frontend
            Habit["Habit Page"]:::frontend
            FPages --> Index
            FPages --> Calendar
            FPages --> Import
            FPages --> Habit
        end
    end

    subgraph Application
        API["API Routes"]:::backend
        Auth["Authentication"]:::security
        CRUD["CRUD Operations"]:::backend
        Middle["Middleware"]:::backend
        Schema["Schema Validation"]:::backend
        Config["Configuration"]:::backend

        API --> Auth
        API --> CRUD
        API --> Middle
        API --> Schema
        API --> Config
    end

    subgraph Storage
        StorageAbs["Storage Abstraction"]:::storage
        SQLite["SQLite Database"]:::storage
        FileStore["File Storage"]:::storage
        SessionStore["Session Storage"]:::storage

        StorageAbs --> SQLite
        StorageAbs --> FileStore
        StorageAbs --> SessionStore
    end

    PWA <--> API
    API <--> StorageAbs

    subgraph DevOps
        CICD["CI/CD Pipeline"]:::devops
        Docker["Docker Container"]:::devops
    end

    classDef frontend fill:#3498db,stroke:#2980b9,color:white
    classDef backend fill:#2ecc71,stroke:#27ae60,color:white
    classDef storage fill:#f1c40f,stroke:#f39c12,color:black
    classDef security fill:#e74c3c,stroke:#c0392b,color:white
    classDef devops fill:#95a5a6,stroke:#7f8c8d,color:white

    click FPages "https://github.com/daya0576/beaverhabits/tree/main/beaverhabits/frontend/"
    click Index "https://github.com/daya0576/beaverhabits/blob/main/beaverhabits/frontend/index_page.py"
    click Calendar "https://github.com/daya0576/beaverhabits/blob/main/beaverhabits/frontend/cal_heatmap_page.py"
    click Import "https://github.com/daya0576/beaverhabits/blob/main/beaverhabits/frontend/import_page.py"
    click Habit "https://github.com/daya0576/beaverhabits/blob/main/beaverhabits/frontend/habit_page.py"
    click FComps "https://github.com/daya0576/beaverhabits/blob/main/beaverhabits/frontend/components.py"
    click FLayout "https://github.com/daya0576/beaverhabits/blob/main/beaverhabits/frontend/layout.py"
    click Assets "https://github.com/daya0576/beaverhabits/tree/main/statics/"
    click Manifest "https://github.com/daya0576/beaverhabits/blob/main/statics/pwa/manifest.json"
    click SW "https://github.com/daya0576/beaverhabits/blob/main/statics/pwa/service_worker.js"
    click API "https://github.com/daya0576/beaverhabits/blob/main/beaverhabits/api.py"
    click Auth "https://github.com/daya0576/beaverhabits/blob/main/beaverhabits/app/auth.py"
    click CRUD "https://github.com/daya0576/beaverhabits/blob/main/beaverhabits/app/crud.py"
    click Middle "https://github.com/daya0576/beaverhabits/blob/main/beaverhabits/app/middelwares.py"
    click Schema "https://github.com/daya0576/beaverhabits/blob/main/beaverhabits/app/schemas.py"
    click StorageAbs "https://github.com/daya0576/beaverhabits/blob/main/beaverhabits/storage/meta.py"
    click SQLite "https://github.com/daya0576/beaverhabits/blob/main/beaverhabits/storage/user_db.py"
    click FileStore "https://github.com/daya0576/beaverhabits/blob/main/beaverhabits/storage/user_file.py"
    click SessionStore "https://github.com/daya0576/beaverhabits/blob/main/beaverhabits/storage/session_file.py"
    click Config "https://github.com/daya0576/beaverhabits/blob/main/beaverhabits/configs.py"
    click CICD "https://github.com/daya0576/beaverhabits/tree/main/.github/workflows/"
```
