# thekodeking/go-pointy architecture

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

- Interactive diagram: https://gitdiagram.com/thekodeking/go-pointy
- Repository: https://github.com/thekodeking/go-pointy

## Overview

##### Client Layer
- External clients (mobile apps, web browsers) that make HTTP requests
- Supported HTTP methods (GET, POST)

##### API Layer
- Main HTTP Server (running on port 8080)
- Five main endpoints:
- Users Endpoints (/users)
- Posts Endpoints (/posts)
- Routing structure

##### Service Layer
- Two main service modules:
- User Service (appointy/user)
- Post Service (appointy/post)
- Password encryption service (MD5 hash)

##### Data Layer
- MongoDB Database
- Two main collections:
- Users Collection (storing user documents)
- Posts Collection (storing post documents)

- [Client Layer]
- ↓
- [API Layer]
- ↓
- [Service Layer]
- ↓
- [Data Layer]

##### Component Representations
- Use rectangles for services and modules

##### Specific Details

Client Layer:
- HTTP Clients (show supported methods: GET, POST)
- Example request paths

API Layer:
- Main Router (port 8080)
- User Endpoints:
- POST /users (Create User)
- GET /users/{id} (Get User)
- Post Endpoints:
- POST /posts (Create Post)
- GET /posts/{id} (Get Post)
- GET /posts/users/{id} (List User Posts)

Service Layer:
- User Service:
- User CRUD operations
- Password encryption/decryption
- Post Service:
- Post CRUD operations
- Timestamp handling

Data Layer:
- MongoDB Collections:
- Users (id, name, email, password)
- Posts (id, caption, imageUrl, timestamp, userId)

##### Additional Elements
- Data models for User and Post
- Security components (password encryption)
- Version information and technology stack details

##### Important Flows to Highlight
- User creation flow with password encryption
- Post creation flow with timestamp generation
- User-Post relationship in data queries

Remember to indicate that this is a backend-only service, and the client implementation is external to this system. Also, note any potential future additions like pagination and thread safety that are planned but not yet implemented.

## Diagram (Mermaid)

```mermaid
graph TB
    %% Style Definitions
    classDef client fill:#a8d1f0,stroke:#000
    classDef api fill:#90EE90,stroke:#000
    classDef service fill:#FFEB3B,stroke:#000
    classDef database fill:#E1BEE7,stroke:#000
    classDef config fill:#FFE0B2,stroke:#000

    %% Client Layer
    subgraph ClientLayer["Client Layer"]
        Client["HTTP Clients\n(GET, POST)"]:::client
    end

    %% API Layer
    subgraph APILayer["API Layer"]
        Server["HTTP Server\n(Port 8080)"]:::api
        
        subgraph UserEndpoints["User Endpoints"]
            CreateUser["POST /users"]:::api
            GetUser["GET /users/{id}"]:::api
        end
        
        subgraph PostEndpoints["Post Endpoints"]
            CreatePost["POST /posts"]:::api
            GetPost["GET /posts/{id}"]:::api
            ListUserPosts["GET /posts/users/{id}"]:::api
        end
    end

    %% Service Layer
    subgraph ServiceLayer["Service Layer"]
        UserService["User Service\nCRUD Operations"]:::service
        PostService["Post Service\nCRUD Operations"]:::service
        PasswordService["Password Encryption\n(MD5 Hash)"]:::service
    end

    %% Data Layer
    subgraph DataLayer["Data Layer"]
        MongoDB[(MongoDB Database)]:::database
        UsersCollection[("Users Collection\nid, name, email, password")]:::database
        PostsCollection[("Posts Collection\nid, caption, imageUrl,\ntimestamp, userId")]:::database
    end

    %% Connections
    Client --> Server
    Server --> CreateUser & GetUser & CreatePost & GetPost & ListUserPosts
    CreateUser & GetUser --> UserService
    CreatePost & GetPost & ListUserPosts --> PostService
    UserService --> PasswordService
    UserService --> UsersCollection
    PostService --> PostsCollection
    UsersCollection & PostsCollection --> MongoDB

    %% Click Events
    click Server "https://github.com/thekodeking/go-pointy/blob/main/main.go"
    click UserService "https://github.com/thekodeking/go-pointy/blob/main/appointy/user/user.go"
    click PostService "https://github.com/thekodeking/go-pointy/blob/main/appointy/post/post.go"

    %% Legend
    subgraph Legend["Legend"]
        ClientLegend["Client Component"]:::client
        APILegend["API Component"]:::api
        ServiceLegend["Service Component"]:::service
        DBLegend["Database Component"]:::database
    end
```
