# towa1204/nhk-plus-board architecture

> Architecture diagram of the GitHub repository towa1204/nhk-plus-board, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-03-29). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/towa1204/nhk-plus-board
- Repository: https://github.com/towa1204/nhk-plus-board

## Overview

##### Main components
- Frontend Presentation Layer:
- "routes" directory: This includes pages, middleware ( _middleware.ts ), error pages (_404.tsx, _500.tsx ), and layout definitions (_layout.tsx & _app.tsx).
- "components" directory: Basic UI components like Button, HomeButton, ProgramCard, etc.
- "islands" directory: Interactive parts of the UI that provide client-side interactivity, such as ProgramForm and ProgramInput.
- "static" files: Styling resources (styles.css) and configuration for Tailwind.

- Backend / Business Logic Layer:
- "backend" directory: Contains domain logic split into several layers:
▪ "client": Handles external API integrations (e.g., LineClient, NhkPlusClient, relevant tests, and API type declarations).
▪ "common": Utility functions, custom exceptions, and common types that support the whole backend.
▪ "repository": Data persistence or storage related logic (e.g., AppSettingRepository, WatchProgramKeysRepository) likely simulating a persistence layer.
▪ "service": Business logic encapsulating application flows (e.g., AppSettingService, MainFlowService, NhkPlusProgramService) with corresponding tests.
- "backend/testdata": Sample JSON files for testing configurations and search result outputs.

- Infrastructure and Configuration:
- Deployment and environment: Files such as .env.example, GitHub workflows, and config files (deno.json, fresh.config.ts, tailwind.config.ts) that manage deployment, environment variables, and project configurations.
- Main entry points like dev.ts, main.ts, and cron.ts represent scheduled tasks and bootstrapping of the server.

##### Relationships and interactions
- The Fresh framework serves as the glue for the UI and server, using the "routes" and "islands" directories to inject dynamic content into the HTML.
- The routes (controller layer) are responsible for interacting with the backend services. When a route is triggered, it can call a service from the "backend/service" layer to perform application logic.
- The service layer communicates with repository classes to fetch or update data, while also potentially interacting with external APIs via clients in "backend/client".
- Utility and common functions in "backend/common" are accessed by multiple parts of the backend (service, repository, etc.) to manage shared concerns like date formatting, exception handling, or key-value utilities.
- The infrastructure components (GitHub workflows, config files) support continuous integration/deployment, environment configuration, and static asset management.

##### Architectural patterns in use
- MVC-like pattern: The routes act as controllers and views, while the backend organizes business logic (models, services, repositories).
- Separation of concerns: Clear boundaries among presentation (routes, islands, components), business logic (services), data access (repositories) and infrastructure (external client integrations).
- Testing layers: Test files exist for client, common utilities, and services, highlighting a test-driven development approach.

- From user request at the Frontend (routes) flowing into the Backend.
- From the service layer to the repository and vice versa.
- UI components (e.g., rectangles for routes, circles for interactive islands).
- Additionally, include any supporting tools or configurations (like GitHub actions as part of CI/CD) in an “Infrastructure” section.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Frontend Presentation Layer"
        FRoutes("Routes") 
        FComponents("Components") 
        FIslands("Islands") 
        FStatic("Static Assets") 
        FTailwind("Tailwind Config")
    end

    subgraph "Backend / Business Logic Layer"
        BClient("API Clients") 
        BCommon("Common Utilities") 
        BRepository("Repositories") 
        BService("Services") 
        BTestData("Test Data")
    end

    subgraph "Infrastructure and Configuration"
        IEnv("Deployment & Environment Files") 
        IEntry("Main Entry Points")
    end

    %% Interactions
    FRoutes -->|"calls"| BService
    BService -->|"uses"| BRepository
    BService -->|"calls"| BClient
    BService -->|"utilizes"| BCommon
    BRepository -->|"uses"| BCommon

    %% Optional internal UI relations (for interactive behavior)
    FRoutes -.->|"renders"| FIslands
    FRoutes -.->|"composes"| FComponents
    FComponents --- FStatic
    FStatic --- FTailwind

    %% Styling classes
    class FRoutes,FComponents,FIslands,FStatic,FTailwind frontend
    class BClient,BCommon,BRepository,BService,BTestData backend
    class IEnv,IEntry infrastructure

    %% Class definitions with colours
    classDef frontend fill:#A8DADC,stroke:#457B9D,stroke-width:2px;
    classDef backend fill:#F4A261,stroke:#E76F51,stroke-width:2px;
    classDef infrastructure fill:#E9C46A,stroke:#2A9D8F,stroke-width:2px;

    %% Click Events
    click FRoutes "https://github.com/towa1204/nhk-plus-board/tree/develop/routes/"
    click FComponents "https://github.com/towa1204/nhk-plus-board/tree/develop/components/"
    click FIslands "https://github.com/towa1204/nhk-plus-board/tree/develop/islands/"
    click FStatic "https://github.com/towa1204/nhk-plus-board/blob/develop/static/styles.css"
    click FTailwind "https://github.com/towa1204/nhk-plus-board/blob/develop/tailwind.config.ts"
    click BClient "https://github.com/towa1204/nhk-plus-board/tree/develop/backend/client/"
    click BCommon "https://github.com/towa1204/nhk-plus-board/tree/develop/backend/common/"
    click BRepository "https://github.com/towa1204/nhk-plus-board/tree/develop/backend/repository/"
    click BService "https://github.com/towa1204/nhk-plus-board/tree/develop/backend/service/"
    click BTestData "https://github.com/towa1204/nhk-plus-board/tree/develop/backend/testdata/"
    click IEnv "https://github.com/towa1204/nhk-plus-board/blob/develop/.env.example"
    click IEntry "https://github.com/towa1204/nhk-plus-board/blob/develop/dev.ts"
```
