# aathithiya-d/bookstagram architecture

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

- Interactive diagram: https://gitdiagram.com/aathithiya-d/bookstagram
- Repository: https://github.com/aathithiya-d/bookstagram

## Overview

##### Main Architectural Layers
- User-facing layer: React_Frontend
- Edge layer: API Gateway (apigateway)
- Service Discovery: Naming Server (namingserver)
- Microservices layer:
- Core monolith or composite service (Spring_Backend)
- Dedicated microservice for books (ms)
- Data layer: MySQL database(s)

##### Out Components and Responsibilities
a. React_Frontend
- Components: pages, admin & user UI, data fetching via axios/User.js
- Static assets: public/
- State & routing: react-router + Tailwind CSS

b. Naming Server (Eureka style)
- Registers all services at startup
- Enables service lookup by API Gateway and other services

c. API Gateway
- Single entry point for all client requests
- Routes to AuthenticationController, BookController, ChatController, etc., in Spring_Backend or to /ms endpoints
- Applies cross-cutting concerns: CORS, rate limiting, auth token forwarding

d. Core Backend Service (Spring_Backend)
- Handles user accounts, authentication (JWT), profiles, chat, communities, reviews, bookshelves
- Layers inside:
- Controllers (AuthenticationController, UserController, …)
- Services + impl (AuthServiceImpl, UserServiceImpl, …)
- Repositories (JpaRepository interfaces)
- DTOs, Models, Util (JwtUtil)
- Reads configuration (application.properties), connects to MySQL

e. Book Microservice (ms)
- Single responsibility: book catalog, inventory counts
- Own controllers, services, repos
- Independent deployment, own database schema or shared MySQL

f. Database(s)
- A single or multiple MySQL instances
- Schema separation per service (Spring_Backend vs. ms)

##### Interactions & Data Flows
- User’s browser → React_Frontend
- React HTTP calls → API Gateway (routes on /api/auth, /api/books, /ms/books, etc.)
- API Gateway → Service Discovery → appropriate service instance
- Services → read/write to MySQL
- Services communicate internally if needed (e.g., Spring_Backend calls ms for book details) via REST

##### Architectural Patterns
- Microservices with Service Discovery (Eureka style)
- API Gateway pattern for request routing and edge security
- Layered backend: Controller → Service → Repository
- JWT-based stateless authentication
- React single-page application as client

##### Detailed Elements to Capture
- React components → Axios calls to /api endpoints
- JWT token flow: login → receive token → attach to subsequent requests
- Discovery registration on service startup
- Gateway routing table (e.g., /auth → Spring_Backend, /ms/books → ms)
- Communication paths for chat and community features

Putting It All Together
[Browser: React_Frontend]
↓ HTTPS
[API Gateway] ←→ [Naming Server]
↓         ↓
┌────────────┐┌─────────────┐
│ Spring_    ││ BookService │
│ Backend    ││ (ms)        │
└────────────┘└─────────────┘
↓               ↓
[MySQL Database(s)]

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% User-facing Layer
    subgraph "User-facing Layer"
        direction TB
        Browser["Browser\n(React Frontend)"]:::ui
        ReactFrontend["React Frontend"]:::ui
        StaticAssets["Static Assets (public/)"]:::ui
        DataFetching["Data Fetching\n(axios/User.js)"]:::ui
        Pages["UI Pages & Routing"]:::ui
        AdminComponents["Admin Components"]:::ui
    end

    %% Edge Layer
    subgraph "Edge Layer"
        direction TB
        APIGateway["API Gateway"]:::gateway
        NamingServer["Naming Server\n(Service Discovery)"]:::gateway
    end

    %% Backend Services Layer
    subgraph "Backend Services"
        direction TB
        SpringBackend["Core Backend Service\n(Spring_Backend)"]:::backend
        MSBookService["Book Microservice\n(ms)"]:::backend
    end

    %% Data Layer
    DB["MySQL Database(s)"]:::db

    %% Connections
    Browser -->|"HTTPS Request"| APIGateway
    APIGateway -->|"Service Lookup"| NamingServer
    NamingServer -->|"Service Registration"| APIGateway
    APIGateway -->|"Route /api/*"| SpringBackend
    APIGateway -->|"Route /ms/books"| MSBookService
    SpringBackend -->|"Reads/Writes"| DB
    MSBookService -->|"Reads/Writes"| DB

    %% Click Events
    click ReactFrontend "https://github.com/aathithiya-d/bookstagram/tree/main/React_Frontend/"
    click StaticAssets "https://github.com/aathithiya-d/bookstagram/tree/main/React_Frontend/public/"
    click DataFetching "https://github.com/aathithiya-d/bookstagram/blob/main/React_Frontend/src/axios/User.js"
    click Pages "https://github.com/aathithiya-d/bookstagram/tree/main/React_Frontend/src/pages/"
    click AdminComponents "https://github.com/aathithiya-d/bookstagram/tree/main/React_Frontend/src/AdminComponents/"
    click APIGateway "https://github.com/aathithiya-d/bookstagram/tree/main/apigateway/"
    click NamingServer "https://github.com/aathithiya-d/bookstagram/tree/main/namingserver/"
    click SpringBackend "https://github.com/aathithiya-d/bookstagram/tree/main/Spring_Backend/src/main/java/com/app/bookstagram/controller/"
    click SpringBackend "https://github.com/aathithiya-d/bookstagram/tree/main/Spring_Backend/src/main/java/com/app/bookstagram/service/"
    click SpringBackend "https://github.com/aathithiya-d/bookstagram/tree/main/Spring_Backend/src/main/java/com/app/bookstagram/service/impl/"
    click SpringBackend "https://github.com/aathithiya-d/bookstagram/tree/main/Spring_Backend/src/main/java/com/app/bookstagram/repository/"
    click SpringBackend "https://github.com/aathithiya-d/bookstagram/tree/main/Spring_Backend/src/main/java/com/app/bookstagram/dto/"
    click SpringBackend "https://github.com/aathithiya-d/bookstagram/tree/main/Spring_Backend/src/main/java/com/app/bookstagram/model/"
    click SpringBackend "https://github.com/aathithiya-d/bookstagram/blob/main/Spring_Backend/src/main/java/com/app/bookstagram/util/JwtUtil.java"
    click SpringBackend "https://github.com/aathithiya-d/bookstagram/tree/main/Spring_Backend/src/main/java/com/app/bookstagram/config/"
    click SpringBackend "https://github.com/aathithiya-d/bookstagram/blob/main/Spring_Backend/src/main/resources/application.properties"
    click MSBookService "https://github.com/aathithiya-d/bookstagram/blob/main/ms/src/main/java/com/app/ms/controller/BookController.java"
    click MSBookService "https://github.com/aathithiya-d/bookstagram/tree/main/ms/src/main/java/com/app/ms/service/"
    click MSBookService "https://github.com/aathithiya-d/bookstagram/tree/main/ms/src/main/java/com/app/ms/service/impl/"
    click MSBookService "https://github.com/aathithiya-d/bookstagram/blob/main/ms/src/main/java/com/app/ms/repository/BookRepository.java"
    click MSBookService "https://github.com/aathithiya-d/bookstagram/tree/main/ms/src/main/java/com/app/ms/dto/"
    click MSBookService "https://github.com/aathithiya-d/bookstagram/blob/main/ms/src/main/java/com/app/ms/model/Book.java"
    click MSBookService "https://github.com/aathithiya-d/bookstagram/blob/main/ms/src/main/resources/application.properties"

    %% Styles
    classDef ui fill:#D0E8FF,stroke:#0284C7,color:#000
    classDef gateway fill:#D1FAE5,stroke:#10B981,color:#000
    classDef backend fill:#FEF3C7,stroke:#F59E0B,color:#000
    classDef db fill:#E5E7EB,stroke:#6B7280,color:#000
```
