# cedrickchee/skel architecture

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

- Interactive diagram: https://gitdiagram.com/cedrickchee/skel
- Repository: https://github.com/cedrickchee/skel

## Overview

##### Main Components

a. Client Layer:
- Supported clients (SPAs, mobile apps, standalone services)
- CORS-enabled endpoints with trusted origins

b. API Gateway/Proxy Layer:
- Caddy reverse proxy (handling HTTPS/TLS termination)
- Rate limiting middleware
- CORS middleware

c. Application Layer (Core API):
- Main API server (port 4000)
- Route handlers (/v1/healthcheck, movies, users endpoints)
- Authentication/Authorization system
- Middleware components (logging, panic recovery, rate limiting)

d. Service Layer:
- Mailer service (SMTP)
- JSON logging service
- Validation service
- Data models and business logic

e. Data Layer:
- PostgreSQL database
- Migration system
- Connection pool management

##### Relationships and Data Flow

- HTTP/HTTPS traffic flow from clients through Caddy to API
- Database connections and pooling
- Email notifications flow
- Authentication token flow
- Migration process flow

##### Specific Implementation Details

**Configuration Management:**
- Environment variables
- Command-line flags
- Development/Staging/Production environments

**Security Features:**
- Rate limiting
- CORS protection
- Authentication tokens
- Permission system

**Monitoring & Debugging:**
- Health check endpoint
- Metrics endpoint (/debug/vars)
- JSON structured logging

##### Deployment Architecture

Production setup:
- Single Ubuntu Linux server
- Systemd service management
- Database location
- Caddy reverse proxy configuration

**[External Clients] → [HTTPS/443] → [Caddy Reverse Proxy]**
- ↓
**[Rate Limiter] → [CORS Middleware] → [API Server :4000]**
- ↓
- ┌─────────────┬─────────────┬─────────────┐
- ↓             ↓             ↓             ↓
- [User Service] [Movie Service] [Auth Service] [Mail Service]
- ↓             ↓             ↓             ↓
- [Data Models] ← [Connection Pool] → [PostgreSQL]

##### Additional Notes

Annotations for:
- Database migration paths
- Configuration options
- Deployment commands
- Health check endpoints
- Metrics collection points

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph Clients
        SPA[Single Page Applications]
        Mobile[Mobile Apps]
        Services[External Services]
    end

    subgraph Gateway
        Caddy[Caddy Reverse Proxy]:::proxy
        RateLimit[Rate Limiting]:::security
        CORSMid[CORS Middleware]:::security
    end

    subgraph API
        Server[API Server :4000]:::server
        Routes[Route Handlers]:::routes
        Auth[Authentication System]:::security
        Mid[Middleware Components]:::middleware
        Health[Health Check]:::monitoring
    end

    subgraph Services
        Mailer[Mailer Service]:::service
        Logger[JSON Logger]:::service
        Validator[Validation Service]:::service
    end

    subgraph DataLayer
        Models[Data Models]:::data
        Movies[Movies Management]:::data
        Users[Users Management]:::data
        Pool[Connection Pool]:::data
        DB[(PostgreSQL)]:::database
        Migrations[Database Migrations]:::data
    end

    subgraph EmailTemplates
        Welcome[Welcome Template]:::template
        Activation[Activation Template]:::template
        Reset[Password Reset Template]:::template
    end

    %% Client to Gateway Connections
    SPA & Mobile & Services --> Caddy
    
    %% Gateway Flow
    Caddy --> RateLimit
    RateLimit --> CORSMid
    CORSMid --> Server
    
    %% API Layer Connections
    Server --> Routes
    Server --> Auth
    Server --> Mid
    Server --> Health
    
    %% Service Layer Connections
    Routes --> Mailer
    Routes --> Logger
    Routes --> Validator
    
    %% Data Layer Connections
    Routes --> Models
    Models --> Pool
    Pool --> DB
    Movies & Users --> Pool
    Migrations --> DB
    
    %% Email Template Connections
    Mailer --> Welcome
    Mailer --> Activation
    Mailer --> Reset

    %% Styles
    classDef proxy fill:#f96
    classDef security fill:#f66
    classDef server fill:#6f6
    classDef routes fill:#6f9
    classDef middleware fill:#69f
    classDef monitoring fill:#ff9
    classDef service fill:#c9f
    classDef data fill:#fc9
    classDef database fill:#9cf
    classDef template fill:#fcf

    %% Click Events
    click Caddy "https://github.com/cedrickchee/skel/tree/main/scripts/production/Caddyfile"
    click Server "https://github.com/cedrickchee/skel/blob/main/cmd/api/main.go"
    click Routes "https://github.com/cedrickchee/skel/blob/main/cmd/api/routes.go"
    click Auth "https://github.com/cedrickchee/skel/blob/main/cmd/api/tokens.go"
    click Mid "https://github.com/cedrickchee/skel/blob/main/cmd/api/middleware.go"
    click Mailer "https://github.com/cedrickchee/skel/blob/main/internal/mailer/mailer.go"
    click Logger "https://github.com/cedrickchee/skel/blob/main/internal/jsonlog/jsonlog.go"
    click Validator "https://github.com/cedrickchee/skel/blob/main/internal/validator/validator.go"
    click Models "https://github.com/cedrickchee/skel/blob/main/internal/data/models.go"
    click Movies "https://github.com/cedrickchee/skel/blob/main/internal/data/movies.go"
    click Users "https://github.com/cedrickchee/skel/blob/main/internal/data/users.go"
    click Migrations "https://github.com/cedrickchee/skel/tree/main/migrations/"
    click Welcome "https://github.com/cedrickchee/skel/blob/main/internal/mailer/templates/user_welcome.tmpl"
    click Activation "https://github.com/cedrickchee/skel/blob/main/internal/mailer/templates/token_activation.tmpl"
    click Reset "https://github.com/cedrickchee/skel/blob/main/internal/mailer/templates/token_password_reset.tmpl"
    click Health "https://github.com/cedrickchee/skel/blob/main/cmd/api/healthcheck.go"
```
