# ahmadexe/prism-backend architecture

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

- Interactive diagram: https://gitdiagram.com/ahmadexe/prism-backend
- Repository: https://github.com/ahmadexe/prism-backend

## Overview

##### Project type and purpose
- PRISM is a backend‐centric, decentralized social‐media platform implemented as a suite of microservices.
- Its goal (per README) is to give users full control of their data via blockchain storage and to provide AI‐driven personalization without compromising privacy.
- The codebase shows four Go‐based services—auth, chats, jobs, posts—plus a gRPC definition for the auth service.

##### File structure
- Top‐level:
– grpc/auth: Protobuf definitions and generated Go stubs for the auth API
– services/{auth,chats,jobs,posts}: Four self‐contained microservices
- Each service follows a consistent layered layout:
– configs/: configuration loading
– data/: domain models
– handlers/: request handlers (business logic entry points)
– middlewares/: cross‐cutting concerns (e.g., authorization)
– repository|repositories/: persistence interfaces & implementations
– routes/: HTTP/gRPC route registration
– main.go: service bootstrap
- No frontend code here—this is strictly backend. External interactions include gRPC (auth) and likely HTTP REST for the other services.

##### README for additional insights
- Emphasizes blockchain for secure user data storage (an external component not directly in this repo)
- Mentions AI personalization (another external component or microservice)
- Includes a snippet on how to generate gRPC code for auth.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External Clients
    Clients["Clients\n(web/mobile)"]:::external

    %% API Gateway
    APIGateway[/API Gateway/]:::infra

    Clients --> APIGateway

    %% Auth Service Subgraph
    subgraph "Auth Service"
        direction TB
        AS_main["main.go"]:::service
        AS_configs["configs"]:::service
        AS_data["data"]:::service
        AS_handlers["handlers"]:::service
        AS_middlewares["middlewares"]:::service
        AS_repos["repositories"]:::service
        AS_routes["routes"]:::service
        AS_utils["utils"]:::service
        AS_main --> AS_configs --> AS_data --> AS_handlers --> AS_middlewares --> AS_repos --> AS_routes --> AS_utils
    end

    %% Auth gRPC Subgraph
    subgraph "Auth gRPC API"
        direction TB
        GRPC_def["auth.proto"]:::service
        GRPC_stub["auth.pb.go\nauth_grpc.pb.go"]:::service
        GRPC_main["main.go"]:::service
        GRPC_def --> GRPC_stub --> GRPC_main
    end

    %% Chats Service Subgraph
    subgraph "Chats Service"
        direction TB
        CH_main["main.go"]:::service
        CH_configs["configs"]:::service
        CH_data["data"]:::service
        CH_handlers["handlers"]:::service
        CH_middlewares["middlewares"]:::service
        CH_repo["repository"]:::service
        CH_routes["routes"]:::service
        CH_utils["utils"]:::service
        CH_main --> CH_configs --> CH_data --> CH_handlers --> CH_middlewares --> CH_repo --> CH_routes --> CH_utils
    end

    %% Jobs and Posts Services
    JobsService["Jobs Service"]:::service
    PostsService["Posts Service"]:::service

    %% External Systems & Infrastructure
    Blockchain["Blockchain Network"]:::external
    AIService["AI/ML Service"]:::external
    MessageBus[(Message Bus)]:::infra
    AuthDB[(Auth DB)]:::infra
    ChatDB[(Chats DB)]:::infra
    JobsDB[(Jobs DB)]:::infra
    PostsDB[(Posts DB)]:::infra

    %% Gateway to Services
    APIGateway -->|"gRPC /auth"| AS_main
    APIGateway -->|"REST /chats"| CH_main
    APIGateway -->|"REST /jobs"| JobsService
    APIGateway -->|"REST /posts"| PostsService

    %% Auth Service Interactions
    AS_main --> Blockchain
    AS_main --> AuthDB
    AS_main -->|"issues JWT tokens"| CH_main
    AS_main -->|"issues JWT tokens"| JobsService
    AS_main -->|"issues JWT tokens"| PostsService

    %% Service Databases
    CH_main --> ChatDB
    JobsService --> JobsDB
    PostsService --> PostsDB

    %% Event Bus
    CH_main --> MessageBus
    JobsService --> MessageBus
    PostsService --> MessageBus

    %% AI/ML Calls
    CH_main --> AIService
    JobsService --> AIService
    PostsService --> AIService

    %% Click Events for Auth Service
    click AS_main "https://github.com/ahmadexe/prism-backend/blob/main/services/auth/main.go"
    click AS_configs "https://github.com/ahmadexe/prism-backend/blob/main/services/auth/configs/configs.go"
    click AS_data "https://github.com/ahmadexe/prism-backend/blob/main/services/auth/data/auth_data.go"
    click AS_data "https://github.com/ahmadexe/prism-backend/blob/main/services/auth/data/follow_request.go"
    click AS_data "https://github.com/ahmadexe/prism-backend/blob/main/services/auth/data/search_request.go"
    click AS_data "https://github.com/ahmadexe/prism-backend/blob/main/services/auth/data/token_request.go"
    click AS_handlers "https://github.com/ahmadexe/prism-backend/blob/main/services/auth/handlers/auth_handlers.go"
    click AS_handlers "https://github.com/ahmadexe/prism-backend/blob/main/services/auth/handlers/search_handler.go"
    click AS_middlewares "https://github.com/ahmadexe/prism-backend/blob/main/services/auth/middlewares/authorization.go"
    click AS_repos "https://github.com/ahmadexe/prism-backend/blob/main/services/auth/repositories/auth_repo.go"
    click AS_routes "https://github.com/ahmadexe/prism-backend/blob/main/services/auth/routes/auth_router.go"
    click AS_utils "https://github.com/ahmadexe/prism-backend/blob/main/services/auth/utils/auth_utils.go"

    %% Click Events for Auth gRPC API
    click GRPC_def "https://github.com/ahmadexe/prism-backend/blob/main/grpc/auth.proto"
    click GRPC_stub "https://github.com/ahmadexe/prism-backend/blob/main/grpc/auth/generated/auth.pb.go"
    click GRPC_stub "https://github.com/ahmadexe/prism-backend/blob/main/grpc/auth/generated/auth_grpc.pb.go"
    click GRPC_main "https://github.com/ahmadexe/prism-backend/blob/main/grpc/auth/main.go"

    %% Click Events for Chats Service
    click CH_main "https://github.com/ahmadexe/prism-backend/blob/main/services/chats/main.go"
    click CH_configs "https://github.com/ahmadexe/prism-backend/blob/main/services/chats/configs/configs.go"
    click CH_data "https://github.com/ahmadexe/prism-backend/blob/main/services/chats/data/conversation.go"
    click CH_data "https://github.com/ahmadexe/prism-backend/blob/main/services/chats/data/message.go"
    click CH_handlers "https://github.com/ahmadexe/prism-backend/blob/main/services/chats/handlers/chat_handler.go"
    click CH_middlewares "https://github.com/ahmadexe/prism-backend/blob/main/services/chats/middlewares/authorization.go"
    click CH_repo "https://github.com/ahmadexe/prism-backend/blob/main/services/chats/repository/chat_repo.go"
    click CH_routes "https://github.com/ahmadexe/prism-backend/blob/main/services/chats/routes/chat_router.go"
    click CH_utils "https://github.com/ahmadexe/prism-backend/blob/main/services/chats/utils/utils.go"

    %% Click Events for Jobs and Posts Services
    click JobsService "https://github.com/ahmadexe/prism-backend/blob/main/services/jobs/main.go"
    click PostsService "https://github.com/ahmadexe/prism-backend/blob/main/services/posts/main.go"

    classDef service fill:#cce5ff,stroke:#004085,color:#004085
    classDef external fill:#d4edda,stroke:#155724,color:#155724
    classDef infra fill:#fff3cd,stroke:#856404,color:#856404
```
