# jordan-dalby/bytestash architecture

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

- Interactive diagram: https://gitdiagram.com/jordan-dalby/bytestash
- Repository: https://github.com/jordan-dalby/bytestash

## Overview

##### Main Components

a. Client Layer:
- React Frontend (SPA)
- Component structure following feature-based organization
- Authentication handling
- Theme management
- Toast notifications

b. Server Layer:
- Node.js/Express backend
- Authentication middleware
- API routes
- Repository layer
- Services layer

c. Storage Layer:
- SQLite database
- File system storage for snippets

##### Key Interactions

- Client-Server communication via REST API
- Authentication flow (including OIDC when enabled)
- Database interactions
- File system operations

##### Detailed Component Breakdown

Frontend (Client):
- Auth Module (OIDC + Internal)
- Snippet Management
- Category Management
- Search & Filter
- Settings
- Embedding System
- API Key Management

Backend (Server):
- Route Handlers
- Authentication Middleware
- Repository Layer
- Service Layer
- OIDC Integration
- API Key Management

**[Client Layer]**
- ↕ HTTP/REST
**[API Gateway/Middleware Layer]**
- ↕
**[Service Layer]**
- ↕
**[Data Access Layer]**
- ↕
**[Storage Layer]**

##### Integration Points

Key integration points:
- OIDC authentication flow
- API key authentication
- Snippet sharing mechanism
- Embedding functionality

##### Deployment Context

Deployment-related components:
- Docker container
- Volume mounts
- Network interfaces
- Helm chart deployment options

Remember to include:
- Version information
- Environment configuration points
- Security boundaries
- Data flow directions
- Component dependencies

This will provide a complete picture of ByteStash's architecture while maintaining clarity and usefulness for development and deployment purposes.

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph Client
        FE["React Frontend"]
        Auth["Authentication Module"]
        Theme["Theme Management"]
        Toast["Toast Notifications"]
        Snip["Snippet Management"]
        Cat["Category Management"]
        Search["Search & Filter"]
        Settings["Settings Module"]
        Embed["Embedding System"]
        ApiKeyFE["API Key Management"]
        OidcFE["OIDC Client"]
        Share["Sharing System"]
        Editor["Code Editor"]
    end

    subgraph Server
        BE["Express Backend"]
        AuthMW["Authentication Middleware"]
        Routes["API Routes"]
        Repos["Repository Layer"]
        Services["Services Layer"]
        ApiKeyBE["API Key Service"]
        OidcBE["OIDC Integration"]
        ShareBE["Share Service"]
    end

    subgraph Storage
        DB[(SQLite Database)]
        FS[("File System")]
    end

    subgraph External
        OIDC["OIDC Provider"]
    end

    %% Client Layer Relationships
    FE --> Auth
    FE --> Theme
    FE --> Toast
    FE --> Snip
    FE --> Cat
    FE --> Search
    FE --> Settings
    FE --> Embed
    FE --> ApiKeyFE
    FE --> OidcFE
    FE --> Share
    FE --> Editor

    %% Server Layer Relationships
    BE --> AuthMW
    BE --> Routes
    Routes --> Services
    Services --> Repos
    Services --> ApiKeyBE
    Services --> OidcBE
    Services --> ShareBE

    %% Cross-Layer Communication
    Client -- "HTTP/REST" --> Server
    Repos --> DB
    Repos --> FS
    OidcFE <--> OIDC
    OidcBE <--> OIDC

    %% Click Events
    click FE "https://github.com/jordan-dalby/ByteStash/tree/main/client/src"
    click Auth "https://github.com/jordan-dalby/ByteStash/tree/main/client/src/components/auth"
    click Theme "https://github.com/jordan-dalby/ByteStash/blob/main/client/src/contexts/ThemeContext.tsx"
    click Toast "https://github.com/jordan-dalby/ByteStash/blob/main/client/src/contexts/ToastContext.tsx"
    click BE "https://github.com/jordan-dalby/ByteStash/tree/main/server/src"
    click AuthMW "https://github.com/jordan-dalby/ByteStash/blob/main/server/src/middleware/auth.js"
    click Routes "https://github.com/jordan-dalby/ByteStash/tree/main/server/src/routes"
    click Repos "https://github.com/jordan-dalby/ByteStash/tree/main/server/src/repositories"
    click Services "https://github.com/jordan-dalby/ByteStash/tree/main/server/src/services"
    click Snip "https://github.com/jordan-dalby/ByteStash/tree/main/client/src/components/snippets"
    click Cat "https://github.com/jordan-dalby/ByteStash/tree/main/client/src/components/categories"
    click Search "https://github.com/jordan-dalby/ByteStash/tree/main/client/src/components/search"
    click Settings "https://github.com/jordan-dalby/ByteStash/tree/main/client/src/components/settings"
    click Embed "https://github.com/jordan-dalby/ByteStash/tree/main/client/src/components/snippets/embed"
    click ApiKeyFE "https://github.com/jordan-dalby/ByteStash/blob/main/client/src/components/auth/ApiKeysModal.tsx"
    click ApiKeyBE "https://github.com/jordan-dalby/ByteStash/blob/main/server/src/repositories/apiKeyRepository.js"
    click OidcFE "https://github.com/jordan-dalby/ByteStash/tree/main/client/src/components/auth/oidc"
    click OidcBE "https://github.com/jordan-dalby/ByteStash/tree/main/server/src/oidc"
    click DB "https://github.com/jordan-dalby/ByteStash/blob/main/server/src/config/database.js"
    click Share "https://github.com/jordan-dalby/ByteStash/tree/main/client/src/components/snippets/share"
    click ShareBE "https://github.com/jordan-dalby/ByteStash/blob/main/server/src/routes/shareRoutes.js"
    click Editor "https://github.com/jordan-dalby/ByteStash/tree/main/client/src/components/editor"

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

    class FE,Theme,Toast,Snip,Cat,Search,Settings,Embed,Share,Editor frontend
    class BE,Routes,Repos,Services,ShareBE backend
    class Auth,AuthMW,ApiKeyFE,ApiKeyBE,OidcFE,OidcBE auth
    class DB,FS storage
    class OIDC external
```
