# spo-iitk/ras-backend architecture

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

- Interactive diagram: https://gitdiagram.com/spo-iitk/ras-backend
- Repository: https://github.com/spo-iitk/ras-backend

## Overview

##### Project Type & Purpose
- This is a backend microservice application (“Recruitment Automation System”) for managing placements at IIT Kanpur.
- It exposes multiple services (Auth, Student, Company, Recruitment Cycle (RC), Application) running on distinct ports behind an Nginx reverse proxy.
- It uses Go (Gin + GORM), PostgreSQL (one database per service), Docker, and Nginx, with inter-service IPC (future gRPC).

##### File-Structure & Architectural Patterns
- Top-Level Directories:
- cmd/ – entry-points for each service (admin, auth, company, ras, student, verification, etc.)
- auth/, student/, company/, rc/, application/, ras/ – service codebases, each with router.go, config.go, model.go, DB adapters, handlers.
- container/ – Dockerfile, init.sql, nginx.conf for deployment.
- config/, constants/, middleware/, util/ – shared configuration, constants (roles), cross-cutting middleware.
- mail/ – mail-service integration.
- Pattern: Microservices, each with its own database schema under service/model.go. Services communicate via HTTP (internal IPC), proxied by Nginx.
- Deployment: Docker Compose orchestrates containers, init.sql bootstraps databases, nginx.conf routes incoming API calls.

##### Key Insights from README
- Five microservices: Auth, Student, Company, Recruitment Cycle (RC), Application.
- Each has its own PostgreSQL database & user (created via container/init.sql).
- Services run on distinct ports; Nginx reverse proxy directs requests based on URL paths.
- Mail and Google Calendar integrations use secrets (secret.yml, GCP credentials).

##### Essential Details
- Ports or base-paths (e.g., /auth/* → Auth Service).
- Database schemas reside per service (model.go).
- Docker network—services and Nginx communicate over an internal Docker bridge.

## Diagram (Mermaid)

```mermaid
flowchart TD
    Client["Client"]:::external
    Nginx["Nginx Reverse Proxy"]:::service

    Client -->|HTTP| Nginx

    subgraph "Microservices"
        subgraph "Auth Service"
            AuthService["Auth Service\n(Gin + GORM)"]:::service
            AuthDB["Postgres DB"]:::db
        end
        subgraph "Student Service"
            StudentService["Student Service\n(Gin + GORM)"]:::service
            StudentDB["Postgres DB"]:::db
        end
        subgraph "Company Service"
            CompanyService["Company Service\n(Gin + GORM)"]:::service
            CompanyDB["Postgres DB"]:::db
        end
        subgraph "Recruitment Cycle Service"
            RCService["RC Service\n(Gin + GORM)"]:::service
            RCDB["Postgres DB"]:::db
        end
        subgraph "Application Service"
            AppService["Application Service\n(Gin + GORM)"]:::service
            AppDB["Postgres DB"]:::db
        end
    end

    Nginx -->|"/auth/*"| AuthService
    Nginx -->|"/student/*"| StudentService
    Nginx -->|"/company/*"| CompanyService
    Nginx -->|"/rc/*"| RCService
    Nginx -->|"/application/*"| AppService

    AuthService -->|reads\/writes| AuthDB
    StudentService -->|reads\/writes| StudentDB
    CompanyService -->|reads\/writes| CompanyDB
    RCService -->|reads\/writes| RCDB
    AppService -->|reads\/writes| AppDB

    MailService["Mail SMTP Service"]:::external
    GoogleCal["Google Calendar API"]:::external

    AuthService -->|sends emails| MailService
    StudentService -->|sends emails| MailService
    CompanyService -->|sends emails| MailService
    RCService -->|sends emails| MailService
    AppService -->|sends emails| MailService

    StudentService -.->|pushes calendar events| GoogleCal
    CompanyService -.->|pushes calendar events| GoogleCal
    RCService -.->|pushes calendar events| GoogleCal
    AppService -.->|pushes calendar events| GoogleCal

    Shared["Shared Modules\n(config, constants,\nmiddleware, util)"]:::shared

    AuthService --> Shared
    StudentService --> Shared
    CompanyService --> Shared
    RCService --> Shared
    AppService --> Shared

    subgraph "Deployment"
        DockerCompose["docker-compose.yml"]:::shared
        Dockerfile["container/Dockerfile"]:::shared
        InitSQL["container/init.sql"]:::shared
        Scripts["scripts/"]:::shared
    end

    DockerCompose --> Nginx
    DockerCompose --> AuthService
    DockerCompose --> StudentService
    DockerCompose --> CompanyService
    DockerCompose --> RCService
    DockerCompose --> AppService

    AuthService -->|shell init| Scripts
    StudentService -->|shell init| Scripts
    CompanyService -->|shell init| Scripts
    RCService -->|shell init| Scripts
    AppService -->|shell init| Scripts

    click Nginx "https://github.com/spo-iitk/ras-backend/blob/main/container/nginx.conf"
    click DockerCompose "https://github.com/spo-iitk/ras-backend/blob/main/docker-compose.yml"
    click Dockerfile "https://github.com/spo-iitk/ras-backend/tree/main/container/Dockerfile"
    click InitSQL "https://github.com/spo-iitk/ras-backend/blob/main/container/init.sql"
    click AuthService "https://github.com/spo-iitk/ras-backend/tree/main/auth/"
    click StudentService "https://github.com/spo-iitk/ras-backend/tree/main/student/"
    click CompanyService "https://github.com/spo-iitk/ras-backend/tree/main/company/"
    click RCService "https://github.com/spo-iitk/ras-backend/tree/main/rc/"
    click AppService "https://github.com/spo-iitk/ras-backend/tree/main/application/"
    click MailService "https://github.com/spo-iitk/ras-backend/tree/main/mail/"
    click Shared "https://github.com/spo-iitk/ras-backend/tree/main/config/"
    click Shared "https://github.com/spo-iitk/ras-backend/blob/main/constants/role.go"
    click Shared "https://github.com/spo-iitk/ras-backend/tree/main/middleware/"
    click Shared "https://github.com/spo-iitk/ras-backend/tree/main/util/"
    click Scripts "https://github.com/spo-iitk/ras-backend/tree/main/scripts/"
    click Scripts "https://github.com/spo-iitk/ras-backend/blob/main/scripts/createDB.sh"
    click Scripts "https://github.com/spo-iitk/ras-backend/blob/main/scripts/production.sh"

    classDef service fill:#D6EAF8,stroke:#1B4F72,stroke-width:2px
    classDef db fill:#D5F5E3,stroke:#145A32,stroke-width:2px
    classDef external fill:#E5E8E8,stroke:#566573,stroke-width:2px
    classDef shared fill:#FCF3CF,stroke:#B7950B,stroke-width:2px
```
