How dogukanoklu/edulens-backend works
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.