How ssaavedraa/mjolnircore works
Project type and purpose
• Project name: MjolnirCore
• Type: Backend monolithic API service (no separate frontend)
• Purpose: Core framework for a CMS, exposes REST endpoints to manage Users, Companies, Products, Teams, and handles authentication, email invites, and data persistence.
High-level architectural pattern
• Layered (also maps to a hexagonal/clean architecture):
• Presentation/API layer (Gin router → Controllers)
• Application/Business layer (Services → Business rules)
• Data layer (Repositories → Database)
• Infrastructure/Adapters (Config, Utils, Interfaces to external services)
Main components
A. External Clients & Entry Points
• Client apps or CURL → HTTP requests to API
• Docker / Docker-Compose container for local dev
B. API Layer
• Gin HTTP Server (cmd/main.go)
• Router definitions (pkg/routes/routes.go)
C. Controllers (pkg/controllers)
• UserController, CompanyController, ProductController, TeamController
• Accept HTTP requests → orchestrate service calls
D. Services (pkg/services)
• Business logic per domain (e.g., user invite, product creation)
• Call into repositories, utils (e.g., JWT, bcrypt wrappers)
E. Repositories (pkg/repositories)
• Data access layer (CRUD operations)
• Uses config/db migration + database driver to persist models
F. Models & DTOs
• Domain models (pkg/models)
• Data Transfer Objects (pkg/dtos) for API contracts
G. Configuration & Infrastructure
• Config loader (pkg/config) reading .env, air.toml, docker-compose.yml
• Database migrations (pkg/config/db/migrations)
• Utility wrappers: bcrypt, JWT, ID Generator, Email sender (pkg/utils & pkg/interfaces)
• i18n static JSON files + Invite email HTML template
H. External Services
• SMTP Email provider
• (Optional future) Kafka producer interface
I. Database
• PostgreSQL or MySQL (configured via .env, managed via docker-compose)
Relationships & data flows
1. Client → HTTP request → Gin Router
2. Router → Controller → Service
3. Service → Repository → Database
4. Service → Utility/Interface adapters (e.g., JWT, bcrypt, email sender)
5. Response flows back in reverse: DB → Repo → Service → Controller → JSON → Client
Architectural patterns & design principles
• Single Responsibility per layer
• Dependency Injection via interface definitions (pkg/interfaces) + mockery for testing
• Separation of concerns: controllers do no DB work; repos know nothing about HTTP
• Config and environment isolation
• Hexagonal style: core logic in services, ports & adapters at edges
Detail to capture
• All top-level packages and their responsibilities
• Interface boundaries and how dependencies are injected
• Build & deployment artifacts (Dockerfile, docker-compose.yml)
• DB migration versioning (SQL scripts)
• Test harness: mocks directory indicates decoupled design