# khoubaib-boughalmi/1337-library architecture

> Architecture diagram of the GitHub repository khoubaib-boughalmi/1337-library, 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/khoubaib-boughalmi/1337-library
- Repository: https://github.com/khoubaib-boughalmi/1337-library

## Overview

##### Main Components

A. Frontend Layer (Next.js + TypeScript):
- Public Pages (index, home, profile)
- Staff Pages (booking-log, books, reservations, users)
- Shared Components (BookCard, AddBook, DateRangePicker)
- Authentication Interface (42 OAuth)

B. Backend Layer (Express.js):
- API Routes (books, reservations, users, 42auth)
- Middleware Layer (authorization, syslog)
- Database Schemas (Books, BookRequests, Users)

C. Database Layer:
- A MongoDB container showing the three main collections:
- Users Collection
- Books Collection
- BookRequests Collection

##### Component Relationships

- Frontend → 42 Authentication: OAuth flow
- Frontend → Backend API: REST API calls
- Backend → MongoDB: Database operations
- Middleware → All Routes: Authentication checks

##### Specific Implementation Details

A. Authentication Flow:
**Client → 42 OAuth → Backend Auth Route → User Session**

B. Data Flow:
**Frontend Components → API Routes → Database Operations → Response**

##### Important Elements

A. Security Layer:
- Authorization middleware protecting routes
- 42 authentication integration points

B. User Interfaces:
- Distinguish between student and staff interfaces
- Separation of concerns in the routing structure

**[42 OAuth Service]**
- ↕
**[Frontend Layer]**
- Public Interface
- Staff Interface
- Shared Components
- ↕
**[Backend Layer]**
- API Routes
- Middleware
- Database Schemas
- ↕
**[MongoDB Database]**

##### Technical Stack Indicators

Technology badges or labels for:
- TypeScript
- Next.js
- Express.js
- MongoDB
- EJS
- TailwindCSS (noted from config files)

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph External
        OAuth[42 OAuth Service]:::external
    end

    subgraph Frontend
        direction TB
        FE[Next.js Frontend]:::frontend
        
        subgraph PublicPages
            direction TB
            Index["Index Page"]:::frontend
            Home["Home Page"]:::frontend
            Profile["Profile Page"]:::frontend
        end

        subgraph StaffPages
            direction TB
            Staff["Staff Interface"]:::frontend
        end

        subgraph SharedComponents
            direction TB
            BookCard["Book Card"]:::frontend
            AddBook["Add Book"]:::frontend
            DatePicker["Date Range Picker"]:::frontend
        end

        App["App Entry"]:::frontend
    end

    subgraph Backend
        direction TB
        BE[Express Backend]:::backend
        AppEntry["App Entry"]:::backend

        subgraph APIRoutes
            direction TB
            AuthRoute["42 Auth Route"]:::api
            BookRoute["Books Route"]:::api
            ReservRoute["Reservations Route"]:::api
            UserRoute["Users Route"]:::api
        end

        subgraph Middleware
            direction TB
            AuthMW["Authorization"]:::middleware
            LogMW["System Logger"]:::middleware
        end

        subgraph Schemas
            direction TB
            BookSchema["Books Schema"]:::schema
            RequestSchema["Book Requests Schema"]:::schema
            UserSchema["Users Schema"]:::schema
        end

        DBConn["Database Connection"]:::backend
    end

    subgraph Database
        direction TB
        MongoDB[(MongoDB)]:::database
        Users[(Users Collection)]:::database
        Books[(Books Collection)]:::database
        Requests[(Book Requests Collection)]:::database
    end

    %% Relationships
    OAuth <--> FE
    FE --> BE
    BE --> MongoDB
    Middleware --> APIRoutes
    DBConn --> MongoDB

    %% Click Events
    click Index "https://github.com/Khoubaib-Boughalmi/1337-library/blob/main/frontend/pages/index.tsx"
    click Home "https://github.com/Khoubaib-Boughalmi/1337-library/blob/main/frontend/pages/home.tsx"
    click Profile "https://github.com/Khoubaib-Boughalmi/1337-library/blob/main/frontend/pages/profile.tsx"
    click Staff "https://github.com/Khoubaib-Boughalmi/1337-library/tree/main/frontend/pages/staff/"
    click BookCard "https://github.com/Khoubaib-Boughalmi/1337-library/blob/main/frontend/components/BookCard.tsx"
    click AddBook "https://github.com/Khoubaib-Boughalmi/1337-library/blob/main/frontend/components/AddBook.tsx"
    click DatePicker "https://github.com/Khoubaib-Boughalmi/1337-library/blob/main/frontend/components/DateRangePicker.tsx"
    click AuthRoute "https://github.com/Khoubaib-Boughalmi/1337-library/blob/main/backend/routes/42auth.js"
    click BookRoute "https://github.com/Khoubaib-Boughalmi/1337-library/blob/main/backend/routes/book.js"
    click ReservRoute "https://github.com/Khoubaib-Boughalmi/1337-library/blob/main/backend/routes/reservations.js"
    click UserRoute "https://github.com/Khoubaib-Boughalmi/1337-library/blob/main/backend/routes/user.js"
    click AuthMW "https://github.com/Khoubaib-Boughalmi/1337-library/blob/main/backend/middlewares/authorization.js"
    click LogMW "https://github.com/Khoubaib-Boughalmi/1337-library/blob/main/backend/middlewares/syslog.js"
    click BookSchema "https://github.com/Khoubaib-Boughalmi/1337-library/blob/main/backend/db/Schemas/BooksSchema.js"
    click RequestSchema "https://github.com/Khoubaib-Boughalmi/1337-library/blob/main/backend/db/Schemas/BookRequestsSchema.js"
    click UserSchema "https://github.com/Khoubaib-Boughalmi/1337-library/blob/main/backend/db/Schemas/UserSchema.js"
    click DBConn "https://github.com/Khoubaib-Boughalmi/1337-library/blob/main/backend/db/db.js"
    click App "https://github.com/Khoubaib-Boughalmi/1337-library/blob/main/frontend/pages/_app.tsx"
    click AppEntry "https://github.com/Khoubaib-Boughalmi/1337-library/blob/main/backend/app.js"

    %% Styling
    classDef frontend fill:#2196F3,color:white
    classDef backend fill:#4CAF50,color:white
    classDef database fill:#FFC107,color:black
    classDef api fill:#9C27B0,color:white
    classDef middleware fill:#FF5722,color:white
    classDef schema fill:#607D8B,color:white
    classDef external fill:#9E9E9E,color:white

    %% Legend
    subgraph Legend
        Frontend[Frontend Component]:::frontend
        Backend[Backend Service]:::backend
        DB[Database]:::database
        API[API Route]:::api
        MW[Middleware]:::middleware
        Schema[Schema]:::schema
        Ext[External Service]:::external
    end
```
