# koiralaprijun00/swedish-inventions architecture

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

- Interactive diagram: https://gitdiagram.com/koiralaprijun00/swedish-inventions
- Repository: https://github.com/koiralaprijun00/swedish-inventions

## Overview

##### Main Components
- Next.js Frontend – This is the heart of the project:
- App Shell: Main layouts and pages (e.g., app/page.tsx, src/app/layout.tsx).
- Locale-Specific Routing: Under src/app/[locale] you have subdirectories for languages with dedicated pages (about, invention details via dynamic routes [id], quiz, timeline).
- Reusable Components: Located in src/app/[locale]/components (like Navbar, Footer, InventionCard, InteractiveTimeline, SocialShare, etc.). These are the building blocks for the UI.
- API Layer:
- API Endpoints: Implemented under src/app/api (e.g., send-email endpoint). Also, note there is an alternative implementation in app/pages/api.
- Content and Static Assets:
- Public Assets: The public folder includes multilingual Markdown content (organized under public/content/en and public/content/sv), invention images, robots.txt, and sitemap files.
- External/Static Files: Other resources such as the custom font configuration and Tailwind CSS setup.
- Internationalization (i18n):
- Language Routing and Requests: Code in src/i18n and routing settings that help switch between locales.
- Configuration and Build Scripts:
- Next.js and Tailwind configuration (files like next.config.mjs, tailwind.config.ts, tsconfig.json) indicate the deployment, build optimizations, and toolchain settings.
- Auxiliary Files:
- Additional data sources (e.g., content-collections.ts, messages folder for translations) that support internationalizations and content management.

##### Relationships and Interactions
- The Frontend interacts with the API endpoints (e.g., the send-email API route handles form submissions).
- The UI components (like the quiz and timeline components) may use dynamic data loaded from static Markdown files stored in the public or src/posts directories.
- The i18n routing mechanism determines which locale-specific pages (and associated content) are rendered based on the URL.
- Next.js handles the page rendering server-side (or using static generation) and serves the assets from the public directory.

##### Architectural Patterns and Design Principles
- Component-based Architecture: The project is organized with reusable React components under the components subdirectory.
- File-based Routing: Leveraging Next.js’s convention-over-configuration routing within the app directory.
- Separation of Concerns: Clear distinction between presentational components, API routes, and static assets.
- Internationalization Pattern: Using separate directories for each locale alongside centralized i18n modules in the src/i18n folder.

##### Including Key Technologies
- Next.js (with the App Router) for server-side rendering and static site generation.
- React as the core UI library.
- Tailwind CSS for styling (configured in tailwind.config.ts and imported globally).
- External font optimization via next/font.
- Markdown processing for content files.

##### Additional Details
- Including external links or dependencies such as Vercel deployment, Next.js documentation, and how the font optimization works.
- Avoid oversimplification; instead, break down each high-level component into subcomponents (like explicitly drawing out the locale-specific directories and the component breakdown within them).
- Connections such as the use of middleware (src/middleware.ts) that may influence routing or localization policies.

## Diagram (Mermaid)

```mermaid
flowchart TD

    %% Next.js Frontend
    subgraph "Next.js Frontend"
        %% App Shell
        subgraph "App Shell"
            layout["App Layout (src/app/layout.tsx)"]:::frontend
            homepage["Homepage (src/app/page.tsx)"]:::frontend
            layout --> homepage
        end

        %% Locale-Specific Routing
        subgraph "Locale-Specific Routing"
            localeBase["Locale Base Directory (src/app/[locale])"]:::frontend
            about["About Page (src/app/[locale]/about/page.tsx)"]:::frontend
            invention["Invention Detail Page (src/app/[locale]/invention/[id]/page.tsx)"]:::frontend
            quiz["Quiz Page (src/app/[locale]/quiz/page.tsx)"]:::frontend
            timeline["Timeline Page (src/app/[locale]/timeline/page.tsx)"]:::frontend
            localeBase --> about
            about --> invention
            invention --> quiz
            quiz --> timeline
        end

        %% Reusable Components
        subgraph "Reusable Components"
            uiComponents["UI Components (src/app/[locale]/components)"]:::frontend
            subgraph "Global Components"
                navbar["Navbar (src/app/Navbar.tsx)"]:::frontend
                footer["Footer (src/app/Footer.tsx)"]:::frontend
                localswitcher["LocalSwitcher (src/app/LocalSwitcher.tsx)"]:::frontend
                contactform["ContactForm (src/app/ContactForm.tsx)"]:::frontend
            end
            uiComponents --> navbar
            uiComponents --> footer
            uiComponents --> localswitcher
            uiComponents --> contactform
        end

        %% Connections within Frontend
        layout --> localeBase
        homepage --> uiComponents
    end

    %% API Layer
    subgraph "API Layer"
        apiEmail["API: Send Email (src/app/api/send-email/route.tsx)"]:::api
        apiAlternative["API Alternative (src/app/pages/api/send-email.ts)"]:::api
    end

    %% Content and Static Assets
    subgraph "Content and Static Assets"
        contentEN["Markdown Content EN (public/content/en)"]:::static
        contentSV["Markdown Content SV (public/content/sv)"]:::static
        inventionImages["Invention Images (public/invention-images)"]:::static
        robots["Robots File (public/robots.txt)"]:::static
        sitemap1["Sitemap (public/sitemap.xml)"]:::static
        sitemap0["Sitemap 0 (public/sitemap-0.xml)"]:::static
    end

    %% Internationalization (i18n)
    subgraph "Internationalization (i18n)"
        i18nConfig["i18n Config (src/i18n)"]:::i18n
        messagesEN["Messages EN (messages/en.json)"]:::i18n
        messagesSV["Messages SV (messages/sv.json)"]:::i18n
        i18nConfig --> messagesEN
        i18nConfig --> messagesSV
    end

    %% Configuration and Build
    subgraph "Configuration and Build"
        nextConfig["Next.js Config (next.config.mjs, next.config.ts)"]:::config
        tailwindConfig["Tailwind Config (tailwind.config.ts, src/app/styles/globals.css)"]:::config
        tsConfig["TypeScript Config (tsconfig.json)"]:::config
    end

    %% Auxiliary Files
    subgraph "Auxiliary Files"
        contentCollections["Content Collections (content-collections.ts & types/content-collections.d.ts)"]:::aux
        postsEN["Markdown Posts EN (src/posts/en)"]:::aux
        postsSV["Markdown Posts SV (src/posts/sv)"]:::aux
        middleware["Middleware (src/middleware.ts)"]:::aux
    end

    %% Data Flow Connections
    layout -->|"configures"| nextConfig
    layout --> tailwindConfig
    localeBase -.-> i18nConfig
    middleware --> localeBase
    contentEN --> localeBase
    contentSV --> localeBase
    postsEN --> localeBase
    postsSV --> localeBase
    contentCollections --> localeBase
    homepage --> apiEmail
    homepage --> apiAlternative

    %% Class Definitions
    classDef frontend fill:#D5E8D4,stroke:#82B366,stroke-width:2px;
    classDef api fill:#F8CECC,stroke:#B85450,stroke-width:2px;
    classDef static fill:#DAE8FC,stroke:#6C8EBF,stroke-width:2px;
    classDef i18n fill:#FFF2CC,stroke:#D6B656,stroke-width:2px;
    classDef config fill:#E1D5E7,stroke:#9673A6,stroke-width:2px;
    classDef aux fill:#FFE6CC,stroke:#D79B00,stroke-width:2px;

    %% Click Events
    click layout "https://github.com/koiralaprijun00/swedish-inventions/blob/main/src/app/layout.tsx"
    click homepage "https://github.com/koiralaprijun00/swedish-inventions/blob/main/src/app/page.tsx"

    click localeBase "https://github.com/koiralaprijun00/swedish-inventions/tree/main/src/app/[locale]"
    click about "https://github.com/koiralaprijun00/swedish-inventions/blob/main/src/app/[locale]/about/page.tsx"
    click invention "https://github.com/koiralaprijun00/swedish-inventions/blob/main/src/app/[locale]/invention/[id]/page.tsx"
    click quiz "https://github.com/koiralaprijun00/swedish-inventions/blob/main/src/app/[locale]/quiz/page.tsx"
    click timeline "https://github.com/koiralaprijun00/swedish-inventions/blob/main/src/app/[locale]/timeline/page.tsx"

    click uiComponents "https://github.com/koiralaprijun00/swedish-inventions/tree/main/src/app/[locale]/components"
    click navbar "https://github.com/koiralaprijun00/swedish-inventions/blob/main/src/app/Navbar.tsx"
    click footer "https://github.com/koiralaprijun00/swedish-inventions/blob/main/src/app/Footer.tsx"
    click localswitcher "https://github.com/koiralaprijun00/swedish-inventions/blob/main/src/app/LocalSwitcher.tsx"
    click contactform "https://github.com/koiralaprijun00/swedish-inventions/blob/main/src/app/ContactForm.tsx"

    click apiEmail "https://github.com/koiralaprijun00/swedish-inventions/blob/main/src/app/api/send-email/route.tsx"
    click apiAlternative "https://github.com/koiralaprijun00/swedish-inventions/blob/main/src/app/pages/api/send-email.ts"

    click contentEN "https://github.com/koiralaprijun00/swedish-inventions/tree/main/public/content/en"
    click contentSV "https://github.com/koiralaprijun00/swedish-inventions/tree/main/public/content/sv"
    click inventionImages "https://github.com/koiralaprijun00/swedish-inventions/tree/main/public/invention-images"
    click robots "https://github.com/koiralaprijun00/swedish-inventions/blob/main/public/robots.txt"
    click sitemap1 "https://github.com/koiralaprijun00/swedish-inventions/blob/main/public/sitemap.xml"
    click sitemap0 "https://github.com/koiralaprijun00/swedish-inventions/blob/main/public/sitemap-0.xml"

    click i18nConfig "https://github.com/koiralaprijun00/swedish-inventions/tree/main/src/i18n"
    click messagesEN "https://github.com/koiralaprijun00/swedish-inventions/blob/main/messages/en.json"
    click messagesSV "https://github.com/koiralaprijun00/swedish-inventions/blob/main/messages/sv.json"

    click nextConfig "https://github.com/koiralaprijun00/swedish-inventions/blob/main/next.config.mjs"
    click tailwindConfig "https://github.com/koiralaprijun00/swedish-inventions/blob/main/tailwind.config.ts"
    click tsConfig "https://github.com/koiralaprijun00/swedish-inventions/blob/main/tsconfig.json"

    click contentCollections "https://github.com/koiralaprijun00/swedish-inventions/blob/main/content-collections.ts"
    click postsEN "https://github.com/koiralaprijun00/swedish-inventions/tree/main/src/posts/en"
    click postsSV "https://github.com/koiralaprijun00/swedish-inventions/tree/main/src/posts/sv"
    click middleware "https://github.com/koiralaprijun00/swedish-inventions/blob/main/src/middleware.ts"
```
