# kth/kursinfo-admin-web architecture

> Architecture diagram of the GitHub repository kth/kursinfo-admin-web, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2024-12-28). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/kth/kursinfo-admin-web
- Repository: https://github.com/kth/kursinfo-admin-web

## Overview

##### System Overview
The project is a microservice-based web application that serves as an administration tool for teachers to manage course information at KTH. Here's how to structure the main components:

##### Main Components

a. Frontend Layer:
- React-based SPA (located in /public/js/app)
- Key pages: AdminStartPage, CourseEditStartPage, DescriptionPage
- Shared components and context providers
- CKEditor integration for rich text editing

b. Backend Layer:
- Node.js Express server (in /server)
- Controller layer (/server/controllers)
- API integration layer (/server/apiCalls)
- Server-side rendering support (/server/ssr-context)

c. External Services:
- KOPPS-API (course information source)
- kursinfo-api (course data storage)
- Azure Blob Storage (image storage)
- Redis (caching layer)

**[Client Layer]**
- ↕️
**[Application Layer]**
- ↕️
**[External Services Layer]**

##### Detailed Component Representation

Client Layer:
**┌─ React Frontend ─────────────────┐**
- Admin Dashboard               │
- Course Editor                 │
- Image Management             │
- CKEditor Integration         │
- ┘

Application Layer:
**┌─ Express Server ──────────────┐**
- ┌─ Controllers ─────────────┐ │
- Admin Pages            │ │
- Description           │ │
- Image                 │ │
- ┘ │
- ┌─ API Integration ───────┐ │
- KOPPS API Client     │ │
- KursInfo API Client  │ │
- ┘ │
- ┘

External Services Layer:
**┌─ Storage ─────┐  ┌─ APIs ──────┐  ┌─ Cache ────┐**
- Azure Blob    │  │ KOPPS API   │  │ Redis      │
- Storage       │  │ KursInfo API│  │            │
- ┘  └────────────┘  └────────────┘

##### Important Flows to Highlight

a. Authentication Flow:
- How user roles (coordinators/examiners) affect access

b. Data Flows:
- Course information retrieval from KOPPS-API
- Image upload to Azure Blob Storage
- Cache interaction for frequently accessed data

c. API Interactions:
- Bidirectional communication with kursinfo-api
- Cached vs direct KOPPS-API calls

##### Additional Elements

- Component types
- Authentication boundaries
- Caching mechanisms

##### Technical Details to Note
- Node.js 18 runtime
- Server-side rendering capability
- Redis caching for KOPPS-API responses
- Azure Blob Storage for image management
- Handlebars templating for views
- React for client-side interactivity

Remember to indicate the development, reference, and production environments as they have different configurations (as evidenced by the .azure directory structure).

This system design should help developers understand both the high-level architecture and the specific implementation details of the kursinfo-admin-web service.

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph Client
        ReactApp["React Frontend"]
        AdminDash["Admin Dashboard"]
        CourseEdit["Course Editor"]
        DescPage["Description Page"]
        CKEdit["CKEditor Integration"]
        FrontComps["Frontend Components"]
        
        ReactApp --> AdminDash
        ReactApp --> CourseEdit
        ReactApp --> DescPage
        ReactApp --> CKEdit
        ReactApp --> FrontComps
    end

    subgraph Server
        Express["Express Server"]
        Controllers["Controllers Layer"]
        Routes["Main Routes"]
        ImgCtrl["Image Controller"]
        SSR["Server-Side Rendering"]
        Views["View Templates"]
        
        Express --> Controllers
        Controllers --> Routes
        Controllers --> ImgCtrl
        Express --> SSR
        Express --> Views
    end

    subgraph "API Integration"
        KoppsClient["KOPPS API Client"]
        KursInfoClient["KursInfo API Client"]
        BlobStorage["Azure Blob Storage"]
    end

    subgraph "External Services"
        KoppsAPI["KOPPS API"]
        KursInfoAPI["KursInfo API"]
        Azure["Azure Storage"]
        Redis["Redis Cache"]
    end

    %% Client to Server connections
    ReactApp --> Express
    
    %% Server to Integration connections
    Controllers --> KoppsClient
    Controllers --> KursInfoClient
    ImgCtrl --> BlobStorage
    
    %% Integration to External connections
    KoppsClient --> KoppsAPI
    KursInfoClient --> KursInfoAPI
    BlobStorage --> Azure
    KoppsClient --> Redis
    
    %% Styling
    classDef frontend fill:#3498db,stroke:#2980b9,color:white
    classDef backend fill:#2ecc71,stroke:#27ae60,color:white
    classDef api fill:#f1c40f,stroke:#f39c12,color:black
    classDef storage fill:#9b59b6,stroke:#8e44ad,color:white
    classDef cache fill:#e67e22,stroke:#d35400,color:white
    
    class ReactApp,AdminDash,CourseEdit,DescPage,CKEdit,FrontComps frontend
    class Express,Controllers,Routes,ImgCtrl,SSR,Views backend
    class KoppsClient,KursInfoClient,KoppsAPI,KursInfoAPI api
    class BlobStorage,Azure storage
    class Redis cache

    %% Click events
    click ReactApp "https://github.com/KTH/kursinfo-admin-web/blob/master/public/js/app/app.jsx"
    click AdminDash "https://github.com/KTH/kursinfo-admin-web/blob/master/public/js/app/pages/AdminStartPage.jsx"
    click CourseEdit "https://github.com/KTH/kursinfo-admin-web/blob/master/public/js/app/pages/CourseEditStartPage.jsx"
    click DescPage "https://github.com/KTH/kursinfo-admin-web/blob/master/public/js/app/pages/DescriptionPage/DescriptionPage.jsx"
    click CKEdit "https://github.com/KTH/kursinfo-admin-web/blob/master/public/js/app/components/Editor/EditorSection.jsx"
    click Express "https://github.com/KTH/kursinfo-admin-web/blob/master/server/server.js"
    click Controllers "https://github.com/KTH/kursinfo-admin-web/tree/master/server/controllers/"
    click KoppsClient "https://github.com/KTH/kursinfo-admin-web/blob/master/server/apiCalls/koppsApi.js"
    click KursInfoClient "https://github.com/KTH/kursinfo-admin-web/blob/master/server/apiCalls/kursInfoApi.js"
    click BlobStorage "https://github.com/KTH/kursinfo-admin-web/blob/master/server/blobStorage.js"
    click SSR "https://github.com/KTH/kursinfo-admin-web/blob/master/server/ssr-context/createServerSideContext.js"
    click Routes "https://github.com/KTH/kursinfo-admin-web/blob/master/server/controllers/index.js"
    click ImgCtrl "https://github.com/KTH/kursinfo-admin-web/blob/master/server/controllers/imageCtrl.js"
    click FrontComps "https://github.com/KTH/kursinfo-admin-web/tree/master/public/js/app/components/"
    click Views "https://github.com/KTH/kursinfo-admin-web/tree/master/server/views/"
```
