Skip to content

Code Documentation

Veevek Dave edited this page Apr 25, 2024 · 14 revisions

1. High-Level Overview

  1. Architecture

Architecture Pattern

  1. Model
  • The Model corresponds to the structure of the data stored in the database. It defines the type of data stored within the database. The model corresponds with the Controller and Database Component.
  1. Controller
  • Controllers act as an interface with the Model component to process all the business logic and incoming requests, manipulate data using the Model component and interact with the Views to render the final output.
  1. Migrations
  • Migrations are a way of versioning the database schema and managing its evolution over time.
  1. Jobs
  • Jobs, refer to operations or tasks that are executed outside the main flow of a web application, usually asynchronously
  • Examples - sending emails, processing files, scheduling tasks

Technology stack

  1. Swift image
  • Swift is an open-source programming language created by Apple for building apps for Apple devices, including iOS, Mac, Apple TV, and Apple Watch.
  • Read more:

https://developer.apple.com/swift/#:~:text=Swift%20is%20a%20powerful%20and,software%20that%20runs%20lightning%2Dfast.

  • Documentation:

https://www.swift.org/documentation/ image width="635"

  1. Vapor
  • Vapor is an open source web framework written in Swift. It can be used to create RESTful APIs, web apps, and real-time applications using WebSockets. In addition to the core framework, Vapor provides an ORM, a templating language, and packages to facilitate user authentication and authorization.[4]
  • Read more:

https://en.wikipedia.org/wiki/Vapor_(web_framework)

  • Vapor Documentation:

https://docs.vapor.codes/

  1. Fluent:
  • Fluent is an ORM framework for Swift. It takes advantage of Swift's strong type system to provide an easy-to-use interface for your database. Using Fluent centers around the creation of model types which represent data structures in your database. These models are then used to perform create, read, update, and delete operations instead of writing raw queries.
  • Documentation:

https://docs.vapor.codes/fluent/overview/

Code Organization

image Screenshot 2024-04-02 at 4 41 25 PM * It is a common practice to organize code into specific folders based on functionality. This practice promotes organization and consistency making it easier it navigate through especially when the codebase is large and has multiple components. In shuttle tracker, the code is divided into controllers, jobs, migrations and models.

Key Components

  • The shuttle tracker has the following controllers:
  • Analytics:
  1. Responsible for calculating the average number of users per bus at any given moment
  2. userIDs returns all the the unique IDs based on the shuttle
  3. BusAvg calculates the avg number of people boarded on a shuttle
  • AnalyticsEntries
  1. Registers routes on the index path of its provided routes builder
  2. Saves the analytics of e
  • AnalyticsEntry
  1. Registers routes for managing individual analytics entries.
  2. Returns all the entries
  • AndroidRedirects
  1. Registers routes for redirects to the Android app
  2. Redirects user to shuttle app on the android store
  • Announcement
  1. Registers routes for managing individual announcements.
  2. Read() receives all the announcements by ID
  3. Delete deletes the announcement based on announcementID
  • Announcements
  1. Structure that registers routes for managing individual announcements.
  2. Returns all announcements based on the ID
  3. Deletes the particular announcement based on ID
  • Bus
  1. A structure that registers routes for managing individual shuttle buses.
  2. Returns all shuttle locations
  3. Updates shuttle location
  4. Updates when a shuttle is boarded and left

Indepth Example

image image image image image image

API Endpoints

  • Analytics:

Endpoints: Parameters: Responses:

  • AnalyticsEntries

Endpoints: Parameters: Responses:

  • AnalyticsEntry

Endpoints: Parameters: Responses:

  • AndroidRedirects

Endpoints: Parameters: Responses:

  • Announcement

Endpoints: Parameters: Responses:

  • Announcements

Endpoints: Parameters: Responses:

  • Bus

Endpoints: Parameters: Responses:

  • Buses

Endpoints: Parameters: Responses:

  • DataFeed

Endpoints: Parameters: Responses:

  • Log

Endpoints: Parameters: Responses:

  • Logs

Endpoints: Parameters: Responses:

  • Milestone

Endpoints: Parameters: Responses: