# pseudo3programmer/emotive-diary architecture

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

- Interactive diagram: https://gitdiagram.com/pseudo3programmer/emotive-diary
- Repository: https://github.com/pseudo3programmer/emotive-diary

## Overview

##### Project Type and Purpose
- Emotivo Diary is a full-stack journal application where users can create journal entries that include emotion analysis. The purpose of the application is to help users track and understand their emotions over time.
- The README confirms that the project consists of a React/TypeScript frontend, a Java Spring Boot backend, and an H2 SQL database, making it clear that the solution spans both client and server implementations.

##### File Structure
- The top-level project files (including package.json, vite.config.ts, tailwind.config.ts, etc.) indicate a modern JavaScript/TypeScript setup for the frontend.
- The presence of the “src” directory, further subdivided into “components”, “hooks”, “pages”, “lib”, etc., suggests a well-organized frontend built with React.
- The “backend” directory holds the Java Spring Boot application with its typical Maven structure (“pom.xml”, “src/main/java”, package organization under "com/emotivo/journal") and includes controllers, services, models, and repositories, implying an MVC or layered architecture.
- Additionally, configurations like “application.properties” in the backend point to the H2 database setup and other settings.

##### README for Additional Insights
- The README clearly lists the frontend and backend tech stacks along with instructions on how they interact. It describes that the frontend communicates with the backend via RESTful API calls.
- API endpoints are well-detailed (CRUD operations and search/filter endpoints for journal entries), emphasizing the backend’s role in managing emotion analysis data.

a. Main Components:
- Frontend (React/TypeScript Application):
- Built with Vite, React, and Tailwind CSS.
- Responsible for rendering UI components, routing (React Router), and visualizations (Recharts).
- Contains components such as EntryForm, Timeline, NavigationBar, and UI components (e.g., alerts, carousels) organized under “src/components” and “src/pages”.
- Backend (Java Spring Boot Application):
- Built with Java 17 and uses Spring Data JPA for database interactions.
- Implements RESTful API endpoints for managing journal entries and emotion analysis.
- Contains packages for controllers (handling HTTP requests), services (business logic), models (domain objects), and repositories (database access).
- Entry point is EmotivoJournalApplication.java.
- Database (H2 SQL, with potential ease of switching to MySQL/PostgreSQL):
- Stores journal entries and associated emotion analyses in structured tables.
- Managed by Spring Data JPA on the backend.
- External Interaction:
- REST API communication between the frontend and backend.
- Future integration points such as more advanced emotion analysis or file/image handling may exist.

b. Relationships and Interactions:
- The frontend sends API calls (GET, POST, DELETE) to the backend endpoints, which then perform CRUD operations on the database.
- Data flows from the database through the service and repository layers in the Spring Boot application, then back via controllers to the frontend.

c. Architectural Patterns and Design Principles:
- It employs a layered (or MVC) architecture on the backend: Controllers handle incoming requests, Services encapsulate business logic, and Repositories manage persistence.
- The frontend is component-based (using React), with clear separation between UI elements and business logic (hooks, utility functions).
- Both parts are decoupled via RESTful interfaces to enable scalability and ease of testing.

d. Relevant Technologies, Frameworks, and Libraries to Include:
- Frontend: React, TypeScript, Vite, Tailwind CSS, React Router, shadcn-ui, and Recharts.
- Backend: Java 17, Spring Boot, Spring Data JPA, Maven, and H2 Database.
- How these technologies integrate—for instance, show the frontend project calling API endpoints exposed by Spring Boot, which in turn uses Spring Data JPA to query the H2 database.

## Diagram (Mermaid)

```mermaid
flowchart TD
    A["User Browser"]:::external

    subgraph "Frontend Layer"
        F["Frontend Application (React, Vite, Tailwind)"]:::frontend
        FC["UI Components (NavigationBar, EntryForm, etc.)"]:::frontend
        FP["Page Components (Timeline, Settings, Index)"]:::frontend
        FH["State & Utility Hooks"]:::frontend
        FU["Utility Functions"]:::frontend
        F --> FC
        F --> FP
        F --> FH
        F --> FU
    end

    subgraph "Backend Layer (Spring Boot)"
        BA["Main Application"]:::backend
        BC["Controller Layer (JournalController)"]:::backend
        BS["Service Layer (JournalService)"]:::backend
        BM["Model Classes"]:::backend
        BR["Repository Layer (JournalEntryRepository)"]:::backend
        BD["Database Configuration"]:::backend
        BA --> BC
        BC --> BS
        BS --> BM
        BS --> BR
        %% BD is used to configure database connection
        BD --- D["H2 SQL Database"]:::database
    end

    D["H2 SQL Database"]:::database

    %% Global Flow
    A -->|"initiates request"| F
    F -->|"REST API Call"| BC
    BR -->|"CRUD Operations"| D

    %% Click Events
    click F "https://github.com/pseudo3programmer/emotive-diary/tree/main/src/"
    click FC "https://github.com/pseudo3programmer/emotive-diary/tree/main/src/components/"
    click FP "https://github.com/pseudo3programmer/emotive-diary/tree/main/src/pages/"
    click FH "https://github.com/pseudo3programmer/emotive-diary/tree/main/src/hooks/"
    click FU "https://github.com/pseudo3programmer/emotive-diary/tree/main/src/utils/"
    click FU "https://github.com/pseudo3programmer/emotive-diary/blob/main/src/lib/utils.ts"
    click BA "https://github.com/pseudo3programmer/emotive-diary/blob/main/backend/src/main/java/com/emotivo/journal/EmotivoJournalApplication.java"
    click BC "https://github.com/pseudo3programmer/emotive-diary/blob/main/backend/src/main/java/com/emotivo/journal/controller/JournalController.java"
    click BS "https://github.com/pseudo3programmer/emotive-diary/blob/main/backend/src/main/java/com/emotivo/journal/service/JournalService.java"
    click BM "https://github.com/pseudo3programmer/emotive-diary/tree/main/backend/src/main/java/com/emotivo/journal/model/"
    click BR "https://github.com/pseudo3programmer/emotive-diary/blob/main/backend/src/main/java/com/emotivo/journal/repository/JournalEntryRepository.java"
    click BD "https://github.com/pseudo3programmer/emotive-diary/blob/main/backend/src/main/resources/application.properties"

    %% Styles
    classDef frontend fill:#cce5ff,stroke:#004085,stroke-width:2px;
    classDef backend fill:#d4edda,stroke:#155724,stroke-width:2px;
    classDef database fill:#f8d7da,stroke:#721c24,stroke-width:2px;
    classDef external fill:#fff3cd,stroke:#856404,stroke-width:2px;
```
