# dogukanoklu/edulens-backend architecture

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

- Interactive diagram: https://gitdiagram.com/dogukanoklu/edulens-backend
- Repository: https://github.com/dogukanoklu/edulens-backend

## Overview

##### Project Type & Purpose
- It is structured as a traditional web API service built with Go, intended to interact with a database (as indicated by SQL scripts and a “database” package) and exposing endpoints for handling attendance and class-related operations.

##### Analyzing the File Structure
- The “api” directory contains the main command (cmd/main.go) which is the entry point.
- The “pkg” directory is organized into several subdirectories:
- database: Handles database connectivity or initializations.
- handlers: Contains HTTP handlers (e.g., attendance.go, class.go) that process incoming HTTP requests.
- middleware: Contains cross-cutting concerns like authentication (auth.go) and CORS (cors.go).
- models: Contains the data models for attendance and class.
- repository: Likely abstracts data access logic for specific models.
- router: Manages route definitions for mapping HTTP requests to handlers.
- script: Contains database schema and setup scripts, which may be used for bootstrapping the database.
- services: Encapsulates business logic for handling domain functionality (like attendance and class services).
- utils: Provides supporting utilities such as JSON response formatting and request validation.
- In addition, there are testing files and documentation under “api/test” and “docs”. This enhanced structure suggests layered architecture which aligns with separation of concerns.

##### Key Components and Their Relationships
- API Entry Point: cmd/main.go – Initializes the service, configures routes, and starts the server.
- Router: Located in pkg/router/router.go – Directs HTTP requests to the correct handler.
- Middleware: In pkg/middleware – Processes tasks such as authentication and CORS handling before requests hit the handlers.
- HTTP Handlers: Found in pkg/handlers – Act as controllers that handle incoming requests and trigger the appropriate business logic.
- Service Layer: In pkg/services – Implements business logic for domain concepts like attendance and class management.
- Repository Layer: In pkg/repository – Interfaces with the database to perform CRUD operations.
- Database Layer: In pkg/database – Manages database connectivity and configuration. Database schema and setup scripts (schema.sql, setup-db.sh) indicate how the database is structured.
- Models: In pkg/models – Defines the data structures used throughout the application.
- Logging and Utilities: pkg/log, pkg/utils – Provide logging and auxiliary functions to standardize responses and validations.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External Client
    Client("External Client"):::client

    %% API Layer
    subgraph "API Layer"
        APIEntry("API Entry (cmd/main)"):::api
        Router("HTTP Router (pkg/router)"):::api
        APIEntry -->|"directs to"| Router
    end

    %% Middleware Layer
    subgraph "Middleware Layer"
        AuthMW("Auth Middleware (pkg/middleware/auth)"):::middleware
        CORSMW("CORS Middleware (pkg/middleware/cors)"):::middleware
        Router -->|"passes to"| AuthMW
        AuthMW -->|"then to"| CORSMW
    end

    %% Handlers Layer
    subgraph "Handlers Layer"
        AttendanceHandler("Attendance Handler (pkg/handlers/attendance)"):::handler
        ClassHandler("Class Handler (pkg/handlers/class)"):::handler
        CORSMW -->|"forwards to"| AttendanceHandler
        CORSMW -->|"forwards to"| ClassHandler
    end

    %% Services Layer
    subgraph "Services Layer"
        AttendanceService("Attendance Service (pkg/services/attendance)"):::service
        ClassService("Class Service (pkg/services/class)"):::service
        AttendanceHandler -->|"calls"| AttendanceService
        ClassHandler -->|"calls"| ClassService
    end

    %% Repository Layer
    subgraph "Repository Layer"
        AttendanceRepository("Attendance Repository (pkg/repository/attendance)"):::repository
        ClassRepository("Class Repository (pkg/repository/class)"):::repository
        AttendanceService -->|"queries"| AttendanceRepository
        ClassService -->|"queries"| ClassRepository
    end

    %% Database Layer
    subgraph "Database Layer"
        DBConnection("Database Connection (pkg/database/db)"):::database
        Database("Database"):::database
        AttendanceRepository -->|"connects"| DBConnection
        ClassRepository -->|"connects"| DBConnection
        DBConnection -->|"accesses"| Database
    end

    %% Supporting Utilities
    subgraph "Supporting Utilities"
        DatabaseSchema("Database Schema Script"):::util
        DatabaseSetup("Database Setup Script"):::util
        AttendanceModel("Attendance Model"):::util
        ClassModel("Class Model"):::util
        LoggingUtil("Logging Utility"):::util
        JSONUtil("JSON Response Utility"):::util
        ReqValidationUtil("Request Validation Utility"):::util
    end

    %% Flow from External Client
    Client -->|"sends request"| APIEntry

    %% Click Events
    click APIEntry "https://github.com/dogukanoklu/edulens-backend/blob/main/api/cmd/main.go"
    click Router "https://github.com/dogukanoklu/edulens-backend/blob/main/api/pkg/router/router.go"
    click AuthMW "https://github.com/dogukanoklu/edulens-backend/blob/main/api/pkg/middleware/auth.go"
    click CORSMW "https://github.com/dogukanoklu/edulens-backend/blob/main/api/pkg/middleware/cors.go"
    click AttendanceHandler "https://github.com/dogukanoklu/edulens-backend/blob/main/api/pkg/handlers/attendance.go"
    click ClassHandler "https://github.com/dogukanoklu/edulens-backend/blob/main/api/pkg/handlers/class.go"
    click AttendanceService "https://github.com/dogukanoklu/edulens-backend/blob/main/api/pkg/services/attendance.go"
    click ClassService "https://github.com/dogukanoklu/edulens-backend/blob/main/api/pkg/services/class.go"
    click AttendanceRepository "https://github.com/dogukanoklu/edulens-backend/blob/main/api/pkg/repository/attendance.go"
    click ClassRepository "https://github.com/dogukanoklu/edulens-backend/blob/main/api/pkg/repository/class.go"
    click DBConnection "https://github.com/dogukanoklu/edulens-backend/blob/main/api/pkg/database/db.go"
    click DatabaseSchema "https://github.com/dogukanoklu/edulens-backend/blob/main/api/pkg/script/schema.sql"
    click DatabaseSetup "https://github.com/dogukanoklu/edulens-backend/blob/main/api/pkg/script/setup-db.sh"
    click AttendanceModel "https://github.com/dogukanoklu/edulens-backend/blob/main/api/pkg/models/attendance.go"
    click ClassModel "https://github.com/dogukanoklu/edulens-backend/blob/main/api/pkg/models/class.go"
    click LoggingUtil "https://github.com/dogukanoklu/edulens-backend/blob/main/api/pkg/log/log.go"
    click JSONUtil "https://github.com/dogukanoklu/edulens-backend/blob/main/api/pkg/utils/json_response.go"
    click ReqValidationUtil "https://github.com/dogukanoklu/edulens-backend/blob/main/api/pkg/utils/req_validation.go"

    %% Styles
    classDef client fill:#D3D3D3,stroke:#000,stroke-width:2px
    classDef api fill:#ADD8E6,stroke:#333,stroke-width:2px
    classDef middleware fill:#FFD700,stroke:#333,stroke-width:2px
    classDef handler fill:#90EE90,stroke:#333,stroke-width:2px
    classDef service fill:#FFB6C1,stroke:#333,stroke-width:2px
    classDef repository fill:#FFA07A,stroke:#333,stroke-width:2px
    classDef database fill:#F4A460,stroke:#333,stroke-width:2px
    classDef util fill:#E0FFFF,stroke:#333,stroke-width:2px
```
