# develop-suda/giter architecture

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

- Interactive diagram: https://gitdiagram.com/develop-suda/giter
- Repository: https://github.com/develop-suda/giter

## Overview

##### Project Type and Purpose
- The README explains that Giter is a web application implementing secure JWT authentication with GitHub integration. Its main functionalities include analyzing commit histories for motivation, tracking commit streaks, and sending commit summary emails.
- The project is structured as a backend service (written in Go) that renders HTML templates and integrates with external services (GitHub API, email systems).

##### File Structure for Architectural Clues
- Key folders like “controllers”, “services”, “repositories” and “models” indicate an MVC (Model-View-Controller) or layered architecture.
- The “middlewares”, “di” (dependency injection), “initializer”, and “infra” directories reinforce the application’s separation of concerns:
- Controllers handle HTTP requests and user interactions (e.g., registration, login, GitHub OAuth).
- Services encapsulate business logic (for authentication, GitHub integration, and request handling).
- Repositories abstract data persistence, interacting with the database via models.
- Middlewares (for JWT/auth and logging) ensure request filtering and monitoring.
- The “templates” folder contains HTML templates indicating that the application generates dynamic web pages.
- Docker-related files (Dockerfile, docker-compose.yml) highlight containerization and infrastructure setup.
- The “query” folder suggests specialized querying for commit data, emphasizing the analytics part of the system.

##### Components and Their Interactions
a. Client Layer:
- A web browser (or front-end client) that interacts with the server via HTTP.
- Displays dynamic pages rendered from HTML templates.
b. Application Layer:
- Controllers: Manage endpoints for authentication (auth_controller.go, github_auth_controller.go) and other requests.
- Middlewares: Handle JWT validation (auth_middleware.go) and logging, intercepting and processing requests before they hit controllers.
- Services: Implement the business logic for authentication, GitHub integration, and request processing.
- Repositories & Data Access: Abstract database interactions with data models (models/user.go) and use query classes for fetching commit data.
c. Infrastructure & Integration Components:
- DI Container (found in the di/ directory) to wire dependencies between controllers, services, repositories, etc.
- Database: (infra/db.go, migrations) components that set up and manage persistent data.
- External Services: GitHub API integrations (GitHub-auth related controllers and services) and the email sending mechanism (invoked via batch jobs as described in the README).
- Additional Components: Initializer components like logger and client initialization (in initializer/), which support infrastructure configuration.
d. Deployment Component:
- Docker and docker-compose configurations, indicating container deployment and orchestration.

##### Architectural Patterns and Design Principles
- Layered/MVC Architecture: Controllers, Services, Repositories, and Models each have their distinct responsibilities.
- Dependency Injection: The use of DI through “di/wire.go” emphasizes loose coupling between components.
- Middleware Chain: Chaining of authentication and logging middlewares reflects common web application design practices.
- Containerization: Dockerfile and docker-compose.yml indicate best practices in deploying cloud-ready containerized applications.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Client Layer"
        Client["Web Browser"]:::client
        Templates["Templates Engine"]:::templates
    end

    subgraph "Application Layer"
        Controllers["Controllers"]:::controller
        Middlewares["Middlewares"]:::middleware
        Services["Services"]:::service
        Repositories["Repositories"]:::repository
        Models["Models"]:::model
        Query["Query Components"]:::query
    end

    subgraph "Infrastructure & Integration"
        DI["DI Container"]:::di
        Infra["Infrastructure (Database, Config)"]:::infra
        Initializer["Initializer"]:::initializer
        External["External Services (GitHub API & Email)"]:::external
    end

    subgraph "Deployment"
        Dockerfile["Dockerfile"]:::deployment
        DockerCompose["docker-compose.yml"]:::deployment
    end

    %% Flow Connections
    Client -->|"HTTPRequest"| Middlewares
    Middlewares -->|"ForwardRequest"| Controllers
    Controllers -->|"CallBusinessLogic"| Services
    Controllers -->|"RenderHTML"| Templates
    Services -->|"InvokeRepo"| Repositories
    Repositories -->|"AccessModels"| Models
    Services -->|"CommitAnalytics"| Query
    Services -->|"CallExternal"| External
    DI --> Controllers
    DI --> Services
    DI --> Repositories
    DI --> Middlewares
    Initializer --> DI
    Repositories -->|"DBQuery"| Infra
    Dockerfile -->|"DeployContainers"| DI
    DockerCompose -->|"OrchestrateDeployment"| Infra

    %% Click Events
    click Templates "https://github.com/develop-suda/giter/tree/main/templates/"
    click Controllers "https://github.com/develop-suda/giter/tree/main/controllers/"
    click Middlewares "https://github.com/develop-suda/giter/tree/main/middlewares/"
    click Services "https://github.com/develop-suda/giter/tree/main/services/"
    click Repositories "https://github.com/develop-suda/giter/tree/main/repositories/"
    click Models "https://github.com/develop-suda/giter/tree/main/models/"
    click Query "https://github.com/develop-suda/giter/tree/main/query/"
    click DI "https://github.com/develop-suda/giter/tree/main/di/"
    click Infra "https://github.com/develop-suda/giter/tree/main/infra/"
    click Initializer "https://github.com/develop-suda/giter/tree/main/initializer/"
    click Dockerfile "https://github.com/develop-suda/giter/tree/main/Dockerfile"
    click DockerCompose "https://github.com/develop-suda/giter/blob/main/docker-compose.yml"

    %% Styles
    classDef client fill:#f9c,stroke:#333,stroke-width:2px;
    classDef templates fill:#ddf,stroke:#333,stroke-width:2px;
    classDef controller fill:#ccf,stroke:#333,stroke-width:2px;
    classDef middleware fill:#ffc,stroke:#333,stroke-width:2px;
    classDef service fill:#cfc,stroke:#333,stroke-width:2px;
    classDef repository fill:#fc9,stroke:#333,stroke-width:2px;
    classDef model fill:#9cf,stroke:#333,stroke-width:2px;
    classDef query fill:#f99,stroke:#333,stroke-width:2px;
    classDef di fill:#d9d,stroke:#333,stroke-width:2px;
    classDef infra fill:#aff,stroke:#333,stroke-width:2px;
    classDef initializer fill:#afa,stroke:#333,stroke-width:2px;
    classDef external fill:#ffd,stroke:#333,stroke-width:2px;
    classDef deployment fill:#fea,stroke:#333,stroke-width:2px;
```
