# dahreau/forum-go architecture

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

- Interactive diagram: https://gitdiagram.com/dahreau/forum-go
- Repository: https://github.com/dahreau/forum-go

## Overview

##### Main Components

A. Frontend Layer:
- Static Assets Component (assets/)
- HTML Templates
- CSS Styles
- JavaScript Modules
- Client-Side Features
- Post Management
- User Interface
- Authentication Forms

B. Backend Layer:
- Server Component (internal/server/)
- Route Handlers
- Middleware
- Template Engine
- Authentication Service
- OAuth Integration
- File Upload Service

C. Database Layer:
- SQLite Database
- Data Access Layer (internal/database/)
- User Management
- Post Management
- Categories
- Activities
- Comments
- Likes

D. Security Layer:
- HTTPS/SSL
- Authentication
- Rate Limiting
- Session Management

##### Relationship Flows to Illustrate

A. Client-Server Communication:
- HTTP/HTTPS Requests
- WebSocket Connections (if implemented)
- File Upload Flows

B. Authentication Flows:
- Local Authentication
- OAuth (Google/GitHub)
- Session Management

C. Data Flows:
- User Interactions
- CRUD Operations
- Notification System

**┌─────────────────────────────────────────────────────────┐**
- Client Layer (Browser)                  │
- ┘
- ↕ HTTPS
**┌─────────────────────────────────────────────────────────┐**
- Security Layer                        │
- (SSL, Rate Limiting, Session Management, Middleware)    │
- ┘
- ↕
**┌─────────────────────────────────────────────────────────┐**
- Application Layer                     │
- ┌─────────────┐  ┌──────────────┐  ┌─────────────────┐ │
- Routes &   │  │  Template    │  │    Services     │ │
- Controllers │  │   Engine     │  │ (Auth, Upload)  │ │
- ┘  └──────────────┘  └─────────────────┘ │
- ┘
- ↕
**┌─────────────────────────────────────────────────────────┐**
- Data Layer                          │
- ┌─────────────┐  ┌──────────────┐  ┌─────────────────┐ │
- Models    │  │  Database    │  │     Cache       │ │
- Access     │  │   (Optional)    │ │
- ┘  └──────────────┘  └─────────────────┘ │
- ┘
- ↕
**┌─────────────────────────────────────────────────────────┐**
- SQLite Database                        │
- ┘

##### Additional Elements

- Docker container boundaries
- Environment configuration flow
- Static asset serving path
- Error handling flow
- Moderation workflow
- Activity tracking flow

##### Key Interactions to Highlight

- User authentication flow (both local and OAuth)
- Post creation and management
- Comment system interaction
- Like/Dislike functionality
- Moderation actions
- File upload process
- Notification system

##### Technical Details to Note

- Go backend services structure
- Template rendering system
- Database schema relationships
- Security middleware chain
- Session management flow
- Rate limiting implementation

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Client["Client Layer (Browser)"]
        UI["User Interface"]:::frontend
        Assets["Static Assets"]:::frontend
        click Assets "https://github.com/Dahreau/forum-go/tree/main/assets/"
        Templates["HTML Templates"]:::frontend
        click Templates "https://github.com/Dahreau/forum-go/tree/main/assets/templates/"
        Styles["CSS Styles"]:::frontend
        click Styles "https://github.com/Dahreau/forum-go/tree/main/assets/css/"
        JSModules["JavaScript Modules"]:::frontend
        click JSModules "https://github.com/Dahreau/forum-go/tree/main/assets/js/"
    end

    subgraph Security["Security Layer"]
        SSL["SSL/HTTPS"]:::security
        click SSL "https://github.com/Dahreau/forum-go/blob/main/server.crt"
        RateLimit["Rate Limiting"]:::security
        SessionMgmt["Session Management"]:::security
        SecMiddleware["Security Middleware"]:::security
        click SecMiddleware "https://github.com/Dahreau/forum-go/blob/main/security/middlewaresecurity.go"
    end

    subgraph App["Application Layer"]
        Routes["Route Handlers"]:::backend
        click Routes "https://github.com/Dahreau/forum-go/blob/main/internal/server/routes.go"
        TemplateEngine["Template Engine"]:::backend
        click TemplateEngine "https://github.com/Dahreau/forum-go/blob/main/internal/server/templates.go"
        AuthService["Authentication Service"]:::backend
        click AuthService "https://github.com/Dahreau/forum-go/blob/main/internal/server/auth.go"
        OAuthInteg["OAuth Integration"]:::backend
        click OAuthInteg "https://github.com/Dahreau/forum-go/blob/main/internal/server/oauth.go"
        FileUpload["File Upload Service"]:::backend
        click FileUpload "https://github.com/Dahreau/forum-go/blob/main/internal/server/upload.go"
        AdminFeatures["Admin Features"]:::backend
        click AdminFeatures "https://github.com/Dahreau/forum-go/blob/main/internal/server/admin.go"
    end

    subgraph Data["Data Layer"]
        Models["Models"]:::data
        click Models "https://github.com/Dahreau/forum-go/blob/main/internal/models/models.go"
        DBAccess["Database Access"]:::data
        click DBAccess "https://github.com/Dahreau/forum-go/blob/main/internal/database/database.go"
        UserMgmt["User Management"]:::data
        click UserMgmt "https://github.com/Dahreau/forum-go/blob/main/internal/database/auth.go"
        PostMgmt["Post Management"]:::data
        click PostMgmt "https://github.com/Dahreau/forum-go/blob/main/internal/database/posts.go"
        Categories["Categories"]:::data
        click Categories "https://github.com/Dahreau/forum-go/blob/main/internal/database/categories.go"
        Activities["Activities"]:::data
        click Activities "https://github.com/Dahreau/forum-go/blob/main/internal/database/activity.go"
        Comments["Comments"]:::data
        click Comments "https://github.com/Dahreau/forum-go/blob/main/internal/database/comments.go"
        Likes["Likes"]:::data
        click Likes "https://github.com/Dahreau/forum-go/blob/main/internal/database/likes.go"
    end

    DB[(SQLite Database)]:::database

    %% Connections
    Client --> Security
    Security --> App
    App --> Data
    Data --> DB

    %% Component Relationships
    UI --> Assets
    Assets --> Templates
    Assets --> Styles
    Assets --> JSModules
    
    AuthService --> OAuthInteg
    Routes --> TemplateEngine
    Routes --> AuthService
    Routes --> FileUpload
    Routes --> AdminFeatures

    %% Styles
    classDef frontend fill:#3498db,stroke:#2980b9,color:white
    classDef backend fill:#2ecc71,stroke:#27ae60,color:white
    classDef security fill:#f1c40f,stroke:#f39c12,color:black
    classDef data fill:#9b59b6,stroke:#8e44ad,color:white
    classDef database fill:#e74c3c,stroke:#c0392b,color:white

    %% Legend
    subgraph Legend
        Frontend["Frontend Component"]:::frontend
        Backend["Backend Component"]:::backend
        SecurityComp["Security Component"]:::security
        DataComp["Data Component"]:::data
        DatabaseComp["Database"]:::database
    end
```
