dal-license-server/docs/ARCHITECTURE.md
djuka dc0114e4b7 Inicijalni commit: kompletna implementacija + dokumentacija + testovi
- Kompletna Go implementacija licencnog servera (19 Go fajlova)
- Klijentski API: activate, deactivate, validate
- Admin API: CRUD licence, stats, audit log
- Admin dashboard: htmx + Go templates
- RSA-2048 potpisivanje licencnih podataka
- Rate limiting i API key autentifikacija
- MySQL migracije i seed podaci (ESIR, ARV, LIGHT_TICKET)
- Unit testovi: keygen, crypto, model, middleware (24 testa)
- Dokumentacija: SPEC.md, ARCHITECTURE.md, SETUP.md, API.md, TESTING.md, README.md

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-04 07:42:25 +00:00

7.0 KiB

DAL License Server — Arhitektura

Dijagram sistema

┌─────────────────────────────────────────────────────┐
│                 DAL LICENSE SERVER                    │
│                 port: 8090                            │
│                                                      │
│  ┌──────────┐  ┌──────────┐  ┌──────────────────┐  │
│  │ Admin API │  │ Klijent  │  │ Admin Dashboard  │  │
│  │ (CRUD)   │  │ API      │  │ (htmx)           │  │
│  └──────────┘  └──────────┘  └──────────────────┘  │
│        │              │               │              │
│        └──────────────┼───────────────┘              │
│                       │                              │
│              ┌────────┴────────┐                     │
│              │   MySQL baza    │                     │
│              │  dal_license_db │                     │
│              └─────────────────┘                     │
│                                                      │
│  RSA-2048 Private Key (samo ovde, nikad ne izlazi)  │
└─────────────────────────────────────────────────────┘
        ▲               ▲               ▲
        │               │               │
   ┌────┴────┐    ┌────┴────┐    ┌────┴────────┐
   │  ESIR   │    │   ARV   │    │ Light-Ticket │
   │ klijent │    │ klijent │    │   klijent    │
   └─────────┘    └─────────┘    └──────────────┘
   Svaki ima RSA public key ugrađen u binary

Struktura projekta

dal-license-server/
├── cmd/server/main.go              — Entry point, MySQL konekcija, migracije
├── internal/
│   ├── config/config.go            — .env loading, DSN builder
│   ├── model/
│   │   ├── license.go              — Product, License, LicenseWithActivation
│   │   ├── activation.go           — Activation model
│   │   ├── audit.go                — AuditEntry model
│   │   └── request.go              — Request/Response strukture
│   ├── repository/
│   │   ├── license_repo.go         — License CRUD, product queries, stats
│   │   ├── activation_repo.go      — Activation CRUD, deactivate, force release
│   │   └── audit_repo.go           — Audit log insert/list
│   ├── service/
│   │   ├── license_service.go      — License CRUD biznis logika
│   │   ├── activation_service.go   — Activate, Deactivate, Validate, ForceRelease
│   │   ├── crypto_service.go       — RSA-2048 potpisivanje (SHA-256, PKCS1v15)
│   │   └── keygen.go               — Generisanje ključeva
│   ├── handler/
│   │   ├── client_handler.go       — POST /api/v1/activate, deactivate, validate
│   │   ├── admin_handler.go        — Admin CRUD API
│   │   ├── dashboard_handler.go    — Dashboard stranice, in-memory sesije
│   │   └── helpers.go              — writeJSON, writeError, clientIP
│   ├── middleware/
│   │   ├── auth.go                 — API key auth (X-API-Key header)
│   │   └── ratelimit.go            — In-memory sliding window rate limiter
│   └── router/router.go           — Sve rute
├── templates/
│   ├── layout/base.html            — Glavni layout sa navbar-om
│   └── pages/                      — login, dashboard, licenses, audit...
├── static/
│   ├── css/style.css               — CSS
│   └── js/htmx.min.js             — htmx biblioteka
├── crypto/
│   ├── private.pem                 — RSA-2048 privatni ključ (ne u git-u!)
│   └── public.pem                  — RSA javni ključ
├── migrations/
│   ├── 001_create_tables.sql       — products, licenses, activations, audit_log
│   └── 002_seed_products.sql       — ESIR, ARV, LIGHT_TICKET seed
└── .env                            — Konfiguracija (ne u git-u!)

Slojevi

1. Handler (HTTP)

Prima HTTP zahteve, parsira input, poziva servis, vraca JSON ili HTML response. Tri grupe:

  • ClientHandler — API za klijentske aplikacije (activate, deactivate, validate)
  • AdminHandler — REST API za admin operacije (CRUD licence, stats, audit)
  • DashboardHandler — htmx stranice za admin dashboard

2. Service (biznis logika)

  • LicenseService — Kreiranje licenci, keygen, validacija tipova, expiry kalkulacija
  • ActivationService — Aktivacija sa RSA potpisom, deaktivacija, online validacija, force release
  • CryptoService — RSA-SHA256 potpisivanje licencnog JSON-a

3. Repository (baza)

  • LicenseRepo — License i Product CRUD, filteri, statistike
  • ActivationRepo — Activation CRUD, deaktivacija, force release
  • AuditRepo — Insert i listanje audit log-a

4. Middleware

  • APIKeyAuth — Provera X-API-Key header-a za admin API
  • RateLimit — In-memory sliding window, per-IP, konfigurisani limiti

Baza podataka (MySQL)

Tabele

products          — Definicija proizvoda (ESIR, ARV, LIGHT_TICKET)
licenses          — Izdate licence sa limitima i feature-ima
activations       — Aktivacije licenci (machine fingerprint, hostname, OS)
audit_log         — Log svih akcija

Relacije

products 1 ──── N licenses
licenses 1 ──── N activations
licenses 1 ──── N audit_log

Kljucni indeksi

  • licenses.license_key — UNIQUE
  • activations (license_id, is_active) — Brza provera aktivnih aktivacija
  • audit_log (created_at) — Sortiranje po vremenu

Autentifikacija

Admin API

  • X-API-Key header sa API kljucem iz .env
  • Minimum 32 karaktera

Admin Dashboard

  • Username/password login (password iz .env)
  • In-memory session (cookie-based)

Klijentski API

  • Bez autentifikacije (javni endpointi)
  • Zastiteni rate limiting-om

Kripto

  • RSA-2048 — Potpisivanje licencnih podataka pri aktivaciji
  • SHA-256 — Hash za machine fingerprint
  • PKCS1v15 — Shema potpisa
  • Isti par kljuceva za sve proizvode
  • Private key samo na serveru, public key ugrađen u klijentske binary-je

Migracije

Pokrecu se automatski pri startu servera (runMigrations u main.go). DSN koristi multiStatements=true za izvrsavanje SQL fajlova sa vise naredbi.


Mart 2026