# olalkeith/personal-journal-app architecture

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

- Interactive diagram: https://gitdiagram.com/olalkeith/personal-journal-app
- Repository: https://github.com/olalkeith/personal-journal-app

## Overview

##### Main Components
- Frontend: Represent the Next.js application layer where the browser-based UI is rendered (using pages in src/app and src/pages). Include components for layout, global CSS, and any reusable UI components.
- API Layer (Backend): Split into two parts:
- REST API Routes: Found under src/pages/api (with routes for authentication, journal CRUD operations).
- GraphQL API: Hosted under src/graphql (with schema and resolvers). Indicate how GraphQL integrates and serves client requests.
- Database: PostgreSQL is used for persistent data storage, accessed through Prisma. Show the connection between API handlers and the Prisma ORM.
- Authentication/Authorization: Highlight the user authentication mechanism (JWT-based with helpers in src/lib/auth.ts and permissions in src/lib/permissions.ts) securing the login and registration endpoints.
- Supporting Infrastructure:
- Testing: Display testing infrastructure for automated tests, referencing Jest (unit tests) and Cypress (e2e tests) as separate components.
- Migrations and Seeding: Include the Prisma migrations (prisma/migrations) and seed scripts as part of the database setup.

##### Relationships and Data Flows
- Data interactions between the API servers and the PostgreSQL database through the Prisma client (located in src/lib/prisma.ts).
- That authentication requests (login, register) interact with the authentication logic (JWT and bcrypt) and then update or query the database.

##### Architectural Patterns and Design Principles
- Full-Stack Separation: Clearly delineate between the client-side rendered UI (Next.js pages/components) and the server-side API (Next.js API routes).
- Modular Design: Highlight modularization by showing separate components for GraphQL, REST API endpoints, and utility libraries.
- Security: Emphasize authentication and authorization mechanisms ensuring proper validation before database operations.

##### Relevant Technologies
- Frontend: Next.js with TypeScript (show pages, global styles, and components).
- Backend: Next.js API routes (for REST endpoints) and GraphQL schema/resolvers.
- Database: PostgreSQL with migrations and seeding via Prisma.
- Authentication: JWT with jsonwebtoken and bcrypt.
- Testing: Use Jest for unit testing and Cypress for end-to-end testing.
- Others: ESLint, Husky (for pre-commit hooks), and supporting configuration files.

##### Final Advice
- Every significant interaction—especially between the UI, API endpoints, and the database.

## Diagram (Mermaid)

```mermaid
graph TD
    %% Global User
    U["User / Browser"]:::user

    %% Frontend Layer
    subgraph "Frontend (Next.js UI)"
        FD1["App Directory"]:::frontend
        FD2["Pages Directory"]:::frontend
        FD3["Layout File"]:::frontend
        FD4["Page File"]:::frontend
    end

    %% REST API Layer
    subgraph "REST API"
        RA1["API Directory"]:::backend
        RA2["Auth: Login"]:::backend
        RA3["Auth: Register"]:::backend
        RA4["Journal: Index"]:::backend
        RA5["Journal: ID Route"]:::backend
        RA6["Journal: Delete"]:::backend
    end

    %% GraphQL API Layer
    subgraph "GraphQL API"
        GA1["GraphQL Directory"]:::backend
        GA2["GraphQL Schema"]:::backend
        GA3["GraphQL Resolvers"]:::backend
        GA4["GraphQL Integration"]:::backend
    end

    %% Authentication/Authorization Utilities
    subgraph "Authentication"
        AH["Auth Helpers"]:::auth
        PERM["Permissions"]:::auth
    end

    %% Database Layer
    subgraph "Database (PostgreSQL via Prisma)"
        DB1["Prisma Schema"]:::database
        DB2["Migrations"]:::database
        DB3["Seed Script"]:::database
        DB4["Prisma Client"]:::database
    end

    %% Testing Infrastructure
    subgraph "Testing"
        T1["Cypress E2E"]:::testing
        T2["Jest: jest.config.js"]:::testing
        T3["Jest: jest.config.ts"]:::testing
        T4["Jest: jest.setup.ts"]:::testing
        T5["Home Test"]:::testing
        T6["Auth RBAC Test"]:::testing
        T7["Auth Test"]:::testing
    end

    %% Supporting Infrastructure
    subgraph "Supporting Infrastructure"
        S1["Husky"]:::infra
        S2["ESLint Config"]:::infra
    end

    %% Connections
    U -->|"triggers"| FD1
    FD1 -->|"REST call"| RA1
    FD1 -->|"GraphQL call"| GA4

    %% REST API calls to Authentication utilities
    RA2 -->|"uses"| AH
    RA3 -->|"uses"| AH
    AH -->|"validates"| PERM
    PERM -->|"queries"| DB4

    %% REST API interactions with Database
    RA1 -->|"CRUD operations"| DB4

    %% GraphQL API interaction with Database via Integration
    GA4 -->|"queries"| DB4

    %% Additional flows from other REST API endpoints to Database
    RA4 -->|"data operations"| DB4
    RA5 -->|"data operations"| DB4
    RA6 -->|"data operations"| DB4

    %% Class Definitions
    classDef user fill:#f9f,stroke:#333,stroke-width:2px,color:#000;
    classDef frontend fill:#bbf,stroke:#333,stroke-width:2px,color:#000;
    classDef backend fill:#dfd,stroke:#333,stroke-width:2px,color:#000;
    classDef auth fill:#fdd,stroke:#333,stroke-width:2px,color:#000;
    classDef database fill:#ffd,stroke:#333,stroke-width:2px,color:#000;
    classDef testing fill:#fee,stroke:#333,stroke-width:2px,color:#000;
    classDef infra fill:#eef,stroke:#333,stroke-width:2px,color:#000;

    %% Click Events for Frontend
    click FD1 "https://github.com/olalkeith/personal-journal-app/tree/main/src/app"
    click FD2 "https://github.com/olalkeith/personal-journal-app/tree/main/src/pages"
    click FD3 "https://github.com/olalkeith/personal-journal-app/blob/main/src/app/layout.tsx"
    click FD4 "https://github.com/olalkeith/personal-journal-app/blob/main/src/app/page.tsx"

    %% Click Events for REST API
    click RA1 "https://github.com/olalkeith/personal-journal-app/tree/main/src/pages/api"
    click RA2 "https://github.com/olalkeith/personal-journal-app/blob/main/src/pages/api/auth/login.ts"
    click RA3 "https://github.com/olalkeith/personal-journal-app/blob/main/src/pages/api/auth/register.ts"
    click RA4 "https://github.com/olalkeith/personal-journal-app/blob/main/src/pages/api/journal/index.ts"
    click RA5 "https://github.com/olalkeith/personal-journal-app/blob/main/src/pages/api/journal/[id].ts"
    click RA6 "https://github.com/olalkeith/personal-journal-app/blob/main/src/pages/api/journal/delete.ts"

    %% Click Events for GraphQL API
    click GA1 "https://github.com/olalkeith/personal-journal-app/tree/main/src/graphql"
    click GA2 "https://github.com/olalkeith/personal-journal-app/blob/main/src/graphql/schema.ts"
    click GA3 "https://github.com/olalkeith/personal-journal-app/blob/main/src/graphql/resolvers.ts"
    click GA4 "https://github.com/olalkeith/personal-journal-app/blob/main/src/pages/api/graphql.ts"

    %% Click Events for Authentication Utilities
    click AH "https://github.com/olalkeith/personal-journal-app/blob/main/src/lib/auth.ts"
    click PERM "https://github.com/olalkeith/personal-journal-app/blob/main/src/lib/permissions.ts"

    %% Click Events for Database
    click DB1 "https://github.com/olalkeith/personal-journal-app/blob/main/prisma/schema.prisma"
    click DB2 "https://github.com/olalkeith/personal-journal-app/tree/main/prisma/migrations"
    click DB3 "https://github.com/olalkeith/personal-journal-app/blob/main/prisma/seed.ts"
    click DB4 "https://github.com/olalkeith/personal-journal-app/blob/main/src/lib/prisma.ts"

    %% Click Events for Testing Infrastructure
    click T1 "https://github.com/olalkeith/personal-journal-app/tree/main/cypress"
    click T2 "https://github.com/olalkeith/personal-journal-app/blob/main/jest.config.js"
    click T3 "https://github.com/olalkeith/personal-journal-app/blob/main/jest.config.ts"
    click T4 "https://github.com/olalkeith/personal-journal-app/blob/main/jest.setup.ts"
    click T5 "https://github.com/olalkeith/personal-journal-app/blob/main/src/tests/Home.test.tsx"
    click T6 "https://github.com/olalkeith/personal-journal-app/blob/main/src/tests/auth-rbac.test.ts"
    click T7 "https://github.com/olalkeith/personal-journal-app/blob/main/src/tests/auth.test.ts"

    %% Click Events for Supporting Infrastructure
    click S1 "https://github.com/olalkeith/personal-journal-app/blob/main/.husky"
    click S2 "https://github.com/olalkeith/personal-journal-app/blob/main/eslint.config.mjs"
```
