# arkanullahs/booknest architecture

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

- Interactive diagram: https://gitdiagram.com/arkanullahs/booknest
- Repository: https://github.com/arkanullahs/booknest

## Overview

##### Main Components

a. Frontend
- React application (located under the frontend folder).
- Major UI components such as AdminDashboard, PublisherDashboard, UserDashboard, Login/Signup, Navbar, Landing page, etc.
- Client-side routing and interactions with the backend through an API.

b. Backend
- Laravel framework (backend folder) structured using controllers, models, middleware, services, and providers.
- Authentication & Authorization: API endpoints for registration and login, JWT middleware for auth, and role-based middleware (admin, publisher, user).
- API endpoints serve functionalities for book search, order management, user profiles, and publisher functionalities.
- Application configuration (config files), migrations for database setup, and service components (JwtService, TestService).

c. Database
- MySQL as the database (as specified in the README).
- Schema managed via migrations found in the backend/database/migrations folder.

d. External & Supporting Services
- JWT authentication mechanism (via a JWT package installed on the backend).
- Possibly other external services such as payment integrations (not specified but common in e‑commerce) or external APIs.

##### Representing Relationships and Interactions

a. Frontend ⇄ Backend Communication
- Clearly label API endpoints (for authentication, profile management, book searches, order creation, etc.) as defined in the README.

b. Backend Internal Structure
- Within the backend, show a separation of layers:
- Controllers – handling HTTP requests (e.g., AuthController, TestController).
- Middleware – securing routes with JWT and role-based access (e.g., JwtMiddleware, RoleMiddleware).
- Services – encapsulating business logic (e.g., JwtService, TestService).
- Models – representing database entities (e.g., User model).
- Providers & configuration – bootstrapping and managing application initialization.

c. Database Connectivity

##### Architectural Patterns and Design Principles

a. Separation of Concerns:
- Clearly delimit the frontend (view) from backend (API/business logic and persistence).
- In the backend, isolate authentication, business logic, and infrastructure (database) into separate modules.

b. RESTful API:

c. Middleware for Security:
- JWT authentication mechanism and role-based middleware as key security features.

d. Modular and Scalable:
- How both the frontend (with individual React components for dashboards, pages, etc.) and backend (with different controllers/services) are built to be extensible as new features or microservices are added.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Layer
    subgraph "Frontend Layer"
        FE1["React Frontend (CSR)"]:::frontend
        FE2["Navbar"]:::frontend
        FE3["Landing Page"]:::frontend
        FE4["Login Component"]:::frontend
        FE5["Signup Component"]:::frontend
        FE6["Admin Dashboard"]:::frontend
        FE7["Publisher Dashboard"]:::frontend
        FE8["User Dashboard"]:::frontend
    end

    %% Backend Layer
    subgraph "Backend Layer"
        BE1["Laravel Backend"]:::backend
        subgraph "Controllers"
            C1["Auth Controller"]:::controller
            C2["Test Controller"]:::controller
        end
        subgraph "Middleware"
            MW1["JWT Middleware"]:::middleware
            MW2["Role Middleware"]:::middleware
        end
        subgraph "Services"
            S1["JWT Service"]:::backend
            S2["Test Service"]:::backend
        end
        subgraph "Models"
            M1["User Model"]:::backend
        end
        R["API Routes"]:::backend
    end

    %% Database Component
    DB["MySQL Database"]:::database

    %% Connections between Frontend and Backend
    FE1 -->|"REST_API_Calls"| R

    %% Backend internal flow
    R -->|"routes_to"| C1
    R -->|"routes_to"| C2
    C1 -->|"secured_by"| MW1
    C1 -->|"secured_by"| MW2
    C2 -->|"secured_by"| MW1
    C2 -->|"secured_by"| MW2
    MW1 -->|"calls"| S1
    MW1 -->|"calls"| S2
    MW2 -->|"calls"| S1
    S1 -->|"manipulates"| M1
    S2 -->|"manipulates"| M1
    M1 -->|"data_access"| DB

    %% Click Events for Frontend Components
    click FE1 "https://github.com/arkanullahs/booknest/tree/master/frontend/"
    click FE2 "https://github.com/arkanullahs/booknest/blob/master/frontend/src/components/navbar.jsx"
    click FE3 "https://github.com/arkanullahs/booknest/blob/master/frontend/src/components/landingpage.jsx"
    click FE4 "https://github.com/arkanullahs/booknest/blob/master/frontend/src/components/login.jsx"
    click FE5 "https://github.com/arkanullahs/booknest/blob/master/frontend/src/components/signup.jsx"
    click FE6 "https://github.com/arkanullahs/booknest/blob/master/frontend/src/components/AdminDashboard.jsx"
    click FE7 "https://github.com/arkanullahs/booknest/blob/master/frontend/src/components/PublisherDashboard.jsx"
    click FE8 "https://github.com/arkanullahs/booknest/blob/master/frontend/src/components/UserDashboard.jsx"

    %% Click Events for Backend Components
    click BE1 "https://github.com/arkanullahs/booknest/tree/master/backend/"
    click C1 "https://github.com/arkanullahs/booknest/blob/master/backend/app/Http/Controllers/AuthController.php"
    click C2 "https://github.com/arkanullahs/booknest/blob/master/backend/app/Http/Controllers/TestController.php"
    click MW1 "https://github.com/arkanullahs/booknest/blob/master/backend/app/Http/Middleware/JwtMiddleware.php"
    click MW2 "https://github.com/arkanullahs/booknest/blob/master/backend/app/Http/Middleware/RoleMiddleware.php"
    click S1 "https://github.com/arkanullahs/booknest/blob/master/backend/app/Services/JwtService.php"
    click S2 "https://github.com/arkanullahs/booknest/blob/master/backend/app/Services/TestService.php"
    click M1 "https://github.com/arkanullahs/booknest/blob/master/backend/app/Models/User.php"
    click R "https://github.com/arkanullahs/booknest/blob/master/backend/routes/api.php"

    %% Click Event for Database Migrations
    click DB "https://github.com/arkanullahs/booknest/tree/master/backend/database/migrations"

    %% Styles
    classDef frontend fill:#ffe0ee,stroke:#ff66b3,stroke-width:2px;
    classDef backend fill:#e0f7ff,stroke:#33aaff,stroke-width:2px;
    classDef controller fill:#fff0f5,stroke:#ff1493,stroke-width:2px;
    classDef middleware fill:#fffacd,stroke:#daa520,stroke-width:2px;
    classDef database fill:#e0ffe0,stroke:#32cd32,stroke-width:2px;
```
