# zangster300/northstar architecture

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

- Interactive diagram: https://gitdiagram.com/zangster300/northstar
- Repository: https://github.com/zangster300/northstar

## Overview

##### Main Components Identification

a) Frontend Layer:
- Templ components (/web/components)
- Web Components (lit-html integration)
- Static assets and styles
- Layout system

b) Backend Layer:
- Go server
- Embedded NATS server
- Router system
- Route handlers

c) Data Layer:
- NATS Key-Value store
- Datastar integration

##### Architecture Pattern Representation

Project's hypermedia-driven architecture with these elements:

a) Core Patterns:
- Server-side rendering flow
- Real-time updates mechanism

b) Component Relationships:
- Template rendering pipeline
- Static asset serving
- Web Component integration
- NATS event streaming

**[Frontend Layer]**
- Templ Components
- Layouts (base.templ)
- Pages (*.templ)
- Shared Components
- Web Components (lit-html)
- Static Assets
- Styles (Tailwind/DaisyUI)
- Client-side Scripts

**[Backend Layer]**
- Go Server
- Router (routes/*.go)
- Route Handlers
- Embedded NATS Server

**[Data Layer]**
- NATS KV Store
- Datastar Integration

##### Key Interactions to Highlight

a) Request Flow:
- Client request → Router → Handler → Template Rendering → Response
- Real-time updates via NATS streaming
- Web Component initialization and lifecycle

b) Data Flow:
- NATS KV store operations
- Datastar data synchronization
- Server-side state management

##### Development Workflow

A separate section showing:
- Live reload mechanism
- Development server setup
- Build pipeline
- Docker deployment flow

##### Notes for Implementation

- Maintain hierarchy in component placement
- Related components visually
- Version/environment-specific paths
- Annotations for important configurations

Remember to include development tooling (Air, esbuild) in a separate section to show the complete development ecosystem.

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Frontend
        TC[Templ Components]
        WC[Web Components]
        SA[Static Assets]
        ST[Styles]
        PG[Pages]
        LS[Layout System]
    end

    subgraph Backend
        GS[Go Server]
        RT[Router]
        RH[Route Handlers]
        NS[NATS Server]
    end

    subgraph Data
        KV[NATS KV Store]
        DS[Datastar Integration]
    end

    subgraph DevTools
        BC[Build Config]
        SC[Styling Config]
        PM[Package Management]
    end

    %% Frontend Relationships
    TC --> LS
    TC --> PG
    SA --> ST
    
    %% Backend Relationships
    GS --> RT
    RT --> RH
    RH --> NS
    
    %% Data Relationships
    NS --> KV
    DS --> KV
    
    %% Cross-layer Relationships
    RH --> TC
    WC --> DS
    TC --> WC

    %% Component Mappings
    click TC "https://github.com/zangster300/northstar/tree/main/web/components"
    click PG "https://github.com/zangster300/northstar/tree/main/web/pages"
    click LS "https://github.com/zangster300/northstar/blob/main/web/layouts/base.templ"
    click WC "https://github.com/zangster300/northstar/tree/main/web/libs/lit-html/src/components"
    click SA "https://github.com/zangster300/northstar/tree/main/web/static/assets"
    click ST "https://github.com/zangster300/northstar/blob/main/web/styles/styles.css"
    click GS "https://github.com/zangster300/northstar/blob/main/main.go"
    click RT "https://github.com/zangster300/northstar/blob/main/routes/router.go"
    click RH "https://github.com/zangster300/northstar/blob/main/routes/routes_counter.go"
    click DS "https://github.com/zangster300/northstar/blob/main/web/libs/datastar/index.ts"
    click BC "https://github.com/zangster300/northstar/blob/main/Taskfile.yml"
    click SC "https://github.com/zangster300/northstar/blob/main/tailwind.config.js"
    click PM "https://github.com/zangster300/northstar/blob/main/package.json"

    classDef frontend fill:#a8d1ff,stroke:#333,stroke-width:2px
    classDef backend fill:#90EE90,stroke:#333,stroke-width:2px
    classDef data fill:#FFE5B4,stroke:#333,stroke-width:2px
    classDef devtools fill:#E6E6FA,stroke:#333,stroke-width:2px

    class TC,WC,SA,ST,PG,LS frontend
    class GS,RT,RH,NS backend
    class KV,DS data
    class BC,SC,PM devtools
```
