# thilakreddyy/jntuh-backend architecture

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

- Interactive diagram: https://gitdiagram.com/thilakreddyy/jntuh-backend
- Repository: https://github.com/thilakreddyy/jntuh-backend

## Overview

##### Main Architectural Components
- API/HTTP Layer: Represented by FastAPI endpoints (see api/routes.py). This is the interface through which client requests enter the system.
- Service Layer: The business logic implemented in the various service modules (e.g., service/getAllResultService.py, service/notificationService.py, etc.) that process and transform data before interacting with data stores.
- Database Layer: Managed via the database directory and Prisma setup. This includes:
- PostgreSQL as the primary persistent datastore.
- ORM/migrations managed by Prisma (look at prisma/schema.prisma and corresponding migrations).
- Caching Layer: Redis is integrated for performance optimization (look into config/redisConnection.py).
- Messaging Layer: Uses RabbitMQ for event-driven data exchange (messaging/consumer.py and messaging/publisher.py).
- Additional Components:
- Scrapers: These modules (in the scrapers folder) handle data fetching and notifications.
- Utility Components: Helpers and logging (in the utils directory) that support overall system operations.
- Containerization and Deployment: Dockerfile, docker-compose.yml, and related files provide the infrastructure design for deployment.

##### Relationships and Interactions
- The API Layer receives HTTP requests and passes them to the Service Layer.
- The Service Layer performs necessary business logic and coordinates data retrieval and processing:
- It interacts with the Database Layer (using models and operations defined in database/models.py and database/operations.py).
- Caching interactions are made through Redis (config/redisConnection.py); typically, data is first checked/updated in the cache.
- Messaging operations: When events occur (like updates or notifications), the Service Layer publishes messages to RabbitMQ (using messaging/publisher.py) and possibly consumes messages (with messaging/consumer.py) to trigger further processing.
- The Scraper modules likely run separately (or scheduled via an external trigger) to fetch external data (e.g., result updates) and feed it into the system.

##### Architectural Patterns and Design Principles
- Layered Architecture: Separation of concerns into API, Service, Database, Caching, and Messaging layers.
- Microservice-like Components: Although it is a monolithic FastAPI app, the clear divisions (services, messaging, scrapers) allow for future decoupling if required.
- Asynchronous / Event-Driven Processing: RabbitMQ integration shows a design that supports asynchronous communications.
- Containerization: Docker file and Docker Compose file promote a containerized and portable deployment.

##### Technologies and Frameworks to Emphasize
- FastAPI for API handling.
- PostgreSQL (with Prisma for migrations) as the database.
- Redis for caching.
- RabbitMQ for messaging.
- Docker and Docker Compose for container deployment.
- Monitoring tools: Prometheus and Grafana.
- Python utilities and logging tools for support and maintenance.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External Client
    Client["Client/Users"]:::client

    %% API Layer
    subgraph "API Layer"
        API["API Layer (FastAPI)"]:::api
    end

    %% Service Layer
    subgraph "Service Layer"
        SERVICE["Service Layer (Business Logic)"]:::service
    end

    %% Database Layer
    subgraph "Database Layer"
        DBModels["DB Models"]:::database
        DBOps["DB Ops"]:::database
        PRISMA_SCHEMA["Prisma Schema"]:::database
        PRISMA_MIGRATIONS["Prisma Migrations"]:::database
    end

    %% Caching Layer
    CACHE["Caching (Redis)"]:::cache

    %% Messaging Layer
    subgraph "Messaging Layer"
        MSG_PUB["Message Publisher"]:::messaging
        MSG_CONS["Message Consumer"]:::messaging
    end

    %% Scrapers
    SCRAPERS["Scrapers (Data Integration)"]:::scrapers

    %% Utility Components
    UTILS["Utilities (Helpers & Logger)"]:::utils

    %% Infrastructure & Monitoring
    subgraph "Infrastructure & Monitoring"
        DOCKERFILE["Dockerfile"]:::infra
        DOCKER_COMPOSE["Docker Compose"]:::infra
        MONITORING["Monitoring (Prometheus & Grafana)"]:::monitor
    end

    %% Data Flow
    Client -->|"sends request"| API
    API -->|"calls"| SERVICE
    SERVICE -->|"queries/updates"| DBModels
    SERVICE -->|"queries/updates"| DBOps
    SERVICE -->|"uses"| PRISMA_SCHEMA
    SERVICE -->|"uses"| PRISMA_MIGRATIONS
    SERVICE -->|"caches"| CACHE
    SERVICE -->|"publishes"| MSG_PUB
    MSG_PUB -->|"triggers"| MSG_CONS
    SCRAPERS -->|"feeds data"| SERVICE
    SERVICE -->|"logs & assists"| UTILS

    %% Infrastructure Deployment Connections (dotted lines)
    DOCKERFILE ---|"deploys"| API
    DOCKER_COMPOSE ---|"orchestrates"| API
    MONITORING ---|"monitors"| SERVICE

    %% Click Events
    click API "https://github.com/thilakreddyy/jntuh-backend/blob/main/api/routes.py"
    click SERVICE "https://github.com/thilakreddyy/jntuh-backend/tree/main/service/"
    click DBModels "https://github.com/thilakreddyy/jntuh-backend/blob/main/database/models.py"
    click DBOps "https://github.com/thilakreddyy/jntuh-backend/blob/main/database/operations.py"
    click PRISMA_SCHEMA "https://github.com/thilakreddyy/jntuh-backend/blob/main/prisma/schema.prisma"
    click PRISMA_MIGRATIONS "https://github.com/thilakreddyy/jntuh-backend/tree/main/prisma/migrations/"
    click CACHE "https://github.com/thilakreddyy/jntuh-backend/blob/main/config/redisConnection.py"
    click MSG_PUB "https://github.com/thilakreddyy/jntuh-backend/blob/main/messaging/publisher.py"
    click MSG_CONS "https://github.com/thilakreddyy/jntuh-backend/blob/main/messaging/consumer.py"
    click SCRAPERS "https://github.com/thilakreddyy/jntuh-backend/tree/main/scrapers/"
    click UTILS "https://github.com/thilakreddyy/jntuh-backend/tree/main/utils/"
    click DOCKERFILE "https://github.com/thilakreddyy/jntuh-backend/tree/main/Dockerfile"
    click DOCKER_COMPOSE "https://github.com/thilakreddyy/jntuh-backend/blob/main/docker-compose.yml"
    click MONITORING "https://github.com/thilakreddyy/jntuh-backend/blob/main/prometheus.yml"

    %% Class Definitions for Styling
    classDef client fill:#FFD700,stroke:#DAA520,stroke-width:2px;
    classDef api fill:#ADD8E6,stroke:#00008B,stroke-width:2px;
    classDef service fill:#90EE90,stroke:#006400,stroke-width:2px;
    classDef database fill:#FFB6C1,stroke:#8B0000,stroke-width:2px;
    classDef cache fill:#EEE8AA,stroke:#BDB76B,stroke-width:2px;
    classDef messaging fill:#FFC0CB,stroke:#FF69B4,stroke-width:2px;
    classDef scrapers fill:#FFA500,stroke:#FF8C00,stroke-width:2px;
    classDef utils fill:#D8BFD8,stroke:#9400D3,stroke-width:2px;
    classDef infra fill:#E0FFFF,stroke:#008B8B,stroke-width:2px;
    classDef monitor fill:#F08080,stroke:#CD5C5C,stroke-width:2px;
```
