______  __  __   __  ______  ______  ______  ______  __  __    
/\  ___\/\ \/\ "-.\ \/\__  _\/\  == \/\  __ \/\  ___\/\ \/ /    
\ \  __\\ \ \ \ \-.  \/_/\ \/\ \  __<\ \  __ \ \ \___\ \  _"-.  
 \ \_\   \ \_\ \_\\"\_\ \ \_\ \ \_\ \_\ \_\ \_\ \_____\ \_\ \_\ 
  \/_/    \/_/\/_/ \/_/  \/_/  \/_/ /_/\/_/\/_/\/_____/\/_/\/_/

🚀 Backend Documentation

This documentation outlines the backend structure, API endpoints, project layout, and the process for updating and deploying the documentation. The backend is built with Rust Rocket for REST API handling, Diesel for database interaction, and PostgreSQL for persistent storage.


📚 Table of Contents

  1. 🌐 API
  2. 📮 Postman API Testing
  3. ⚡ Quick Start
  4. 🗄️ Database Schema
  5. 🗂️ Project Layout
  6. 🛠️ How to Add a New Module

🌐 API

🔐 Authentication

API Status Time Finished Link to Docs
/signup ✅ Complete 2024-12-07 2:00pm View Docs

📘 Account Management

API Status Time Finished Link to Docs
/account_create ✅ Complete 2024-12-07 3:10pm View Docs
/account_summary?email=<> ✅ Complete 2024-12-07 3:40pm View Docs
/delete_account?email=<>&account_name=<> ✅ Complete 2024-12-07 4:20pm View Docs

📦 Category Management

API Status Time Finished Link to Docs
/category_create ✅ Complete 2024-12-07 View Docs
/category_summary?email=<> ✅ Complete 2024-12-07 View Docs
/delete_category?email=<>&category_nickname=<> ✅ Complete 2024-12-07 View Docs
/category_update?email=<>&field=<field_to_update>&category_nickname=<>&new_value=<> ✅ Complete 2024-12-07 View Docs

💸 Transaction Management

API Status Time Finished Link to Docs
/add_trans ✅ Complete 2024-12-12 View Docs
/delete_trans?<delete_query..> ✅ Complete 2024-12-12 View Docs

📮 Postman API Testing

To explore and test the API endpoints, you can check out the Postman API documentation here (localhost version).


Quick Start

🔥 Clone the project

git clone https://github.com/FinTrak-Solutions/Backend.git

📦 Install Virtual Environment

cd Backend
virtualenv venv
source venv/bin/activate
pip3 install mkdocs

📁 Go to the Documentation Directory

cd Documentation

📝 Modify .md files in docs/

# Check and update locally
mkdocs serve
# Modify .md files in the docs/ folder

🚀 Build and Deploy

# Build and deploy
mkdocs build
mkdocs gh-deploy

🗄️ Database Schema

📘 Full details about the Database Schema can be found here.


🗂️ Project Layout

Here is the visualized structure of the src directory for the backend.

src
├── db.rs  -- 🗄️ Handles database setup and connections
├── handlers -- 🛠️ Controllers for handling business logic
│   ├── account_handler.rs  -- 📘 Handles account-related logic
│   ├── auth_handler.rs  -- 🔐 Handles user authentication logic
│   ├── category_handler.rs  -- 📦 Handles category-related logic
│   └── mod.rs  -- 📦 Module declaration file for handlers
├── main.rs  -- 🚀 The main entry point for the backend application
├── models -- 📦 Data models that map to the database schema
│   ├── account.rs  -- 📘 Account model
│   ├── category.rs  -- 📦 Category model
│   ├── mod.rs  -- 📦 Module declaration file for models
│   ├── transaction.rs  -- 💸 Transaction model
│   └── user.rs  -- 🔐 User model
├── routes -- 🌐 Defines the routes for the API endpoints
│   ├── account.rs  -- 📘 Account-related API routes
│   ├── auth.rs  -- 🔐 Authentication-related API routes
│   ├── category.rs  -- 📦 Category-related API routes
│   ├── mod.rs  -- 📦 Module declaration file for routes
│   └── transaction.rs  -- 💸 Transaction-related API routes
└── schema.rs  -- 📘 Automatically generated schema file for Diesel

🛠️ How to Add a New Module

Want to add a new module (like transaction or budget)? Follow these steps to ensure a consistent, clean structure.

1️⃣ Create the New Module

  1. Create a new folder in src/handlers/, src/models/, and src/routes/ for your new module.
   touch src/handlers/new_module_handler.rs
   touch src/models/new_module.rs
   touch src/routes/new_module.rs
  1. Add the new module to the mod.rs files in each of these folders.

src/handlers/mod.rs

pub mod new_module_handler;

src/models/mod.rs

pub mod new_module;

src/routes/mod.rs

pub mod new_module;

2️⃣ Define the Database Schema

  1. Add the table to the schema.rs file if it doesn't exist.
  2. Run Diesel to generate the schema for the new table:
   diesel migration generate create_new_module

3️⃣ Add Business Logic

  1. Add business logic to new_module_handler.rs.
  2. Implement CRUD functions like create, read, update, delete.

4️⃣ Register Routes

  1. Add routes for the new module in routes/new_module.rs.
  2. Use Rocket to define GET, POST, PUT, and DELETE endpoints.

Example Route in src/routes/new_module.rs:

use rocket::{get, post};

#[get("/new_module")]
pub fn get_new_module() -> &'static str {
    "Get all new module items"
}

#[post("/new_module")]
pub fn create_new_module() -> &'static str {
    "Create a new module item"
}

5️⃣ Update main.rs

  1. Add the new module's route to the main.rs file.
  2. Register the routes with Rocket.

src/main.rs

#[macro_use] extern crate rocket;

mod routes;

#[launch]
fn rocket() -> _ {
    rocket::build()
        .mount("/", routes![
            routes::new_module::get_new_module,
            routes::new_module::create_new_module,
        ])
}