How bakigoal/snippetbox works
Main Components
a) Web Layer (Presentation Layer)
• Following components from cmd/web:
• HTTP Handlers (handlers-snippets.go, handlers-users.go)
• Middleware
• Router (routes.go)
• Templates Engine (templates.go)
b) Business Logic Layer (Domain Layer)
• This in the middle
• Components from internal/models:
• Snippets Model
• Users Model
• Validator
c) Data Layer
• This at the bottom
• Include:
• SQL Database (represented by the sql/ directory contents)
• Sessions Store
d) Static Assets
• As a side component
• Include:
• UI Templates
• Static Files (CSS/JS/Images)
Component Relationships
• HTTP Request → Middleware → Router → Handlers
• Handlers → Models → Database
• Handlers → Template Engine → UI Templates
• Static Assets → HTTP Server (direct serve)
Specific Elements
┌─────────────────────────────────────────────────┐
• Web Layer │
• ┌─────────┐ ┌─────────┐ ┌────────┐ ┌────────┐ │
• Middleware│→│ Router │→│Handlers│←│Contexts│ │
• ┘ └─────────┘ └────────┘ └────────┘ │
• ┘
• ↕
┌─────────────────────────────────────────────────┐
• Business Logic Layer │
• ┌─────────┐ ┌─────────┐ ┌───────────┐ │
• Snippets│ │ Users │ │ Validator │ │
• Model │ │ Model │ └───────────┘ │
• ┘ └─────────┘ │
• ┘
• ↕
┌─────────────────────────────────────────────────┐
• Data Layer │
• ┌─────────┐ ┌─────────────┐ │
• SQL DB │ │ Sessions DB │ │
• ┘ └─────────────┘ │
• ┘
┌─────────────┐
• Static Assets│
• ┌─────────┐ │
• Templates│ │←────────────────┐
• ┘ │ │
• ┌─────────┐ │ │
• CSS/JS │ │ │
• ┘ │ │
• ┘ ↑
• Template Engine
Additional Details to Note
• TLS configuration (from tls/ directory)
• Separation between public and internal packages
• Error handling flow across layers
• Session management flow
Important Architectural Patterns to Highlight
• Clean Architecture pattern (separation of concerns)
• MVC-like structure (handlers as controllers, templates as views, models as model)
• Middleware chain pattern
• Repository pattern for data access
Technical Stack Indicators
• Go (as primary language)
• SQL Database
• HTML Templates
• Static File Serving
• TLS/HTTPS Support