# saharcarmel/locallibrary architecture

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

- Interactive diagram: https://gitdiagram.com/saharcarmel/locallibrary
- Repository: https://github.com/saharcarmel/locallibrary

## Overview

##### Main Components Identification
The system consists of two primary layers that should be prominently displayed:

Frontend Layer (React Application):
- Main Components (BookSelector, LibraryAnalytics, ReadingMetrics)
- UI Components (buttons, cards, dialogs, inputs)
- Hooks (useLibraryStats)

Backend Layer (Python/FastAPI):
- API Routers (books, sessions, stats)
- Database Interface (database.py)
- Data Models (models.py, schemas.py)
- Library Scanner (scan_lib.py)

##### Component Relationships

- Library Scanner → Books: Data ingestion flow

##### Specific Elements

Frontend Section:
**┌─ Frontend (React) ─────────────────┐**
- ┌─ Views ─────┐ ┌─ Components ─┐  │
- BookSelector │ │SessionAdd    │  │
- LibAnalytics │ │UI Components │  │
- ReadMetrics  │ └─────────────┘  │
- ┘                   │
- ┌─ Hooks ──────────────────────┐ │
- useLibraryStats               │ │
- ┘  │
- ┘

Backend Section:
**┌─ Backend (FastAPI) ───────────────┐**
- ┌─ API Routes ─┐ ┌─ Data Layer ┐ │
- /books        │ │Models       │ │
- /sessions     │ │Schemas      │ │
- /stats        │ │Database     │ │
- ┘ └────────────┘  │
- ┌─ Services ──────────────────┐  │
- Library Scanner              │  │
- ┘  │
- ┘

##### Additional Details

Environment & Configuration:
- Configuration files (.env, vite.config.js)
- Development/production environments

Database:
- Schema structure (reference schema.sql)
- Data flow directions

##### Notes for Implementation

- Use consistent spacing and alignment
- Version information
- Notes about scaling considerations
- Document authentication flow if present

- Component nesting
- Custom styling
- Export to various formats
- Easy updates and modifications

Remember to maintain a balance between detail and clarity, focusing on the architectural decisions that matter most for understanding the system's structure and data flow.

- How the frontend and backend communicate
- Where data is stored and processed
- How the library scanning feature integrates
- The overall system architecture and dependencies

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Frontend
        MainComponents["Main Components"]
        UIComponents["UI Components"]
        Hooks["Hooks & Utils"]
        SessionMgmt["Session Management"]
        
        subgraph MainComponents
            BS["BookSelector"]:::component
            LA["LibraryAnalytics"]:::component
            RM["ReadingMetrics"]:::component
        end
        
        subgraph UIComponents
            BTN["Button"]:::component
            CRD["Card"]:::component
            DLG["Dialog"]:::component
            INP["Input"]:::component
            PRG["Progress"]:::component
        end
        
        subgraph Hooks
            ULS["useLibraryStats"]:::component
        end
        
        subgraph SessionMgmt
            SA["SessionAdd"]:::component
        end
        
        FE["Frontend Entry"]:::component
        FC["Frontend Config"]:::config
    end
    
    subgraph Backend
        APIRouters["API Routers"]
        DataLayer["Data Layer"]
        Services["Services"]
        
        subgraph APIRouters
            BR["Books Router"]:::component
            SR["Sessions Router"]:::component
            STR["Stats Router"]:::component
        end
        
        subgraph DataLayer
            DI["Database Interface"]:::component
            DM["Data Models"]:::component
            DS["Data Schemas"]:::component
            DSC["Database Schema"]:::component
        end
        
        subgraph Services
            LS["Library Scanner"]:::component
            DIS["Data Import Service"]:::component
        end
        
        BE["Backend Entry"]:::component
        BC["Backend Config"]:::config
        DC["Development Config"]:::config
    end
    
    %% Relationships
    MainComponents --> APIRouters
    SessionMgmt --> SR
    Hooks --> STR
    Services --> DataLayer
    APIRouters --> DataLayer
    
    %% Styles
    classDef component fill:#a8d5ff,stroke:#333,stroke-width:1px
    classDef config fill:#ffe0a8,stroke:#333,stroke-width:1px
    
    %% Click Events
    click BS "https://github.com/SaharCarmel/LocalLibrary/blob/main//src/BookSelector.jsx"
    click LA "https://github.com/SaharCarmel/LocalLibrary/blob/main//src/LibraryAnalytics.jsx"
    click RM "https://github.com/SaharCarmel/LocalLibrary/blob/main//src/ReadingMetrics.jsx"
    click BTN "https://github.com/SaharCarmel/LocalLibrary/blob/main//src/components/ui/button.jsx"
    click CRD "https://github.com/SaharCarmel/LocalLibrary/blob/main//src/components/ui/card.jsx"
    click DLG "https://github.com/SaharCarmel/LocalLibrary/blob/main//src/components/ui/dialog.jsx"
    click INP "https://github.com/SaharCarmel/LocalLibrary/blob/main//src/components/ui/input.jsx"
    click PRG "https://github.com/SaharCarmel/LocalLibrary/blob/main//src/components/ui/progress.jsx"
    click ULS "https://github.com/SaharCarmel/LocalLibrary/blob/main//src/hooks/useLibraryStats.js"
    click SA "https://github.com/SaharCarmel/LocalLibrary/blob/main//src/components/SessionAdd.jsx"
    click BR "https://github.com/SaharCarmel/LocalLibrary/blob/main//server/routers/books.py"
    click SR "https://github.com/SaharCarmel/LocalLibrary/blob/main//server/routers/sessions.py"
    click STR "https://github.com/SaharCarmel/LocalLibrary/blob/main//server/routers/stats.py"
    click DI "https://github.com/SaharCarmel/LocalLibrary/blob/main//server/database.py"
    click DM "https://github.com/SaharCarmel/LocalLibrary/blob/main//server/models.py"
    click DS "https://github.com/SaharCarmel/LocalLibrary/blob/main//server/schemas.py"
    click DSC "https://github.com/SaharCarmel/LocalLibrary/blob/main//server/schema.sql"
    click LS "https://github.com/SaharCarmel/LocalLibrary/blob/main//server/scan_lib.py"
    click DIS "https://github.com/SaharCarmel/LocalLibrary/blob/main//server/import_data.py"
    click FE "https://github.com/SaharCarmel/LocalLibrary/blob/main//src/main.jsx"
    click BE "https://github.com/SaharCarmel/LocalLibrary/blob/main//server/main.py"
    click FC "https://github.com/SaharCarmel/LocalLibrary/blob/main//vite.config.js"
    click BC "https://github.com/SaharCarmel/LocalLibrary/blob/main//server/.env"
    click DC "https://github.com/SaharCarmel/LocalLibrary/blob/main//.env.development"
```
