# tietokilta/web architecture

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

- Interactive diagram: https://gitdiagram.com/tietokilta/web
- Repository: https://github.com/tietokilta/web

## Overview

##### Main Components

a. Frontend Layer:
- Next.js Web Application (@tietokilta/web)
- Client-side components
- Server-side components
- API routes
- Internationalization system

b. CMS Layer:
- Payload CMS (@tietokilta/cms)
- Admin Panel
- Content API
- Media Management
- Authentication System

c. Database Layer:
- MongoDB Database
- Collections (boards, committees, documents, etc.)
- Media Storage

d. Shared Components:
- UI Library (@tietokilta/ui)
- Type Definitions (@tietokilta/cms-types)
- Configuration Packages

##### Architecture Representation

**┌─────────────────────────────────────────────────────────────┐**
- Client Browsers                         │
- ┬─────────────────────────────────┘
- ↓
**┌─────────────────────────────────────────────────────────────┐**
- Next.js Web Application                   │
- ┌──────────────┐  ┌──────────────┐  ┌──────────────┐      │
- Pages     │  │    API       │  │  Components  │      │
- (App Router)│  │   Routes     │  │  (@tietokilta/ui)  │
- ┘  └──────────────┘  └──────────────┘      │
- ┬─────────────────────────────────┘
- ↓
**┌─────────────────────────────────────────────────────────────┐**
- Payload CMS                             │
- ┌──────────────┐  ┌──────────────┐  ┌──────────────┐      │
- Admin Panel  │  │ Content API  │  │Media Manager │      │
- ┘  └──────────────┘  └──────────────┘      │
- ┬─────────────────────────────────┘
- ↓
**┌─────────────────────────────────────────────────────────────┐**
- MongoDB Database                        │
- ┌──────────────┐  ┌──────────────┐  ┌──────────────┐      │
- Collections  │  │    Media     │  │  Versions    │      │
- ┘  └──────────────┘  └──────────────┘      │
- ┘

##### Important Relationships to Highlight

- Next.js app consuming Payload CMS API
- CMS authentication flow
- Database interactions
- Shared component usage
- Internationalization flow
- Media handling pipeline

##### Additional Elements

- External service integrations (HSL stops, calendar)
- Build and deployment pipeline
- Development tooling

##### Specific Implementation Details

Technical stack annotations:
- Next.js 14 with App Router
- Payload CMS
- MongoDB
- TypeScript
- Tailwind CSS
- Docker
- pnpm workspace

##### Development Flow

How the development environment works:
- Local development setup
- Database seeding
- Image storage
- Type generation
- Build process

Remember to maintain a balance between detail and clarity, focusing on the architectural decisions that make this project unique, such as the monorepo structure and the tight integration between the CMS and website components.

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Client
        Browser["Web Browser"]
    end

    subgraph WebApp["Next.js Web Application"]
        Pages["Pages (App Router)"]:::frontend
        APIRoutes["API Routes"]:::frontend
        Components["Components"]:::frontend
        i18n["Internationalization"]:::frontend
        APIIntegration["API Integration"]:::frontend
    end

    subgraph CMS["Payload CMS"]
        AdminPanel["Admin Panel"]:::cms
        ContentAPI["Content API"]:::cms
        MediaManager["Media Manager"]:::cms
        Collections["Collections"]:::cms
        AccessControl["Access Control"]:::cms
        EmailSystem["Email System"]:::cms
    end

    subgraph Database["MongoDB Database"]
        DBCollections["Collections"]:::database
        MediaStorage["Media Storage"]:::database
    end

    subgraph Shared["Shared Components"]
        UILib["UI Library"]:::shared
        Types["Type Definitions"]:::shared
        Config["Configuration"]:::shared
    end

    Browser --> Pages
    Pages --> APIIntegration
    APIIntegration --> ContentAPI
    Pages --> Components
    Components --> UILib
    Pages --> i18n
    APIRoutes --> ContentAPI
    
    AdminPanel --> Collections
    ContentAPI --> Collections
    MediaManager --> MediaStorage
    Collections --> DBCollections
    AccessControl --> Collections
    EmailSystem --> Collections

    %% Component Mappings
    click Pages "https://github.com/tietokilta/web/tree/main/apps/web/src/app/[locale]"
    click Components "https://github.com/tietokilta/web/tree/main/apps/web/src/components"
    click APIRoutes "https://github.com/tietokilta/web/tree/main/apps/web/src/app/next_api"
    click Collections "https://github.com/tietokilta/web/tree/main/apps/cms/src/collections"
    click AccessControl "https://github.com/tietokilta/web/tree/main/apps/cms/src/access"
    click EmailSystem "https://github.com/tietokilta/web/tree/main/apps/cms/src/emails"
    click UILib "https://github.com/tietokilta/web/tree/main/packages/ui"
    click Types "https://github.com/tietokilta/web/tree/main/packages/cms-types"
    click Config "https://github.com/tietokilta/web/tree/main/packages/config-typescript"
    click i18n "https://github.com/tietokilta/web/blob/main/apps/web/src/lib/plugins/remark-i18n.ts"
    click MediaManager "https://github.com/tietokilta/web/blob/main/apps/cms/src/controllers/media-import-controller.ts"
    click APIIntegration "https://github.com/tietokilta/web/tree/main/apps/web/src/lib/api"

    %% Styling
    classDef frontend fill:#3498db,stroke:#2980b9,color:white
    classDef cms fill:#2ecc71,stroke:#27ae60,color:white
    classDef database fill:#f1c40f,stroke:#f39c12,color:black
    classDef shared fill:#95a5a6,stroke:#7f8c8d,color:white

    %% Legend
    subgraph Legend
        Frontend["Frontend"]:::frontend
        CMSSystem["CMS"]:::cms
        DB["Database"]:::database
        SharedComp["Shared"]:::shared
    end
```
