How andrescampuzano/golang-dashboard works
Main Components
• API Entry Point & Router: Represented in files like main.go and api.go which configure the HTTP server (using Gorilla Mux).
• Authentication Module: The auth.go file handles JWT-based authentication and authorization.
• Service Layers: There are dedicated service files (for example, customer.service.go, expense.service.go, earnings.service.go, etc.) that encapsulate business logic for users, customers, products, sales, expenses, and earnings.
• Storage/Data Access Layers: For each entity, there are corresponding storage files (e.g., customer.storage.go, product.storage.go, sale.storage.go, etc.) which abstract and handle interactions with the PostgreSQL database. The database.go file sets up database connection and schema initializations, with migrations located in the migrations folder.
• External Integrations:
• AWS S3: s3.go shows integration with AWS’s S3 bucket for file uploads and deletions.
• Email Service: The emails.go and SendGrid dependencies indicate a component responsible for sending emails.
• Environment Configuration: The .env.example file and usage of godotenv in Go indicate a configuration management component.
• Helper/Utility Functions: Files like utils.go support common functionalities such as JSON formatting and HTTP routing.
Relationships and Data Flow
• The HTTP Server (main.go) sets up the routing and directs incoming requests to the appropriate service.
• Each service (for example, customer.service.go) handles business logic then interacts with its storage layer (e.g., customer.storage.go) to perform CRUD operations on the PostgreSQL database.
• Authentication (auth.go) intercepts requests to verify JWT tokens before granting access to protected endpoints.
• External communications: The AWS S3 component handles file uploads/downloads, and the email functionality uses SendGrid to deliver emails.
• Database Connection: The database.go file and migrations ensure connectivity and schema setup for PostgreSQL.
Architectural Patterns & Design Principles
• Separation of Concerns: The design distinctly separates routing, business logic (services), and data access (storage).
• Modular Design: Each entity (user, customer, product, sale, expense, earnings) has its own service and storage files, ensuring loose coupling and easier maintenance.
• External Service Integration: The project modularly integrates with third-party services (AWS S3, SendGrid, PostgreSQL) through dedicated components.