# timongisler/javalin-diary-rewrite architecture

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

- Interactive diagram: https://gitdiagram.com/timongisler/javalin-diary-rewrite
- Repository: https://github.com/timongisler/javalin-diary-rewrite

## Overview

##### Main Components
- Javalin Web Server – The primary entry point for HTTP requests (see JavalinAppProvider.kt and Main.kt).
- Business Logic/Commands – These are the domain components split into areas such as “entries” (with operations like Save, Update, Delete, Get) and “user” (RegisterCommand and related login tests).
- Database Layer – Includes the Database.kt file and the migration scripts (under src/main/resources/db/migration) which set up the schema for diary entries and users.
- Security Module – Contains classes like AccessManager and Roles (found under src/main/kotlin/security), which enforce authorization checks.
- Common/Utility Functions – Utility functions and context extensions (in src/main/kotlin/common) that support both business logic and request processing.
- Testing Suite – Located under src/test, showing integration tests across user, entry, and common functionality, which indicate design choices like containerized PostgreSQL for integration testing.

##### Relationships and Interactions
- External requests first hit the Javalin web server, where the JavalinAppProvider sets up routing.
- Requests for entry or user operations are mapped to their respective command classes, which in turn interact with the Database layer.
- Database transactions rely on migration scripts to define schema changes.
- Security and authentication calls go through the AccessManager, ensuring that only authorized operations proceed.
- Utility functions (ContextExtensions, UserEmail, UserPassword) support the command classes as middleware or helpers.
- As this is backend-only, any API responses (formatted likely in JSON) are sent back to the client.

##### Architectural Patterns & Design Principles
- Separation of Concerns – The application cleanly separates routing (Javalin handling), business logic (commands for entries and users), and security.
- Layered Architecture – Presentation (HTTP layer), Domain (commands and business logic), and Data Access (Database and migration scripts).
- Use of dependency management through Gradle (build.gradle.kts) ensures that libraries and frameworks are properly integrated.
- Test-Driven Development – A significant test directory ensures components are tested in isolation and integration.

- Every block is clearly labeled with its role (for example, “JavalinAppProvider – Routing & HTTP server” or “Database – Data persistence & Migrations”).
- Dependencies, such as the Security module’s check happening before business logic execution, and the connection between the Database layer and migration scripts.
- That the tests provide validation for each of the up-layer components, demonstrating contract verifications.

Overall, focus on clarity, detailed labeling, and illustrating the separation and flow between the core components identified above.

## Diagram (Mermaid)

```mermaid
graph TD
    %% HTTP Layer
    subgraph "HTTP Layer"
        A["Javalin Web Server"]:::infrastructure
    end

    %% Security Module
    subgraph "Security Module"
        B1["AccessManager"]:::security
        B2["Roles"]:::security
    end

    %% Business Logic Layer
    subgraph "Business Logic"
        subgraph "Entries Module"
            E1["SaveEntryCommand"]:::domain
            E2["UpdateEntryCommand"]:::domain
            E3["DeleteEntryCommand"]:::domain
            E4["GetEntryCommand"]:::domain
            E5["GetEntriesOverviewQuery"]:::domain
        end
        subgraph "User Module"
            U1["RegisterCommand"]:::domain
        end
    end

    %% Database Layer
    subgraph "Database Layer"
        D2["Migration Scripts"]:::database
        D1["Database"]:::database
    end

    %% Common Utilities
    subgraph "Common Utilities"
        U2["ContextExtensions"]:::utility
        U3["UserEmail"]:::utility
        U4["UserPassword"]:::utility
    end

    %% Testing Suite
    subgraph "Testing Suite"
        T1["Integration & Unit Tests"]:::testing
    end

    %% Connections
    A -->|"routes"| B1
    B1 -->|"auth-check"| E1
    B1 -->|"auth-check"| U1
    E1 -->|"CRUD"| D1
    E2 -->|"CRUD"| D1
    E3 -->|"CRUD"| D1
    E4 -->|"CRUD"| D1
    E5 -->|"CRUD"| D1
    U1 -->|"CRUD"| D1
    D2 -->|"schema_updates"| D1
    U2 -.->|"helper"| E1
    U2 -.->|"helper"| U1
    T1 -.->|"tests"| A
    T1 -.->|"tests"| B1
    T1 -.->|"tests"| D1
    T1 -.->|"tests"| E1
    T1 -.->|"tests"| U1

    %% Click Events
    click A "https://github.com/timongisler/javalin-diary-rewrite/blob/master/src/main/kotlin/JavalinAppProvider.kt"
    click A "https://github.com/timongisler/javalin-diary-rewrite/blob/master/src/main/kotlin/Main.kt"
    click E1 "https://github.com/timongisler/javalin-diary-rewrite/tree/master/src/main/kotlin/entries"
    click U1 "https://github.com/timongisler/javalin-diary-rewrite/blob/master/src/main/kotlin/User/RegisterCommand.kt"
    click U1 "https://github.com/timongisler/javalin-diary-rewrite/tree/master/src/test/kotlin/user"
    click D1 "https://github.com/timongisler/javalin-diary-rewrite/blob/master/src/main/kotlin/Database.kt"
    click D2 "https://github.com/timongisler/javalin-diary-rewrite/tree/master/src/main/resources/db/migration"
    click B1 "https://github.com/timongisler/javalin-diary-rewrite/tree/master/src/main/kotlin/security"
    click B2 "https://github.com/timongisler/javalin-diary-rewrite/tree/master/src/main/kotlin/security"
    click U2 "https://github.com/timongisler/javalin-diary-rewrite/tree/master/src/main/kotlin/common"
    click U3 "https://github.com/timongisler/javalin-diary-rewrite/tree/master/src/main/kotlin/common"
    click U4 "https://github.com/timongisler/javalin-diary-rewrite/tree/master/src/main/kotlin/common"
    click T1 "https://github.com/timongisler/javalin-diary-rewrite/tree/master/src/test"

    %% Styles
    classDef infrastructure fill:#AED6F1,stroke:#1F618D,stroke-width:2px;
    classDef security fill:#F5B7B1,stroke:#C0392B,stroke-width:2px;
    classDef domain fill:#F9E79F,stroke:#B7950B,stroke-width:2px;
    classDef database fill:#ABEBC6,stroke:#28B463,stroke-width:2px;
    classDef utility fill:#D7BDE2,stroke:#8E44AD,stroke-width:2px;
    classDef testing fill:#FAD7A0,stroke:#D35400,stroke-width:2px;
```
