# duncanritchie/velut architecture

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

- Interactive diagram: https://gitdiagram.com/duncanritchie/velut
- Repository: https://github.com/duncanritchie/velut

## Overview

##### High-Level Architecture Overview

a. Client Layer:
- Next.js Frontend (Server-Side Rendered)
- Client-Side Components (for specific features like Multi-word search)

b. Server Layer:
- Next.js Server
- API Routes (/api/word/*)

c. Data Layer:
- MongoDB Collections (lemmata, words, summary)

##### Component Breakdown
Create sub-sections showing:

a. Page Components:
- Main pages (home, word details, advanced search, etc.)
- Layout components (header, footer)
- Specialized components (search, forms tables, parsing lists)

b. Core Features:
- Word Processing
- Rhyming Logic
- Inflection Handling
- Multi-word Search

##### Data Flow Architecture
Following flows:

a. Search Flow:
- User Input → Server-Side Processing → MongoDB Queries → Rendered Results
- Special handling for client-side rendering in Multi-word search

b. Word Processing Flow:
- Input Processing → Diacritics Handling → Database Lookup → Results Formation

##### External Integrations
- MongoDB Atlas Connection
- Fly.io Deployment
- External Dictionary Links (Logeion, Wiktionary)

##### Specific elements
- MongoDB collections (lemmata, words, summary)
- Next.js pages structure
- API routes
- Component hierarchy
- Data processing pipeline

##### Server-side rendering architecture
- How Next.js handles page requests
- Where client-side rendering is used (Multi-word search)

##### Data Processing Pipeline
- Flow from raw input to processed results
- Diacritics handling and word normalization

##### Search Functionality
- Different search types (rhymes, anagrams, subwords)
- Advanced search features
- Multi-word processing

##### Database Interaction
- MongoDB connection handling
- Collection relationships
- Query patterns

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Client
        FC[Frontend Components]
        LC[Layout Components]
        SC[Search Components]
        ASC[Advanced Search]
        MWS[Multi-word Search]
        FT[Forms Tables]
        PL[Parsing Lists]
        DL[Dictionary Links]
    end

    subgraph Server
        NJS[Next.js Server]
        subgraph API
            AR["/api/word/*"]
            WP[Word Processing]
            RL[Rhyming Logic]
            IH[Inflection Handler]
            MWP[Multi-word Processor]
            DH[Diacritics Handler]
            SP[Scansion Processor]
            SWP[Subwords Processor]
        end
    end

    subgraph Database
        MDB[(MongoDB)]
        LEM[(Lemmata Collection)]
        WRD[(Words Collection)]
        SUM[(Summary Collection)]
    end

    subgraph External
        MA[MongoDB Atlas]
        FLY[Fly.io]
        EXT[External Dictionaries]
    end

    %% Connections
    FC --> NJS
    NJS --> AR
    AR --> WP
    WP --> RL
    WP --> IH
    WP --> MWP
    WP --> DH
    WP --> SP
    WP --> SWP
    WP -.-> MDB
    MDB --- LEM
    MDB --- WRD
    MDB --- SUM
    NJS --> MA
    MA --> FLY
    DL --> EXT

    %% Click Events
    click WP "https://github.com/DuncanRitchie/velut/tree/main/lib/words/"
    click RL "https://github.com/DuncanRitchie/velut/blob/main/lib/words/rhymes.js"
    click IH "https://github.com/DuncanRitchie/velut/tree/main/lib/lemmata/"
    click MWP "https://github.com/DuncanRitchie/velut/blob/main/lib/words/multi.js"
    click DH "https://github.com/DuncanRitchie/velut/blob/main/lib/words/diacritics.js"
    click SP "https://github.com/DuncanRitchie/velut/blob/main/lib/words/scansion.js"
    click SWP "https://github.com/DuncanRitchie/velut/blob/main/lib/words/subwords.js"
    click AR "https://github.com/DuncanRitchie/velut/tree/main/pages/api/word/"
    click LC "https://github.com/DuncanRitchie/velut/blob/main/components/header/Header.jsx"
    click SC "https://github.com/DuncanRitchie/velut/blob/main/components/search/Search.jsx"
    click ASC "https://github.com/DuncanRitchie/velut/blob/main/components/advanced/AdvancedSearch.jsx"
    click MWS "https://github.com/DuncanRitchie/velut/blob/main/components/multi/MultiCSR.jsx"
    click FT "https://github.com/DuncanRitchie/velut/tree/main/components/formsTables/"
    click PL "https://github.com/DuncanRitchie/velut/blob/main/components/parsingsList/ParsingsList.jsx"
    click DL "https://github.com/DuncanRitchie/velut/blob/main/components/dictionaries/Dictionaries.jsx"

    %% Styling
    classDef frontend fill:#a8d1ff
    classDef server fill:#98ff98
    classDef database fill:#ffeb99
    classDef external fill:#e6e6e6
    classDef api fill:#ffd1dc

    class FC,LC,SC,ASC,MWS,FT,PL,DL frontend
    class NJS,WP,RL,IH,MWP,DH,SP,SWP server
    class MDB,LEM,WRD,SUM database
    class MA,FLY,EXT external
    class AR api
```
