# ah-ae/what-are-you-reading architecture

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

- Interactive diagram: https://gitdiagram.com/ah-ae/what-are-you-reading
- Repository: https://github.com/ah-ae/what-are-you-reading

## Overview

##### High-Level Architecture Components

a) Frontend Layer:
- Next.js App Router Architecture (indicated by the app directory structure)
- Client-side Components (UI components in app/ui)
- Server Components (pages and layouts)
- State Management (using atoms as seen in app/store)

b) Backend Layer:
- API Routes (seen in route.ts files)
- Authentication System (app/(auth) directory)
- Database Layer (Prisma ORM, indicated by prisma directory)

c) External Services:
- Kakao OAuth Integration (visible in app/(auth)/kakao)

##### Component Organization

**[Client Layer]**

- Public Routes
- Authentication Routes (/login, /signup)
- Kakao OAuth Routes

- Protected Routes
- Bookshelf Routes (/mine, /yours)
- Book Management (/books/add)
- Settings (/settings)

**[Application Layer]**

- State Management (Recoil atoms)
- Server Actions (*.actions.ts)
- Middleware (middleware.ts)

**[Data Layer]**

- Prisma ORM
- Database (defined in schema.prisma)

##### Key Interactions to Highlight

- Authentication flow with Kakao OAuth
- Data flow between client components and server actions
- Database interactions through Prisma
- State management flow with Recoil atoms

##### Component Details

Specific elements:
- UI Components (app/ui/*)
- Shared Layouts (app/layout.tsx)
- Authentication Guards (middleware.ts)
- Database Schema (prisma/schema.prisma)
- State Management (app/store/atoms.ts)

##### Additional Notes

- The separation between client and server components
- The role of server actions in data mutations
- The integration with external authentication
- The modular structure of the UI components
- The relationship between routes and their corresponding actions

Remember to:
- Use consistent symbols throughout
- Flow of data between components
- Which parts are server-side vs client-side

This architecture represents a modern Next.js application with a focus on server components, type safety (TypeScript), and a clear separation of concerns between UI, business logic, and data access layers.

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Client
        UI[UI Layer]
        RC[Route Components]
        SP["Store Provider"]:::state
        click SP "https://github.com/Ah-ae/what-are-you-reading/blob/main/app/store/store-provider.tsx"
    end

    subgraph Auth["Authentication Layer"]
        direction TB
        AM["Auth Middleware"]:::auth
        click AM "https://github.com/Ah-ae/what-are-you-reading/blob/main/middleware.ts"
        KO["Kakao OAuth"]:::auth
        click KO "https://github.com/Ah-ae/what-are-you-reading/tree/main/app/(auth)/kakao"
        LA["Login Actions"]:::auth
        click LA "https://github.com/Ah-ae/what-are-you-reading/blob/main/app/(auth)/login/actions.ts"
        SA["Signup Actions"]:::auth
        click SA "https://github.com/Ah-ae/what-are-you-reading/blob/main/app/(auth)/signup/actions.ts"
        AU["Auth Utils"]:::auth
        click AU "https://github.com/Ah-ae/what-are-you-reading/blob/main/app/utils/auth.ts"
    end

    subgraph Components["UI Components"]
        direction TB
        BC["Book Components"]:::ui
        click BC "https://github.com/Ah-ae/what-are-you-reading/tree/main/app/ui/books"
        BSC["Bookshelf Components"]:::ui
        click BSC "https://github.com/Ah-ae/what-are-you-reading/tree/main/app/ui/bookshelf"
        MC["Modal Components"]:::ui
        click MC "https://github.com/Ah-ae/what-are-you-reading/tree/main/app/ui/modals"
        NAV["Navigation"]:::ui
        click NAV "https://github.com/Ah-ae/what-are-you-reading/tree/main/app/ui/nav"
    end

    subgraph Features["Core Features"]
        direction TB
        BM["Book Management"]:::feature
        click BM "https://github.com/Ah-ae/what-are-you-reading/tree/main/app/books"
        BSM["Bookshelf Management"]:::feature
        click BSM "https://github.com/Ah-ae/what-are-you-reading/tree/main/app/(bookshelf)"
        SET["Settings"]:::feature
        click SET "https://github.com/Ah-ae/what-are-you-reading/tree/main/app/(bookshelf)/settings"
    end

    subgraph Data["Data Layer"]
        direction TB
        PS["Prisma Schema"]:::data
        click PS "https://github.com/Ah-ae/what-are-you-reading/blob/main/prisma/schema.prisma"
        DU["Database Utils"]:::data
        click DU "https://github.com/Ah-ae/what-are-you-reading/blob/main/app/lib/db.ts"
        DA["Data Access"]:::data
        click DA "https://github.com/Ah-ae/what-are-you-reading/blob/main/app/lib/data.ts"
    end

    subgraph State["State Management"]
        direction TB
        AT["Atoms"]:::state
        click AT "https://github.com/Ah-ae/what-are-you-reading/blob/main/app/store/atoms.ts"
        SM["Session Management"]:::state
        click SM "https://github.com/Ah-ae/what-are-you-reading/blob/main/app/lib/session.ts"
    end

    UI --> Components
    RC --> Features
    SP --> State
    
    Features --> LA
    Features --> SA
    Features --> Data
    
    Auth --> Data
    KO --> AU
    AM --> AU
    AU --> SM
    
    Data --> PS
    Data --> DU
    Data --> DA

    classDef ui fill:#2563eb,color:white
    classDef auth fill:#16a34a,color:white
    classDef data fill:#ea580c,color:white
    classDef state fill:#9333ea,color:white
    classDef feature fill:#0284c7,color:white

    %% Legend
    subgraph Legend
        UI_L["UI Components"]:::ui
        AUTH_L["Authentication"]:::auth
        DATA_L["Data Layer"]:::data
        STATE_L["State Management"]:::state
        FEATURE_L["Core Features"]:::feature
    end
```
