# jpells/jblog architecture

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

- Interactive diagram: https://gitdiagram.com/jpells/jblog
- Repository: https://github.com/jpells/jblog

## Overview

##### Main Components
- Go Web Application: At the heart of the system is the main Go application (main.go) which acts as the HTTP server.
- Request Handlers & Routing: The application handles various routes including the homepage, administrative ("/admin") routes, login pages, and pages for creating/editing posts.
- Template Rendering Engine: There’s a dedicated “templates” directory containing HTML files (home.html, admin.html, login.html, edit.html, post.html) used for rendering web pages.
- Data Store Layer: The system uses two different blog post stores – an in-memory implementation (in_memory_blog_post_store.go) and a filesystem-based implementation (filesystem_blog_post_store.go). These components encapsulate the storage and retrieval of blog posts.
- User Authentication Module: Although implemented simply (using Basic Auth), it is a critical aspect enabling access control in the admin interface.
- Testing Suite: There are test files (main_test.go, in_memory_blog_post_store_test.go, filesystem_blog_post_store_test.go) which indicate a component of the architecture dedicated to ensuring code correctness.
- CI/CD and Deployment: The existence of GitHub workflows (in .github/workflows with YAML files for Go) and configuration files like Taskfile.yml indicate that the project integrates automated testing, deployment, and build processes.

##### Detail the Relationships and Interactions
- Incoming HTTP requests reach the Go web server, which uses a routing layer to determine whether to serve a public or an administrative page.
- For the UI, the server interacts with the Template Engine that loads HTML files from the “templates” directory to deliver dynamic content.
- When a blog post is created, edited, or viewed, the server calls methods provided by one of the two blog post store implementations (either in-memory or filesystem based, depending on configuration or context). This abstraction allows for interchangeable persistence mechanisms.
- User authentication is performed at the entry point for secure routes, ensuring that only authorized users can access the admin interface.
- The CI/CD components (GitHub workflows) are responsible for building, testing, and deploying the application automatically when updates occur.

##### Architectural Patterns & Design Principles
- Modularity: The separation between the HTTP server, template rendering, and data storage (with interchangeable store implementations) reflects a modular design.
- Separation of Concerns: The system clearly delineates presentation (templates), business logic (HTTP handlers, authentication, routing), and data access (blog post store).
- Testing & Continuous Integration: The inclusion of both tests and CI tools shows a design that emphasizes code quality and quick feedback loops.

##### Relevant Technologies and Frameworks
- Language: Go (with its inherent HTTP server and concurrency model).
- Templating: Standard Go html/template package is likely used to render the views.
- CI/CD: GitHub workflows using YAML for automation.
- Authentication: Basic HTTP authentication for admin and login endpoints.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Global Entities
    User["Web Browser"]:::client

    %% Main Application
    HTTPServer["HTTP Server (main.go)"]:::server
    Auth["User Authentication (Basic Auth)"]:::auth
    TemplateEngine["Template Engine (templates)"]:::template

    %% Blog Post Stores Subgraph
    subgraph "Blog Post Store"
        InMemoryStore["In-Memory Store"]:::db
        FileSystemStore["Filesystem Store"]:::db
    end

    %% Testing Suite Subgraph
    subgraph "Testing Suite"
        MainTests["Main Tests"]:::test
        InMemoryTests["In-Memory Tests"]:::test
        FileSystemTests["Filesystem Tests"]:::test
    end

    %% CI/CD Pipeline Subgraph
    subgraph "CI/CD Pipeline"
        GitHubWorkflows["GitHub Workflows"]:::cicd
        Taskfile["Taskfile"]:::cicd
    end

    %% Connections
    User -->|"HTTPRequest"| HTTPServer
    HTTPServer -->|"RenderPage"| TemplateEngine
    TemplateEngine -->|"ReturnHTML"| HTTPServer
    HTTPServer -->|"Authenticate"| Auth
    HTTPServer -->|"CRUDOperations"| InMemoryStore
    HTTPServer -->|"CRUDOperations"| FileSystemStore
    GitHubWorkflows -->|"RunTests"| MainTests
    GitHubWorkflows -->|"RunTests"| InMemoryTests
    GitHubWorkflows -->|"RunTests"| FileSystemTests
    GitHubWorkflows -->|"Deploy"| HTTPServer
    Taskfile -->|"ExecutesCI/CD"| HTTPServer
    MainTests -->|"Validate"| HTTPServer
    InMemoryTests -->|"Validate"| InMemoryStore
    FileSystemTests -->|"Validate"| FileSystemStore

    %% Click Events
    click HTTPServer "https://github.com/jpells/jblog/blob/main/main.go"
    click TemplateEngine "https://github.com/jpells/jblog/tree/main/templates/"
    click InMemoryStore "https://github.com/jpells/jblog/blob/main/in_memory_blog_post_store.go"
    click FileSystemStore "https://github.com/jpells/jblog/blob/main/filesystem_blog_post_store.go"
    click MainTests "https://github.com/jpells/jblog/blob/main/main_test.go"
    click InMemoryTests "https://github.com/jpells/jblog/blob/main/in_memory_blog_post_store_test.go"
    click FileSystemTests "https://github.com/jpells/jblog/blob/main/filesystem_blog_post_store_test.go"
    click GitHubWorkflows "https://github.com/jpells/jblog/tree/main/.github/workflows/"
    click Taskfile "https://github.com/jpells/jblog/blob/main/Taskfile.yml"

    %% Styles
    classDef client fill:#ccf,stroke:#333,stroke-width:2px;
    classDef server fill:#f9c,stroke:#333,stroke-width:2px;
    classDef auth fill:#f99,stroke:#333,stroke-width:2px;
    classDef template fill:#cfc,stroke:#333,stroke-width:2px;
    classDef db fill:#ffc,stroke:#333,stroke-width:2px;
    classDef test fill:#fc9,stroke:#333,stroke-width:2px;
    classDef cicd fill:#9ff,stroke:#333,stroke-width:2px;
```
