# prosamik/prosamik-server architecture

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

- Interactive diagram: https://gitdiagram.com/prosamik/prosamik-server
- Repository: https://github.com/prosamik/prosamik-server

## Overview

##### Main Components

a. External Layer:
- Client Applications (showing incoming HTTP requests)
- GitHub Authentication Service
- Static File Storage
- PostgreSQL Database

b. Application Core Layers:
##### Router Layer
- API Routes
- Admin Routes
- Blog Routes
- Newsletter Routes
- Project Routes
- Analytics Routes

##### Middleware Layer
- Authentication Middleware
- Rate Limiter
- General Middleware

##### Handler Layer
- Blog Handlers
- Project Handlers
- Newsletter Handlers
- Analytics Handlers
- Admin Handlers
- Feedback Handlers
- Markdown Handlers

##### Service Layer
- Authentication Services (JWT & GitHub)
- Markdown Parser Service
- Markdown Fetcher Service

##### Repository Layer
- Blog Repository
- Project Repository
- Newsletter Repository
- Analytics Repository

##### Component Relationships

- External clients → Router Layer
- Router Layer → Middleware Layer
- Middleware Layer → Handler Layer
- Handler Layer → Service Layer
- Handler Layer → Repository Layer
- Repository Layer → PostgreSQL Database
- Authentication Services → GitHub External Service

##### Technical Details to Highlight

- JWT Authentication flow
- GitHub OAuth integration
- Rate limiting mechanism
- Markdown processing pipeline
- Database interaction patterns
- Template rendering system

##### Additional Elements

- Version/environment configuration flow
- Error handling patterns
- Monitoring/logging points
- Public vs. private APIs

- Presentation layer (handlers)
- Business logic (services)
- Data access (repositories)
- External interfaces (auth, database)

## Diagram (Mermaid)

```mermaid
graph TB
    %% External Layer
    subgraph External
        Client[Client Applications]
        GitHub[GitHub Auth Service]:::external
        Storage[Static File Storage]:::external
        DB[(PostgreSQL)]:::database
    end

    %% Router Layer
    subgraph Routers
        MainRouter[Main Router]:::router
        click MainRouter "https://github.com/proSamik/prosamik-server/blob/main/internal/router/router.go"
        APIRoutes[API Routes]:::router
        click APIRoutes "https://github.com/proSamik/prosamik-server/blob/main/internal/router/api_routes.go"
        BlogRoutes[Blog Routes]:::router
        click BlogRoutes "https://github.com/proSamik/prosamik-server/blob/main/internal/router/blog_routes.go"
        ProjectRoutes[Project Routes]:::router
        click ProjectRoutes "https://github.com/proSamik/prosamik-server/blob/main/internal/router/project_routes.go"
        AdminRoutes[Admin Routes]:::router
        click AdminRoutes "https://github.com/proSamik/prosamik-server/blob/main/internal/router/admin.go"
        NewsletterRoutes[Newsletter Routes]:::router
        click NewsletterRoutes "https://github.com/proSamik/prosamik-server/blob/main/internal/router/newsletter_management.go"
        AnalyticsRoutes[Analytics Routes]:::router
        click AnalyticsRoutes "https://github.com/proSamik/prosamik-server/blob/main/internal/router/analytics_management.go"
    end

    %% Middleware Layer
    subgraph Middleware
        AuthMiddleware[Auth Middleware]:::middleware
        click AuthMiddleware "https://github.com/proSamik/prosamik-server/blob/main/internal/middleware/auth_middleware.go"
        RateLimiter[Rate Limiter]:::middleware
        click RateLimiter "https://github.com/proSamik/prosamik-server/blob/main/internal/middleware/rate_limiter.go"
        GenMiddleware[General Middleware]:::middleware
        click GenMiddleware "https://github.com/proSamik/prosamik-server/blob/main/internal/middleware/middleware.go"
    end

    %% Handler Layer
    subgraph Handlers
        BlogHandler[Blog Handler]:::handler
        click BlogHandler "https://github.com/proSamik/prosamik-server/blob/main/internal/handler/blogs_handler.go"
        ProjectHandler[Project Handler]:::handler
        click ProjectHandler "https://github.com/proSamik/prosamik-server/blob/main/internal/handler/projects_handler.go"
        NewsletterHandler[Newsletter Handler]:::handler
        click NewsletterHandler "https://github.com/proSamik/prosamik-server/blob/main/internal/handler/newsletter_handler.go"
        AnalyticsHandler[Analytics Handler]:::handler
        click AnalyticsHandler "https://github.com/proSamik/prosamik-server/blob/main/internal/handler/analytics_handler.go"
        FeedbackHandler[Feedback Handler]:::handler
        click FeedbackHandler "https://github.com/proSamik/prosamik-server/blob/main/internal/handler/feedback_handler.go"
        MarkdownHandler[Markdown Handler]:::handler
        click MarkdownHandler "https://github.com/proSamik/prosamik-server/blob/main/internal/handler/markdown_handler.go"
    end

    %% Service Layer
    subgraph Services
        JWTAuth[JWT Auth Service]:::service
        click JWTAuth "https://github.com/proSamik/prosamik-server/blob/main/internal/auth/jwt_auth.go"
        GitHubAuth[GitHub Auth Service]:::service
        click GitHubAuth "https://github.com/proSamik/prosamik-server/blob/main/internal/auth/github_auth.go"
        MarkdownParser[Markdown Parser]:::service
        click MarkdownParser "https://github.com/proSamik/prosamik-server/blob/main/internal/parser/markdown_to_html.go"
        MarkdownFetcher[Markdown Fetcher]:::service
        click MarkdownFetcher "https://github.com/proSamik/prosamik-server/blob/main/internal/fetcher/markdown_fetcher.go"
    end

    %% Repository Layer
    subgraph Repositories
        BlogRepo[Blog Repository]:::repository
        click BlogRepo "https://github.com/proSamik/prosamik-server/blob/main/internal/repository/blog_repository.go"
        ProjectRepo[Project Repository]:::repository
        click ProjectRepo "https://github.com/proSamik/prosamik-server/blob/main/internal/repository/project_repository.go"
        NewsletterRepo[Newsletter Repository]:::repository
        click NewsletterRepo "https://github.com/proSamik/prosamik-server/blob/main/internal/repository/newsletter_repository.go"
        AnalyticsRepo[Analytics Repository]:::repository
        click AnalyticsRepo "https://github.com/proSamik/prosamik-server/blob/main/internal/repository/analytics_repository.go"
    end

    %% Templates
    subgraph Templates
        BaseTemplate[Base Template]:::template
        click BaseTemplate "https://github.com/proSamik/prosamik-server/blob/main/internal/templates/base.html"
        BlogTemplate[Blog Management]:::template
        click BlogTemplate "https://github.com/proSamik/prosamik-server/blob/main/internal/templates/blog_management.html"
        ProjectTemplate[Project Management]:::template
        click ProjectTemplate "https://github.com/proSamik/prosamik-server/blob/main/internal/templates/project_management.html"
        AnalyticsTemplate[Analytics Management]:::template
        click AnalyticsTemplate "https://github.com/proSamik/prosamik-server/blob/main/internal/templates/analytics_management.html"
        NewsletterTemplate[Newsletter Management]:::template
        click NewsletterTemplate "https://github.com/proSamik/prosamik-server/blob/main/internal/templates/newsletter_management.html"
    end

    %% Connections
    Client --> MainRouter
    MainRouter --> |Routes Requests| APIRoutes & BlogRoutes & ProjectRoutes & AdminRoutes & NewsletterRoutes & AnalyticsRoutes
    APIRoutes & BlogRoutes & ProjectRoutes & AdminRoutes & NewsletterRoutes & AnalyticsRoutes --> AuthMiddleware & RateLimiter & GenMiddleware
    AuthMiddleware & RateLimiter & GenMiddleware --> BlogHandler & ProjectHandler & NewsletterHandler & AnalyticsHandler & FeedbackHandler & MarkdownHandler
    BlogHandler & ProjectHandler & NewsletterHandler & AnalyticsHandler --> JWTAuth & GitHubAuth & MarkdownParser & MarkdownFetcher
    BlogHandler & ProjectHandler & NewsletterHandler & AnalyticsHandler --> BlogRepo & ProjectRepo & NewsletterRepo & AnalyticsRepo
    BlogRepo & ProjectRepo & NewsletterRepo & AnalyticsRepo --> DB
    GitHubAuth --> GitHub
    Handlers --> Templates

    %% Styling
    classDef external fill:#68a0cf
    classDef router fill:#95d475
    classDef middleware fill:#f9d56e
    classDef handler fill:#ff9b73
    classDef service fill:#ff9b73
    classDef repository fill:#c3a6ff
    classDef database fill:#68a0cf
    classDef template fill:#d3d3d3
```
