# alessiodam/smid architecture

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

- Interactive diagram: https://gitdiagram.com/alessiodam/smid
- Repository: https://github.com/alessiodam/smid

## Overview

##### Project’s Core Components
- Web Server & API Gateway: Represented by main.go, which serves as the entry point for HTTP requests.
- Request Handlers: Located in the “handlers” directory (auth.go and dashboard.go) – these manage authentication logic and the dashboard endpoints.
- Middleware: Located in the “middleware” folder (auth.go) – these components process authentication tokens or perform request validations before they reach the handlers.
- Business Logic / Data Models: Inside the “models” directory, which includes user information and caching. These components define the domain and enforce business rules.
- Database Layer: The “db” directory (db/db.go) is responsible for database interactions. Even if it’s a thin abstraction, it’s critical to illustrate persistence.
- Utility Functions: The “utils” folder (http.go and jwt.go) provides helper functions, such as handling HTTP specifics or JWT creation/verification.
- Deployment & Configuration: Files like Dockerfile, compose.yml, and GitHub workflows indicate containerized deployment and CI/CD practices.
- Client/UI Components: Files like index.html, dashboard.html, example.html, and smid-client.js are anchors for possibly demonstrating the service or providing integration support.

##### Component Relationships and Data Flow
- External Clients (smartschool apps or web browsers) initiate HTTP requests.
- These hit the Web Server/API Gateway (main.go) which then routes requests to specific Handlers (auth and dashboard).
- Before reaching the handlers, requests pass through Middleware that might validate JWT tokens (using functionalities in utils/jwt.go).
- Handlers interact with Business Logic/Models to perform operations such as user authentication.
- For operations needing persistence, Handlers or Models interface with the Database layer.
- Utility modules provide necessary functionality for HTTP handling and token management.
- Deployment configurations (Dockerfile, compose.yml, GitHub workflows) show that the entire service is ready for containerized deployment, ensuring reliable builds and deployments.

##### Architectural Patterns and Design Principles
- Layered Architecture: Separation into routing, middleware, handlers, model (or business logic), and database layers.
- Modularization: Clear modular design with functionalities separated into different directories.
- Containerization: The presence of Docker and Docker Compose files underline a microservice or containerized deployment strategy.
- Security and Authentication: With dedicated JWT utilities and authentication handlers/middlewares.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External Interaction
    subgraph "External Interaction"
        ext("External Clients (Smartschool Apps/Web Browsers)"):::external
    end

    %% Client/UI Components
    subgraph "Client/UI Components"
        client1("index.html"):::client
        client2("dashboard.html"):::client
        client3("example.html"):::client
        client4("smid-client.js"):::client
    end

    %% Server Layer
    subgraph "Server Layer"
        api("API Gateway (main.go)"):::server
        middleware("JWT Middleware (middleware/auth.go)"):::server
        authHandler("Auth Handler (handlers/auth.go)"):::server
        dashHandler("Dashboard Handler (handlers/dashboard.go)"):::server
    end

    %% Business Layer
    subgraph "Business Layer"
        business("Business Logic / Models"):::business
        um("User Model (models/User.go)"):::businessFile
        cm("Cache Model (models/Cache.go)"):::businessFile
        mm("Common Models (models/models.go)"):::businessFile
        database("Database Access (db/db.go)"):::database
    end

    %% Utility Functions
    subgraph "Utility Functions"
        httpUtil("HTTP Utility (utils/http.go)"):::utility
        jwtUtil("JWT Utility (utils/jwt.go)"):::utility
    end

    %% Deployment & Configuration
    subgraph "Deployment & Configuration"
        docker("Dockerfile"):::deployment
        compose("Compose File (compose.yml)"):::deployment
        cicd("CI/CD Workflow (.github/workflows/deploy-prod.yaml)"):::deployment
    end

    %% Connections
    ext -->|"sendsRequest"| api
    api -->|"routesTo"| middleware
    middleware -->|"validatesJWT"| jwtUtil
    middleware -->|"usesHTTP"| httpUtil
    middleware -->|"calls"| authHandler
    middleware -->|"calls"| dashHandler
    authHandler -->|"invokes"| business
    dashHandler -->|"invokes"| business
    business -->|"delegatesTo"| um
    business -->|"delegatesTo"| cm
    business -->|"delegatesTo"| mm
    business -->|"queries"| database
    authHandler -->|"usesHTTP"| httpUtil
    dashHandler -->|"usesHTTP"| httpUtil

    %% Deployment connections from API Gateway
    api -->|"deployedWith"| docker
    api -->|"deployedWith"| compose
    api -->|"deployedWith"| cicd

    %% Client/UI loading by External Clients
    ext -->|"loads"| client1
    ext -->|"loads"| client2
    ext -->|"loads"| client3
    ext -->|"loads"| client4

    %% Styles
    classDef external fill:#b3d9ff,stroke:#333,stroke-width:2px;
    classDef client fill:#e6e6fa,stroke:#333,stroke-width:2px;
    classDef server fill:#c2f0c2,stroke:#333,stroke-width:2px;
    classDef business fill:#ffcc99,stroke:#333,stroke-width:2px;
    classDef businessFile fill:#ffe680,stroke:#333,stroke-width:2px;
    classDef database fill:#ffcc99,stroke:#333,stroke-width:2px;
    classDef utility fill:#ff9999,stroke:#333,stroke-width:2px;
    classDef deployment fill:#d9d9d9,stroke:#333,stroke-width:2px;

    %% Click Events
    click api "https://github.com/alessiodam/smid/blob/main/main.go"
    click middleware "https://github.com/alessiodam/smid/blob/main/middleware/auth.go"
    click authHandler "https://github.com/alessiodam/smid/blob/main/handlers/auth.go"
    click dashHandler "https://github.com/alessiodam/smid/blob/main/handlers/dashboard.go"
    click business "https://github.com/alessiodam/smid/tree/main/models/"
    click um "https://github.com/alessiodam/smid/blob/main/models/User.go"
    click cm "https://github.com/alessiodam/smid/blob/main/models/Cache.go"
    click mm "https://github.com/alessiodam/smid/blob/main/models/models.go"
    click database "https://github.com/alessiodam/smid/blob/main/db/db.go"
    click httpUtil "https://github.com/alessiodam/smid/blob/main/utils/http.go"
    click jwtUtil "https://github.com/alessiodam/smid/blob/main/utils/jwt.go"
    click docker "https://github.com/alessiodam/smid/tree/main/Dockerfile"
    click compose "https://github.com/alessiodam/smid/blob/main/compose.yml"
    click cicd "https://github.com/alessiodam/smid/blob/main/.github/workflows/deploy-prod.yaml"
    click client1 "https://github.com/alessiodam/smid/blob/main/index.html"
    click client2 "https://github.com/alessiodam/smid/blob/main/dashboard.html"
    click client3 "https://github.com/alessiodam/smid/blob/main/example.html"
    click client4 "https://github.com/alessiodam/smid/blob/main/smid-client.js"
```
