# pavansiddapuram/makerble-assessment architecture

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

- Interactive diagram: https://gitdiagram.com/pavansiddapuram/makerble-assessment
- Repository: https://github.com/pavansiddapuram/makerble-assessment

## Overview

##### Project type and purpose
- This is a monolithic RESTful API server for a hospital management system, written in Go.
- It exposes HTTP endpoints (Gin) for two user roles (receptionist, doctor), uses JWT for auth, GORM/MySQL for persistence, and provides Swagger UI for documentation.

##### File structure
- cmd/server/main.go – application entrypoint, loads config, runs migrations, starts Gin HTTP server.
- internal/config – reads .env and initializes the database connection.
- internal/middleware – JWT validation and role‐based access control.
- internal/handler – HTTP controllers organized by feature (auth, patient).
- internal/service – business logic layer (auth workflows, patient operations).
- internal/repository – data access layer (GORM queries for user and patient tables).
- internal/model – domain models reflecting DB schema.
- migrations – schema migrations code.
- docs – Swagger definitions (JSON/YAML) and generated docs.go.
- generate_hash.go – password hashing utility.
- internal/test – unit tests for patient operations.

##### README for additional insights
- Tech stack: Go 1.24, Gin web framework, GORM ORM, MySQL, JWT auth, Swagger UI.
- Two distinct endpoint groups with URL prefixes (/api/receptionist, /api/doctor).
- Requests flow through middleware, handlers, services, repositories.
- Uses .env for configuration and go migrations for schema setup.

a. Main components
– Clients: Swagger UI, cURL/Postman, browser
– API Server (Gin router)
– Auth subsystem (login endpoint, JWT token issuer, auth middleware)
– HTTP Handlers (receptionist controller, doctor controller)
– Service layer (auth service, patient service)
– Repository layer (user repo, patient repo)
– MySQL database
– Migrations tool
– Configuration (.env)
– Documentation (Swagger definitions)
b. Relationships and interactions
1) Client sends HTTP request → Gin router
2) Router invokes JWT middleware (if protected) → validates token
3) Validated request → appropriate handler
4) Handler calls service layer for business logic
5) Service calls repository to read/write via GORM → MySQL
6) Response bubbles back through handler → client
7) At startup: main.go reads .env → runs migrations → serves Swagger UI
c. Architectural patterns and principles
– Layered (Controller → Service → Repository)
– Separation of concerns (auth vs. business logic vs. data access)
– Dependency injection via config and function parameters
– Single binary monolith
d. Key technologies
– Gin (HTTP routing)
– jwt-go (authentication middleware)
– GORM (ORM)
– MySQL (relational DB)
– Swagger (API documentation)

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Clients" 
        style Clients stroke-dasharray: 5 5
        SwaggerUI["Swagger UI"]:::external
        Postman["Postman / cURL"]:::external
        Browser["Browser"]:::external
    end

    subgraph "Configuration & Migrations"
        Env[".env"]:::config
        ConfigLoader["Config Loader"]:::config
        MigrationTool["Migration Tool"]:::config
    end

    subgraph "API Server"
        Main["Main (cmd/server/main.go)"]:::compute
        Router["Gin Router"]:::compute
    end

    subgraph "Middleware"
        AuthMiddleware["AuthMiddleware (internal/middleware/auth.go)"]:::compute
    end

    subgraph "HTTP Handlers"
        AuthHandler["AuthHandler (login/logout)"]:::compute
        PatientHandler["PatientHandler (receptionist/doctor)"]:::compute
    end

    subgraph "Service Layer"
        AuthService["AuthService (internal/service/auth.go)"]:::compute
        PatientService["PatientService (internal/service/patient.go)"]:::compute
    end

    subgraph "Repository Layer"
        UserRepo["UserRepository (internal/repository/user.go)"]:::compute
        PatientRepo["PatientRepository (internal/repository/patient.go)"]:::compute
    end

    subgraph "Domain Models"
        UserModel["UserModel (internal/model/user.go)"]:::compute
        PatientModel["PatientModel (internal/model/patient.go)"]:::compute
    end

    DB["MySQL Database"]:::db

    subgraph "Documentation"
        SwaggerYAML["swagger.yaml"]:::docs
        SwaggerJSON["swagger.json"]:::docs
        DocsGen["Docs Generator (docs/docs.go)"]:::compute
        README["README.md"]:::docs
    end

    Util["Password Hash Utility (generate_hash.go)"]:::compute
    Tests["Patient Unit Tests (internal/test/patient_test.go)"]:::compute
    Modules["go.mod / go.sum"]:::docs

    %% Startup flow
    Env -->|loads| ConfigLoader
    ConfigLoader -->|provides DB connection & JWT secret| Main
    MigrationTool -->|runs migrations| Main
    Main -->|starts| Router
    Main -->|serves| DocsGen
    DocsGen --> SwaggerYAML
    DocsGen --> SwaggerJSON
    Main -->|init module| Modules

    %% Request flow
    SwaggerUI -->|HTTP Request| Router
    Postman -->|HTTP Request| Router
    Browser -->|HTTP Request| Router

    Router -->|Authenticate| AuthMiddleware
    AuthMiddleware -->|Validated| AuthHandler
    AuthHandler -->|calls| AuthService
    AuthService -->|hash call| Util
    AuthService -->|reads/writes| UserRepo
    UserRepo -->|uses| UserModel
    UserRepo -->|SQL| DB

    Router -->|Route| PatientHandler
    PatientHandler -->|calls| PatientService
    PatientService -->|reads/writes| PatientRepo
    PatientService -->|reads user| UserRepo
    PatientService -->|uses| Util
    PatientRepo -->|uses| PatientModel
    PatientRepo -->|SQL| DB

    %% Tests
    Tests --> PatientService
    Tests --> PatientRepo

    %% Docs
    README -->|documents| Main
    README -->|documents| Router
    README -->|documents| AuthHandler
    README -->|documents| PatientHandler

    %% Click events
    click Main "https://github.com/pavansiddapuram/makerble-assessment/blob/main/cmd/server/main.go"
    click ConfigLoader "https://github.com/pavansiddapuram/makerble-assessment/blob/main/internal/config/db.go"
    click Env "https://github.com/pavansiddapuram/makerble-assessment/blob/main/.env"
    click MigrationTool "https://github.com/pavansiddapuram/makerble-assessment/blob/main/migrations/migrate.go"
    click SwaggerYAML "https://github.com/pavansiddapuram/makerble-assessment/blob/main/docs/swagger.yaml"
    click SwaggerJSON "https://github.com/pavansiddapuram/makerble-assessment/blob/main/docs/swagger.json"
    click DocsGen "https://github.com/pavansiddapuram/makerble-assessment/blob/main/docs/docs.go"
    click Util "https://github.com/pavansiddapuram/makerble-assessment/blob/main/generate_hash.go"
    click AuthMiddleware "https://github.com/pavansiddapuram/makerble-assessment/blob/main/internal/middleware/auth.go"
    click AuthHandler "https://github.com/pavansiddapuram/makerble-assessment/blob/main/internal/handler/auth.go"
    click PatientHandler "https://github.com/pavansiddapuram/makerble-assessment/blob/main/internal/handler/patient.go"
    click AuthService "https://github.com/pavansiddapuram/makerble-assessment/blob/main/internal/service/auth.go"
    click PatientService "https://github.com/pavansiddapuram/makerble-assessment/blob/main/internal/service/patient.go"
    click UserRepo "https://github.com/pavansiddapuram/makerble-assessment/blob/main/internal/repository/user.go"
    click PatientRepo "https://github.com/pavansiddapuram/makerble-assessment/blob/main/internal/repository/patient.go"
    click UserModel "https://github.com/pavansiddapuram/makerble-assessment/blob/main/internal/model/user.go"
    click PatientModel "https://github.com/pavansiddapuram/makerble-assessment/blob/main/internal/model/patient.go"
    click Tests "https://github.com/pavansiddapuram/makerble-assessment/blob/main/internal/test/patient_test.go"
    click Modules "https://github.com/pavansiddapuram/makerble-assessment/blob/main/go.mod"
    click README "https://github.com/pavansiddapuram/makerble-assessment/blob/main/README.md"

    %% Styles
    classDef compute fill:#cce5ff,stroke:#333,stroke-width:1px
    classDef config fill:#ffe5b4,stroke:#333,stroke-width:1px
    classDef db fill:#c2f0c2,stroke:#333,stroke-width:1px
    classDef external fill:#ffffff,stroke:#000,stroke-dasharray: 5 5
    classDef docs fill:#f2f2f2,stroke:#333,stroke-width:1px
```
