# theopfr/cachew-db architecture

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

- Interactive diagram: https://gitdiagram.com/theopfr/cachew-db
- Repository: https://github.com/theopfr/cachew-db

## Overview

##### Main Components

a) Server Component (cachew):
- Authentication Module
- Database Engine (B-tree implementation)
- Protocol Handler (CASP)
- Command Processor
- State Manager
- Error Handler

b) Client Components:
- CLI Client
- Python Client (planned)
- Dashboard (planned)

**[Client Layer]**
- ↕ CASP Protocol
**[Server Layer]**
- ↕
**[Storage Layer]**

##### Detailed Component Breakdown

- Surround it with the State Manager
- Command Processor interface
- Authentication Module
- Error Handler spanning across components

b) Protocol Layer (Between Server and Clients):
- CASP Protocol handler
- Bidirectional communication flows
- Authentication flow

c) Client Layer (Top):
- CLI Client
- Placeholder for Python Client
- Placeholder for Dashboard
- All connecting through CASP

##### Specific Elements

**⬡ Server Components**
**⬢ Active Clients**
**⬣ Planned Clients**
**→ Data Flow**
**⇢ Authentication Flow**

##### Key Relationships to Highlight

- How authentication flows through the system
- B-tree's relationship with the command processor
- Demonstrate concurrent client handling
- Error propagation paths

##### Technical Details

- Port/Host configuration (8080 default)
- Supported data types (STR, INT, FLOAT, BOOL, JSON)
- Command processing flow
- In-memory storage indication

##### Implementation Notes

- The non-persistent, in-memory nature
- Type safety mechanisms
- Concurrent client handling
- The ordered nature of the B-tree storage

##### Future Extension Points

Placeholder connections for:
- Persistence layer (planned)
- Additional client implementations
- Dashboard integration
- INCR/DECR command support

## Diagram (Mermaid)

```mermaid
graph TB
    %% Style Definitions
    classDef server fill:#2374ab
    classDef client fill:#57cc99
    classDef planned fill:#ffb703,stroke-dasharray: 5 5
    classDef security fill:#e63946
    classDef protocol fill:#8d99ae
    classDef error fill:#ff758f
    
    %% Client Layer
    subgraph Clients
        CLI["CLI Client"]:::client
        PythonClient["Python Client"]:::planned
        Dashboard["Dashboard"]:::planned
    end
    
    click CLI "https://github.com/theopfr/cachew-db/tree/main/cli-client/"
    click PythonClient "https://github.com/theopfr/cachew-db/tree/main/python-client/"
    click Dashboard "https://github.com/theopfr/cachew-db/tree/main/dashboard/"
    
    %% Protocol Layer
    CASP["CASP Protocol Handler"]:::protocol
    
    click CASP "https://github.com/theopfr/cachew-db/blob/main/CASP_SPECIFICATION.md"
    
    %% Server Core Layer
    subgraph ServerCore
        Auth["Authentication Module"]:::security
        CmdProc["Command Processor"]:::server
        StateMan["State Manager"]:::server
        DBEngine["Database Engine\n(B-tree)"]:::server
        Schema["Schema Handler"]:::server
        Response["Response Handler"]:::server
    end
    
    click Auth "https://github.com/theopfr/cachew-db/blob/main/cachew/src/server.rs"
    click CmdProc "https://github.com/theopfr/cachew-db/blob/main/cachew/src/parser.rs"
    click StateMan "https://github.com/theopfr/cachew-db/blob/main/cachew/src/state.rs"
    click DBEngine "https://github.com/theopfr/cachew-db/blob/main/cachew/src/database.rs"
    click Schema "https://github.com/theopfr/cachew-db/blob/main/cachew/src/schemas.rs"
    click Response "https://github.com/theopfr/cachew-db/blob/main/cachew/src/response.rs"
    
    %% Error Handler Layer
    subgraph ErrorHandling
        ErrHandler["Error Handler"]:::error
        AuthErr["Authentication Errors"]:::error
        DBErr["Database Errors"]:::error
        ProtErr["Protocol Errors"]:::error
        ParseErr["Parser Errors"]:::error
    end
    
    click ErrHandler "https://github.com/theopfr/cachew-db/tree/main/cachew/src/errors/"
    click AuthErr "https://github.com/theopfr/cachew-db/blob/main/cachew/src/errors/authentication_errors.rs"
    click DBErr "https://github.com/theopfr/cachew-db/blob/main/cachew/src/errors/database_errors.rs"
    click ProtErr "https://github.com/theopfr/cachew-db/blob/main/cachew/src/errors/protocol_errors.rs"
    click ParseErr "https://github.com/theopfr/cachew-db/blob/main/cachew/src/errors/parser_errors.rs"
    
    %% Connections
    CLI --> CASP
    PythonClient -.-> CASP
    Dashboard -.-> CASP
    
    CASP --> Auth
    Auth --> CmdProc
    CmdProc --> StateMan
    CmdProc --> Schema
    StateMan --> DBEngine
    DBEngine --> Response
    Response --> CASP
    
    %% Error Handling Connections
    ErrHandler --> AuthErr
    ErrHandler --> DBErr
    ErrHandler --> ProtErr
    ErrHandler --> ParseErr
    
    Auth -.-> AuthErr
    DBEngine -.-> DBErr
    CASP -.-> ProtErr
    CmdProc -.-> ParseErr
    
    %% Legend
    subgraph Legend
        L1["Server Component"]:::server
        L2["Active Client"]:::client
        L3["Planned Component"]:::planned
        L4["Security Component"]:::security
        L5["Protocol Component"]:::protocol
        L6["Error Handling"]:::error
    end
```
