# skssmd/golang-gin_starter architecture

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

- Interactive diagram: https://gitdiagram.com/skssmd/golang-gin_starter
- Repository: https://github.com/skssmd/golang-gin_starter

## Overview

##### Main Components
- Auth Component:
- Contains files like Controlers.go, googleauth.go, methods.go, middlewares.go, models.go, routes.go, and services.go.
- Handles user sign-up, login, JWT token creation/validation, role verification, and Google authentication.
- Control Panel:
- Located in the “controlPanel” directory (with controlPanel/process.go and controlPanel/routes.go).
- Exposes administrative endpoints that allow CRUD operations and advanced queries on registered data models.
- Subscription Module:
- Includes subscription/controllers.go, models.go, routes.go, services.go, and webhook_handler.go.
- Designed to manage subscription services and integrates with the Stripe payment processing.
- Base & Initial Setup:
- “base” holds base executables, and “initials” contains connectToDb.go and loadEndVariables.go – these are used for bootstrapping the database connection and initializing environment variables.
- Entry Point and Configuration:
- main.go orchestrates the overall service startup.
- .env and go.mod provide configuration and dependency management.
- Database:
- There is an integrated database file (database.db), which may be used when opting for SQLite or could be easily swapped for PostgreSQL, as mentioned in the README.

##### Interactions and Data Flow
- The starting point is the main.go file, which bootstraps the application by initializing database connections (using code from initials/ directory), loading environment variables, and setting up routes.
- The Auth module uses middleware functions (LoginRequired, RequireVerification, RequireAdmin, RequireSuperuser) to secure endpoints; these are invoked on specific routes defined in auth/routes.go.
- The Control Panel module registers models (from the Auth module and other domain-specific models) and exposes RESTful endpoints along with advanced query capabilities for administrative operations.
- The Subscription module encapsulates payment flows, and its routes are exposed as part of the overall API.
- There is a clear separation of concerns: each feature (authentication, subscription, admin control panel) lives in its own package, with shared database connectivity and configuration setup defined in initials and environment files.

##### Architectural Patterns and Design Principles
- Modularity and Separation of Concerns: Each major functionality is encapsulated in its own directory/package (auth, controlPanel, subscription).
- Middleware Pattern: The use of authentication and authorization middlewares provides fine-grained control over API accessibility.
- RESTful API Design: Endpoints for control panel, authentication, and subscriptions follow a REST-like structure.
- Environment-driven Configuration: The usage of .env and environment variables (e.g., SECRET, VERIFICATION) facilitates flexible configuration.
- Extensibility: For instance, the control panel allows new models to be registered easily, and the advanced query syntax provides a versatile query mechanism.

##### Technologies, Frameworks, and Libraries
- Gin Framework: The foundation for routing and handling HTTP requests.
- JWT for authentication and token management.
- Stripe: For payment and subscription services.
- Database (PostgreSQL or SQLite): Managed through standard Go database connectivity practices.
- Go modules for dependency management.

## Diagram (Mermaid)

```mermaid
flowchart TD
    A["main.go (Entry Point)"]:::entry
    B["Initialization (.env, go.mod, initials/ & base/)"]:::init
    C["HTTP Gateway (Gin Engine)"]:::gateway
    D["Auth Module (Handles JWT, Google Auth, Email Verification)"]:::auth
    E["Control Panel (Admin CRUD & Queries)"]:::control
    F["Subscription Module (Stripe Integration)"]:::subscription
    G["Database (SQLite/PostgreSQL)"]:::db
    H["External: Google OAuth"]:::external
    I["External: Stripe Payment"]:::external

    A -->|"initialize"| B
    B -->|"setupRoutes"| C
    C -->|"authRoutes"| D
    C -->|"controlRoutes"| E
    C -->|"subscriptionRoutes"| F

    D -->|"userDataAccess"| G
    E -->|"modelManagement"| G
    F -->|"paymentProcessing"| I
    D -->|"googleAuthIntegration"| H

    %% Click Events
    click D "https://github.com/skssmd/golang-gin_starter/tree/main/auth/"
    click E "https://github.com/skssmd/golang-gin_starter/tree/main/controlPanel/"
    click F "https://github.com/skssmd/golang-gin_starter/tree/main/subscription/"
    click B "https://github.com/skssmd/golang-gin_starter/tree/main/initials/"
    click A "https://github.com/skssmd/golang-gin_starter/blob/main/main.go"
    click G "https://github.com/skssmd/golang-gin_starter/blob/main/database.db"

    %% Styling
    classDef entry fill:#f9f,stroke:#333,stroke-width:2px;
    classDef init fill:#cfc,stroke:#333,stroke-width:2px;
    classDef gateway fill:#ccf,stroke:#333,stroke-width:2px;
    classDef auth fill:#D2E4FC,stroke:#333,stroke-width:2px;
    classDef control fill:#F3DCD4,stroke:#333,stroke-width:2px;
    classDef subscription fill:#E2F0CB,stroke:#333,stroke-width:2px;
    classDef db fill:#ffe,stroke:#333,stroke-width:2px;
    classDef external fill:#fcc,stroke:#333,stroke-width:2px;
```
