# samudradev/samudra architecture

> Architecture diagram of the GitHub repository samudradev/samudra, 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/samudradev/samudra
- Repository: https://github.com/samudradev/samudra

## Overview

##### Main Components Identification

The project is primarily a database-centric application with a Rust-based backend. Here's how to structure the main components:

a) Database Layer:
- Separate PostgreSQL and SQLite support (evident from migrations folders)
- Four main entities: Lemma, Konsep, Cakupan, and Kata_Asing
- Relationships between these entities

b) Core Application Layer:
- Data Operations Module
- State Management
- Error Handling
- I/O Interface

**[Database Layer]**
- PostgreSQL / SQLite
- Tables
- Lemma (Main terms)
- Konsep (Concepts)
- Cakupan (Coverage/Context)
- Kata_Asing (Foreign terms)

**[Application Layer]**
- Core Operations
- Data Operations
- State Management
- Error Handling
- I/O Interface
- Database Interface

##### Relationship Visualization

Use the following conventions:
- Diamond endings for composition relationships
- Crow's foot notation for many-to-many relationships

##### Technical Details

- SQLx as the database interface
- Rust-specific components
- Migration handling for both PostgreSQL and SQLite
- Transaction management
- Error propagation paths

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph DB["Database Layer"]
        direction TB
        PSQL[(PostgreSQL)]
        SQLite[(SQLite)]
        
        subgraph Entities
            direction TB
            Lemma["Lemma (Terms)"]:::entity
            Konsep["Konsep (Concepts)"]:::entity
            Cakupan["Cakupan (Context)"]:::entity
            KataAsing["Kata Asing (Foreign Terms)"]:::entity
        end
        
        Migrations["Database Migrations"]:::component
        PSQL --> Migrations
        SQLite --> Migrations
        Migrations --> Entities
    end
    
    subgraph APP["Application Layer"]
        direction TB
        subgraph Core["Core Operations"]
            direction TB
            DataOps["Data Operations"]:::core
            StateMan["State Management"]:::core
            ErrorHandle["Error Handling"]:::core
        end
        
        subgraph Interface["Interface Layer"]
            direction TB
            IOInterface["I/O Interface"]:::interface
            DBInterface["Database Interface"]:::interface
        end
        
        DataTypes["Data Types"]:::component
        ViewDefs["View Definitions"]:::component
        Changes["Changes Tracking"]:::component
        
        Core --> DataTypes
        Core --> ViewDefs
        Core --> Changes
    end
    
    DBInterface --> DB
    IOInterface --> Core
    Core --> DBInterface
    
    %% Relationships between entities
    Lemma --> Konsep
    Lemma --> Cakupan
    Lemma --> KataAsing
    
    %% Click events for component mapping
    click Lemma "https://github.com/samudradev/samudra/blob/main/database/src/data/items/lemma.rs"
    click Konsep "https://github.com/samudradev/samudra/blob/main/database/src/data/items/konsep.rs"
    click Cakupan "https://github.com/samudradev/samudra/blob/main/database/src/data/items/cakupan.rs"
    click KataAsing "https://github.com/samudradev/samudra/blob/main/database/src/data/items/kata_asing.rs"
    click Migrations "https://github.com/samudradev/samudra/tree/main/database/migrations"
    click DataOps "https://github.com/samudradev/samudra/blob/main/database/src/operations.rs"
    click StateMan "https://github.com/samudradev/samudra/blob/main/database/src/states.rs"
    click ErrorHandle "https://github.com/samudradev/samudra/blob/main/database/src/errors.rs"
    click IOInterface "https://github.com/samudradev/samudra/blob/main/database/src/io/interface.rs"
    click DBInterface "https://github.com/samudradev/samudra/blob/main/database/src/engine.rs"
    click DataTypes "https://github.com/samudradev/samudra/blob/main/database/src/types.rs"
    click ViewDefs "https://github.com/samudradev/samudra/blob/main/database/src/views.rs"
    click Changes "https://github.com/samudradev/samudra/blob/main/database/src/changes.rs"
    
    %% Styling
    classDef entity fill:#a8d5ff,stroke:#333,stroke-width:2px
    classDef core fill:#98ff98,stroke:#333,stroke-width:2px
    classDef interface fill:#ffa07a,stroke:#333,stroke-width:2px
    classDef component fill:#f0f0f0,stroke:#333,stroke-width:2px
    
    %% Legend
    subgraph Legend
        direction TB
        E["Entity"]:::entity
        C["Core Component"]:::core
        I["Interface"]:::interface
        Gen["General Component"]:::component
    end
```
