Skip to content

enchanteddev/BlazinglySAC

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

43 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

BlazinglySAC

BlazinglySAC is a high-performance backend for a Student Activity Center (SAC) application, built with Rust and the Axum web framework. It provides a robust and scalable platform for managing student clubs, events, announcements, and other student-related activities.

Features

  • User Authentication: Secure user registration and login using JWT (JSON Web Tokens) with email verification.
  • Profile Management: Users can view and manage their profiles.
  • Council and Club Management: Admins can create and manage councils and clubs.
  • Club Membership: Students can join and leave clubs.
  • Announcements and Events: Club heads can create, update, and delete announcements and events for their respective clubs.
  • Discussion Forum: Users can create threads and comments within clubs to foster discussions.
  • File Uploads: Users can upload files, which are stored securely.
  • Grievance System: Students can submit grievances, which can be reviewed by admins.

Tech Stack

  • Language: Rust
  • Web Framework: Axum
  • Database: PostgreSQL
  • Async Runtime: Tokio
  • Authentication: JWT (JSON Web Tokens)
  • Password Hashing: bcrypt
  • Database Toolkit: SQLx
  • Serialization/Deserialization: Serde

Architecture and Design Principles

BlazinglySAC is built with a focus on performance, scalability, and maintainability. The following are the core architectural and design principles:

  • Modularity: The codebase is organized into modules, each responsible for a specific domain (e.g., auth, club, announcements). This separation of concerns makes the codebase easier to understand, maintain, and scale.
  • Layered Architecture: The application follows a classic layered architecture, with a clear separation between the API layer (Axum handlers), the business logic layer, and the data access layer (using sqlx).
  • State Management: The application state, including the database connection pool and JWT secret, is managed in an AppState struct and shared across handlers using Axum's state management capabilities.
  • Authentication and Authorization: JWT-based authentication is implemented as middleware to protect routes. Authorization is handled within each handler by checking the user's role or ownership of a resource.
  • Error Handling: The application uses Axum's IntoResponse trait to handle errors and return appropriate HTTP status codes.
  • Asynchronous Programming: The entire application is built on top of the Tokio async runtime, enabling high concurrency and scalability.

API Endpoints

The following is a list of the available API endpoints, grouped by module:

Authentication

  • POST /auth/register: Register a new user.
  • POST /auth/login: Log in a user and receive a JWT.
  • GET /auth/whoami: Get the profile of the currently logged-in user.
  • GET /auth/verify/:token: Verify user email with token.
  • POST /auth/reverify/: Resend verification email.

Profile

  • GET /auth/whoami: Get the profile of the currently logged-in user.

Council

  • POST /council/create: Create a new council (admin only).
  • GET /council/list: Get a list of all councils.
  • POST /council/update: Update a council (admin only).

Club

  • GET /club/list: Get a list of all clubs.
  • GET /club/list_my: Get the clubs the user is a member of.
  • GET /club/list_my_applied: Get the clubs the user has applied to.
  • POST /club/create: Create a new club (admin only).
  • POST /club/update: Update a club.
  • POST /club/join: Apply to join a club.
  • GET /club/view_applications: View club join applications.
  • POST /club/accept_application: Accept a club join application.
  • GET /club/get_full: Get full details of a club.

Announcement

  • GET /announcement/public: Get public announcements.
  • GET /announcement/view: Get full announcements.
  • POST /announcement/create: Create a new announcement.

Event

  • GET /event/view: Get events.
  • POST /event/create: Create a new event.

Thread

  • GET /conversation/threads: Get threads.
  • POST /conversation/threads/new/: Create a new thread.
  • POST /conversation/threads/like/: Like a thread.

Comment

  • GET /conversation/comments: Get comments.
  • POST /conversation/comments/new/: Create a new comment.
  • POST /conversation/comments/like/: Like a comment.

File Upload

  • POST /media/upload/: Upload a file.
  • GET /media/view: View file.
  • GET /media/attachment: View attachment from ID.

Grievance

  • POST /grievance/create: Submit a new grievance.
  • GET /grievance/list: Get all grievances.

Database Schema

The database schema is managed using sqlx-cli and is defined in the migrations directory. The following are the main tables in the database:

  • user_profile: Stores user information.
  • council: Stores information about student councils.
  • club: Stores information about student clubs.
  • membership: Stores the relationship between users and clubs.
  • announcement: Stores announcements made by clubs.
  • event: Stores events organized by clubs.
  • thread: Stores threads for discussions within clubs.
  • comment: Stores comments on threads.
  • upload: Stores information about uploaded files.
  • website_grievances: Stores grievances submitted by users.
  • transportation: Stores transportation information.

For more details, please refer to the SQL files in the migrations directory.

Getting Started

To get a local copy up and running, follow these simple steps.

Prerequisites

  • Rust
  • PostgreSQL
  • sqlx-cli

Installation

  1. Clone the repo:
    git clone https://github.com/your_username/blazinglySAC.git
  2. Navigate to the project directory:
    cd blazinglySAC
  3. Install the required Rust tools:
    rustup component add rustfmt
  4. Set up the database:
    • Create a PostgreSQL database.
    • Create a .env file in the root of the project and add the DATABASE_URL and EMAIL_PASSWORD environment variables (see Environment Variables section below).
    • Run the database migrations:
      sqlx migrate run
  5. Run the application:
    cargo run

The application will be available at http://localhost:5000.

Environment Variables

The following environment variables are required to run the application. Create a .env file in the root of the project and add the following:

DATABASE_URL=postgres://user:password@host:port/database
EMAIL_PASSWORD=your_email_password

Build and Deploy

To build the application for production, run the following command:

cargo build --release

The release binary will be located in the target/release directory.

Contributing

Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.

If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue with the tag "enhancement".

  1. Fork the Project
  2. Create your Feature Branch (git checkout -b feature/AmazingFeature)
  3. Commit your Changes (git commit -m 'Add some AmazingFeature')
  4. Push to the Branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

About

SAC Backend for IIT Palakkad. But Blazingly Fast 🦀.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages