How wendersoon/social_networking_app_golang works
Main System Components
• API Service: Encapsulated in the "api" folder. This is the backend responsible for direct interaction with the database and handles authentication (JWT), database operations, middleware processing, and response formatting.
• Web Application: Located in the "webapp" folder. This serves as the frontend layer, handling user interactions via HTML views and assets (CSS/JS), and communicating with the API service (either by proxying frontend requests or directly issuing API calls).
• Database: Although not explicitly a folder, the API contains an "sql" script (api/sql/sql.sql); hence, a database (e.g., MySQL) is required as a persistent data store.
• Environment Configurations: Both components (API and WebApp) have dedicated .env files that define critical runtime settings such as credentials and ports.
File Structure to Understand the Architectural Boundaries
• In the API:
• The "src" folder is organized into clear packages—autenticacao (JWT management), banco (database connection), config (environment variables), controllers (API request handling), middlewares, modelos (data structures), repositorios (database operations), respostas (API responses), router (route management), and seguranca (credential encryption).
• This separation suggests a layered architecture where each layer (from configuration and routing to business logic and data access) is isolated.
• In the Web Application:
• The "src" folder mirrors much of the API’s structure: config, controllers, middlewares, modelos, and router.
• Additional folders handle cookies, requisicoes (to call the API), and templates (views) in the "views" folder.
• API Component:
• Configuration (config)
• Authentication (autenticacao and seguranca)
• Controllers (handling HTTP requests and responses)
• Middlewares (logging, auth/validation)
• Models and Repositories (representing the business entities and data access)
• Router (defining the REST endpoints)
• Database Connection (banco)
• Web Application Component:
• Assets (CSS/JS)
• Views (HTML templates and their sub-templates)
• Controllers (routing frontend actions)
• Cookies and Sessions management
• Requisicoes (for making API calls) and corresponding responses
• Router (for organizing routes for page navigation)
• Database Component:
Additional Details and Architectural Patterns
• How the API and the Web Application are separated concerns – the API is entirely focused on business logic and persistent data, while the WebApp deals with UI rendering and client-side interaction.
• RESTful architecture for API endpoints.
• Use of middleware for cross-cutting concerns (logging and authentication) and the use of JWT tokens for securing endpoints.
• That configuration management is done via environment files (.env), which should be a part of the deployment considerations.