# Frontend Architecture & API Integration

Here, the frontend of our web page is going to be discussed. Please get familiar with VUE.js documentation if you haven't done so yet:

[https://vuejs.org/guide/introduction](https://vuejs.org/guide/introduction)

A RESTful API guide could also be useful:  
[<span style="white-space: pre-wrap;">https://restfulapi.net/ </span>](https://restfulapi.net/%20)

<span style="white-space: pre-wrap;">Our frontend is a </span>**Single Page Application (SPA)**<span style="white-space: pre-wrap;"> built with </span>**Vue.js**. We use a modular structure where every page and component encapsulates its own HTML, CSS, and JavaScript logic.

## 1. Directory Structure &amp; Organization

We separate the code based on its “responsibility” in the app.

<table id="bkmrk-directorypurposesrc%2F" style="margin-bottom: 32px;"><colgroup><col></col><col></col></colgroup><tbody><tr><td style="border: 1px solid;">**Directory**

</td><td style="border: 1px solid;">**Purpose**

</td></tr><tr><td style="border: 1px solid;">**`<strong class="editor-theme-bold editor-theme-code">src/views/</strong>`**

</td><td style="border: 1px solid;"><span style="white-space: pre-wrap;">The main page containers. These are “Smart” components that usually handle data fetching for a whole page (e.g., </span>`<span class="editor-theme-code">HomeView.vue</span>`).

</td></tr><tr><td style="border: 1px solid;">**`<strong class="editor-theme-bold editor-theme-code">src/components/</strong>`**

</td><td style="border: 1px solid;"><span style="white-space: pre-wrap;">Reusable UI sections. These are “Dumb” or “Presentational” components (e.g., </span>`<span class="editor-theme-code">HeroSection.vue</span>`<span style="white-space: pre-wrap;">, </span>`<span class="editor-theme-code">FooterSection.vue</span>`).

</td></tr><tr><td style="border: 1px solid;">**`<strong class="editor-theme-bold editor-theme-code">src/components/admin/</strong>`**

</td><td style="border: 1px solid;">Specialized management modules for the Admin Dashboard. These handle the CRUD logic for news, teams, and members.

</td></tr><tr><td style="border: 1px solid;">**`<strong class="editor-theme-bold editor-theme-code">src/services/</strong>`**

</td><td style="border: 1px solid;">The API layer. All communication with the Spring Boot backend happens here.

</td></tr><tr><td style="border: 1px solid;">**`<strong class="editor-theme-bold editor-theme-code">src/router/</strong>`**

</td><td style="border: 1px solid;">The navigation logic. Maps URLs to specific Views.

</td></tr></tbody></table>

## 2. Routing (Adding New Pages)

```js
// src/router/index.js
const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path: "/",
      name: "home",
      component: HomeView,
    },
    // Add new routes here
  ]
})
```

## 3. Communication with Backend (API Service)

<span style="white-space: pre-wrap;">We </span>**never**<span style="white-space: pre-wrap;"> make direct </span>`<span class="editor-theme-code">fetch</span>`<span style="white-space: pre-wrap;"> or </span>`<span class="editor-theme-code">axios</span>`<span style="white-space: pre-wrap;"> calls inside a </span>`<span class="editor-theme-code">.vue</span>`<span style="white-space: pre-wrap;"> component. Instead, we use a centralized service layer in </span>`<span class="editor-theme-code">src/services/api.js</span>`. This allows us to manage global headers, authentication tokens, and base URLs in one place.

### Step 1: Register the API Endpoint

```js
export const aboutUsAPI = {
  get: () => apiRequest("/organization"),
  update: (id, data) =>
    apiRequest(`/organization/${id}`, {
      method: "PUT",
      body: JSON.stringify(data),
    }),
};
```

### Step 2: Use the API in a Component

```js
import { aboutUsAPI } from '@/services/api';

const fetchOrganization = async () => {
  try {
    const data = await aboutUsAPI.get();
    // Do something with data...
  } catch (err) {
    console.error("API Error:", err);
  }
};
```

## 4. Admin Panel Architecture

<span style="white-space: pre-wrap;">The Admin Panel follows a “Manager” pattern. The </span>`<span class="editor-theme-code">AdminView.vue</span>`<span style="white-space: pre-wrap;"> acts as the main wrapper, while the actual editing tools are found in </span>`<span class="editor-theme-code">src/components/admin/</span>`.

**Managers:**<span style="white-space: pre-wrap;"> Components like </span>`<span class="editor-theme-code">NewsManager.vue</span>`<span style="white-space: pre-wrap;"> or </span>`<span class="editor-theme-code">EventsManager.vue</span>`<span style="white-space: pre-wrap;"> contain the forms and logic needed to edit content.</span>

**Data Flow:**<span style="white-space: pre-wrap;"> Typically, a Manager fetches data on mount, allows the user to edit it, and sends a </span>`<span class="editor-theme-code">PUT</span>`<span style="white-space: pre-wrap;"> or </span>`<span class="editor-theme-code">POST</span>`<span style="white-space: pre-wrap;"> request back through the </span>`<span class="editor-theme-code">services/api.js</span>`<span style="white-space: pre-wrap;"> layer.</span>

## <span style="background-color: rgb(224, 62, 45);">5. TODO: COOKIES, TOKEN BASED SESSIONS</span>