# dsc-mcmaster-u/ai-journal architecture

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

- Interactive diagram: https://gitdiagram.com/dsc-mcmaster-u/ai-journal
- Repository: https://github.com/dsc-mcmaster-u/ai-journal

## Overview

##### Main Components

a) Client Layer:
- Next.js Frontend Application
- Auth Module (login)
- Main Application Module (dashboard, journals, stats, settings)
- UI Components Layer
- Custom Hooks Layer

b) Server Layer:
- Express.js Backend
- Controllers Layer
- Services Layer
- Routes Layer
- Middleware Layer
- Authentication System (Passport.js)

c) Database Layer:
- MySQL Database

d) External Services:
- AI Integration (mentioned in project description)
- Authentication Service
- Cloud Infrastructure (Google Cloud)

##### Architecture Pattern Representation

**┌─ Client Layer ─────────────────────┐**
- Next.js Frontend                   │
- ┌─────────────┐ ┌─────────────┐   │
- Auth Module │ │ Main Module │   │
- ┘ └─────────────┘   │
- ┌─────────────┐ ┌─────────────┐   │
- UI Layer    │ │ Hooks Layer │   │
- ┘ └─────────────┘   │
- ┬───────────────────┘

**┌───────────────▼───────────────────┐**
- API Layer                         │
- ┌─────────────┐ ┌─────────────┐   │
- Controllers │ │   Routes    │   │
- ┘ └─────────────┘   │
- ┌─────────────┐ ┌─────────────┐   │
- Services   │ │ Middleware  │   │
- ┘ └─────────────┘   │
- ┬───────────────────┘

**┌───────────────▼───────────────────┐**
- Data Layer                        │
- ┌─────────────┐                   │
- MySQL     │                   │
- ┘                   │
- ┘

##### Key Relationships to Highlight
- Frontend to Backend communication via REST APIs
- Authentication flow between client, server, and database
- Data flow for journal entries and mood tracking
- Integration points with AI services
- Database interactions from various services

##### DevOps Infrastructure
A separate section showing:
- Docker containers
- Kubernetes orchestration
- Google Cloud deployment
- CI/CD pipelines (shown in .github/workflows)

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Client
        FE[Next.js Frontend]
        AuthMod["Authentication Module"]
        MainMod["Main Application Module"]
        UILayer["UI Components Layer"]
        HooksLayer["Custom Hooks Layer"]
        JournalFE["Journal Feature"]
        ApiTest["API Testing Interface"]
        Stats["Statistics Dashboard"]
        Settings["User Settings"]
        CommonUI["Common UI Components"]
        TestFE["Frontend Tests"]
    end

    subgraph Server
        BE[Express.js Backend]
        Controllers["Controllers Layer"]
        Services["Services Layer"]
        Routes["Routes Layer"]
        Middleware["Middleware Layer"]
        PassportAuth["Authentication System"]
        JournalBE["Journal Controller"]
        MoodController["Mood Controller"]
        MoodService["Mood Service"]
        TestBE["Backend Tests"]
    end

    subgraph Database
        DB[(MySQL Database)]
        DBConn["Database Connection"]
    end

    subgraph External
        AI["AI Integration"]
        Auth["Authentication Service"]
        GCloud["Google Cloud"]
        CICD["CI/CD Pipelines"]
    end

    %% Relationships
    FE --> BE
    AuthMod --> PassportAuth
    MainMod --> Controllers
    JournalFE --> JournalBE
    ApiTest --> Routes
    Controllers --> Services
    Services --> DB
    Middleware --> PassportAuth
    PassportAuth --> Auth
    BE --> AI
    BE --> GCloud
    DBConn --> DB

    %% Click Events
    click AuthMod "https://github.com/DSC-McMaster-U/ai-journal/tree/main/frontend/app/(auth)/login"
    click MainMod "https://github.com/DSC-McMaster-U/ai-journal/tree/main/frontend/app/(main)"
    click UILayer "https://github.com/DSC-McMaster-U/ai-journal/tree/main/frontend/components"
    click HooksLayer "https://github.com/DSC-McMaster-U/ai-journal/tree/main/frontend/hooks"
    click Controllers "https://github.com/DSC-McMaster-U/ai-journal/tree/main/backend/src/controllers"
    click Services "https://github.com/DSC-McMaster-U/ai-journal/tree/main/backend/src/services"
    click Routes "https://github.com/DSC-McMaster-U/ai-journal/tree/main/backend/src/routes"
    click Middleware "https://github.com/DSC-McMaster-U/ai-journal/tree/main/backend/src/middleware"
    click PassportAuth "https://github.com/DSC-McMaster-U/ai-journal/blob/main/backend/src/passport.js"
    click DBConn "https://github.com/DSC-McMaster-U/ai-journal/blob/main/backend/src/database.js"
    click JournalFE "https://github.com/DSC-McMaster-U/ai-journal/tree/main/frontend/app/(main)/journals"
    click JournalBE "https://github.com/DSC-McMaster-U/ai-journal/blob/main/backend/src/controllers/journalController.js"
    click MoodController "https://github.com/DSC-McMaster-U/ai-journal/blob/main/backend/src/controllers/moodController.js"
    click MoodService "https://github.com/DSC-McMaster-U/ai-journal/blob/main/backend/src/services/moodService.js"
    click ApiTest "https://github.com/DSC-McMaster-U/ai-journal/tree/main/frontend/app/(main)/api-testing"
    click Stats "https://github.com/DSC-McMaster-U/ai-journal/tree/main/frontend/app/(main)/stats"
    click Settings "https://github.com/DSC-McMaster-U/ai-journal/tree/main/frontend/app/(main)/settings"
    click CommonUI "https://github.com/DSC-McMaster-U/ai-journal/tree/main/frontend/components/common"
    click TestFE "https://github.com/DSC-McMaster-U/ai-journal/tree/main/frontend/components/__tests__"
    click TestBE "https://github.com/DSC-McMaster-U/ai-journal/tree/main/backend/__tests__"
    click CICD "https://github.com/DSC-McMaster-U/ai-journal/tree/main/.github/workflows"

    %% Styling
    classDef frontend fill:#3498db,stroke:#2980b9,color:white
    classDef backend fill:#2ecc71,stroke:#27ae60,color:white
    classDef database fill:#f1c40f,stroke:#f39c12,color:black
    classDef external fill:#9b59b6,stroke:#8e44ad,color:white
    classDef security fill:#e74c3c,stroke:#c0392b,color:white

    class FE,AuthMod,MainMod,UILayer,HooksLayer,JournalFE,ApiTest,Stats,Settings,CommonUI,TestFE frontend
    class BE,Controllers,Services,Routes,Middleware,JournalBE,MoodController,MoodService,TestBE backend
    class DB,DBConn database
    class AI,Auth,GCloud,CICD external
    class PassportAuth security
```
