# stefanluth/kummerkasten architecture

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

- Interactive diagram: https://gitdiagram.com/stefanluth/kummerkasten
- Repository: https://github.com/stefanluth/kummerkasten

## Overview

##### Main System Components

Frontend Layer:
- Main page routes (/top/*, /reported, /unlock, etc.)
- Key components (_components directory)
- Server actions (_actions directory)

Backend Layer:
- API routes (particularly the delete route)
- Prisma ORM connection
- PostgreSQL database

##### Component Relationships

- Client-side components → Server Actions
- Server Actions → Database (via Prisma)
- API Routes → Database (via Prisma)

##### Specific Implementation Details

- Authentication System (password-based access)
- Post Management System
- Voting System
- Reporting System

##### Data Flow

- User interaction flow (unlock → post → vote/report)
- Anonymous data handling
- Post lifecycle (creation → voting → possible reporting → possible deletion)

**[Client Layer]**
- Pages (Next.js Routes)
- Main Feed
- Top Posts (day/week/month/year/all)
- Reported Posts
- Unlock Page

- Components
- NavBar
- Post Components
- Forms (Add/Report)

**[Server Layer]**
- Server Actions
- Post Management
- Voting System
- Report Handling

- API Routes
- Delete Post

**[Data Layer]**
- Prisma ORM
- PostgreSQL Database
- Posts Table
- Votes Table
- Reports Table

Important Elements to Include:

##### Security Features
- Password protection mechanism
- Anonymous submission flow
- Report threshold system

##### State Management
- How post data is fetched and cached
- Voting state management
- Report counting mechanism

- Blue: Client-side components
- Green: Server-side components
- Yellow: Database layer
- Red: Security-critical paths
- Purple: Anonymous data flow

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Styles
    classDef frontend fill:#3498db,color:white
    classDef server fill:#2ecc71,color:white
    classDef database fill:#f1c40f,color:black
    classDef security fill:#e74c3c,color:white
    classDef api fill:#9b59b6,color:white

    %% Frontend Layer
    subgraph Frontend
        Pages["Pages/Routes"]
        Components["Components"]
        
        subgraph Pages
            MainFeed["Main Feed"]
            TopPosts["Top Posts System"]
            ReportedPosts["Reported Posts"]
            UnlockPage["Unlock Page"]
        end

        subgraph Components
            NavBar["Navigation Bar"]
            PostComponents["Post Components"]
            VotingUI["Voting UI"]
            ReportUI["Report UI"]
            Fingerprint["Hidden Fingerprint"]
        end
    end

    %% Server Layer
    subgraph Server
        ServerActions["Server Actions"]
        APIRoutes["API Routes"]

        subgraph ServerActions
            PostManagement["Post Management"]
            VoteAction["Vote Handler"]
            ReportAction["Report Handler"]
        end

        subgraph APIRoutes
            DeleteAPI["Delete API"]
        end
    end

    %% Data Layer
    subgraph Data
        PrismaORM["Prisma ORM"]
        Database[(PostgreSQL)]
    end

    %% Connections
    MainFeed --> PostComponents
    TopPosts --> PostComponents
    ReportedPosts --> PostComponents
    PostComponents --> PostManagement
    VotingUI --> VoteAction
    ReportUI --> ReportAction
    DeleteAPI --> PrismaORM
    ServerActions --> PrismaORM
    PrismaORM --> Database

    %% Click Events
    click MainFeed "https://github.com/stefanluth/kummerkasten/blob/main/app/page.tsx"
    click TopPosts "https://github.com/stefanluth/kummerkasten/tree/main/app/top/"
    click ReportedPosts "https://github.com/stefanluth/kummerkasten/blob/main/app/reported/page.tsx"
    click UnlockPage "https://github.com/stefanluth/kummerkasten/tree/main/app/unlock/"
    click NavBar "https://github.com/stefanluth/kummerkasten/tree/main/app/_components/NavBar/"
    click PostComponents "https://github.com/stefanluth/kummerkasten/tree/main/app/_components/Post/"
    click VotingUI "https://github.com/stefanluth/kummerkasten/blob/main/app/_components/Post/Voting.tsx"
    click ReportUI "https://github.com/stefanluth/kummerkasten/blob/main/app/_components/Post/ReportPost.tsx"
    click Fingerprint "https://github.com/stefanluth/kummerkasten/blob/main/app/_components/HiddenFingerprint.tsx"
    click PostManagement "https://github.com/stefanluth/kummerkasten/tree/main/app/_actions/post/"
    click VoteAction "https://github.com/stefanluth/kummerkasten/blob/main/app/_actions/post/vote.ts"
    click ReportAction "https://github.com/stefanluth/kummerkasten/blob/main/app/_actions/post/report.ts"
    click DeleteAPI "https://github.com/stefanluth/kummerkasten/blob/main/app/[id]/delete/route.ts"
    click PrismaORM "https://github.com/stefanluth/kummerkasten/blob/main/utils/prisma.ts"
    click Database "https://github.com/stefanluth/kummerkasten/blob/main/prisma/schema.prisma"

    %% Style Applications
    class MainFeed,TopPosts,ReportedPosts,UnlockPage,NavBar,PostComponents,VotingUI,ReportUI,Fingerprint frontend
    class ServerActions,PostManagement,VoteAction,ReportAction server
    class Database database
    class DeleteAPI api
    class UnlockPage security

    %% Legend
    subgraph Legend
        Frontend_L["Frontend"]:::frontend
        Server_L["Server"]:::server
        Database_L["Database"]:::database
        Security_L["Security Critical"]:::security
        API_L["API"]:::api
    end
```
