arvindsatya
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights New
    • Engagement control
    • Make a copy
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Note Insights Versions and GitHub Sync Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Make a copy Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       Owned this note    Owned this note      
    Published Linked with GitHub
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    --- layout: assignment title: "Assignment 4: Backend Design & Implementation" categories: assignments due_date: 2023-10-10 23:59:00 -0400 date: 2023-09-26 23:59:00 -0400 --- **Overview.** Congratulations! Over the last three weeks, you ideated and converged on a preliminary design for your social media app. Over the next four weeks, you'll realize your design as a working backend and frontend implementation. In this assignment, you'll focus on your app's backend (server-side) functionality. We will give you starter code that implements the functionality for some basic social media concepts including `User`, `WebSession`, `Post`, and `Friend`. Your job is to extend this code— adjusting these concepts as need be and adding additional concepts—so that you have a working implementation of the design you converged on in A3. <!-- However, as you'll no doubt experience, design is an ongoing and iterative process: as you begin to implement your ideas, you'll likely notice particular instances where your design may not be working out as you had intended. We encourage you to continue to refine and tweak your design throughout this period such that, after four weeks of implementation, you have produced a robust and usable app that provides meaningful and novel value for your target user population. --> As you work through this assignment, you are likely to find that translating your abstract design ideas into code surfaces issues with your design that you had not previously anticipated. For example, perhaps you made some assumptions about how a concept would be used, or perhaps there are some ambiguities in your design. Feel free to make any changes to your conceptual design that you feel are necessary, but take careful notes on changes that you make. These notes will inform a brief design reflection that you'll also submit, summarizing the changes you made and their rationales. <!-- An application's backend should be thought of as an interface in its own right—enabling future developers to build a variety of different frontend clients for Fritter (e.g., a website, a mobile app, etc), or even to use Fritter's services in other apps. As a result, implementation will continue to involve making design decisions. For instance, you are likely to find that translating your abstract ideas into code imposes a different set of pressures on your concepts than those you had considered thus far (i.e., end user needs or ethical considerations via VSD). How you account for these new design questions will be a central challenge of this assignment. --> **Purpose.** This assignment helps you practice: (a) formulating concept states with abstract data models; (b) translating abstract data models into concrete data representations; (c\) designing web service endpoints that conform to RESTful design principles; (d) implementing a client-server architecture using Node.js and Express. **Deadlines.** The final version of this assignment is due in just under two weeks' time (11:59pm on Tues Oct 10), but you must also submit an intermediate milestone midway through (11:59pm on Tues Oct 3) containing deliverables specified below. This milestone will only be graded for completion (i.e., have you submitted the required materials), and the assignment will be graded as a whole after the conclusion of the final deadline. **Slack days may be used only to extend the final deadline; you must turn your milestone in by the associated deadline.** ## Your Tasks 1. **Starter Code.** Fork this [GitHub repository](https://github.com/61040-fa23/backend-starter) by clicking the green "Use this template" button and selecting your _personal GitHub account_ (we cannot use the `61040-fa23` GitHub organization due to limitations with the free tier of the deployment platform, Vercel). This repository contains starter code for the assignment, and the `README.md` file describes its structure. Read through this file, follow the initial steps to install Node.js, Express and other necessary packages as well as register for the cloud-based services for MongoDB (your persistent data store) and Vercel (the deployment platform). Verify that you're able to get the backend service running locally. 2. **Starter Code Tutorial.** Read through [the tutorial](https://61040-fa23.github.io/pages/concept-implementations.html) we've published to familiarize yourself with how the starter code is structured, and how it implements ideas we have covered in class thus far. Our starter code wraps Express.js to eliminate some common headaches, and to better align with concept design. So we strongly encourage you to read this tutorial even if you have prior experience working with this tech stack. 3. **Data Modeling**. For each of the concepts in your design from A3, create an **abstract data model** of the state, comprising, for each concept, a list of state variables, each declared to be a set, or a relation from one set to another. Make each concept as **generic** as possible, and include in the concept header (after the concept name) any type parameters. Write a definition of your app as a **list of concepts**, with type parameters instantiated appropriately, and **draw a diagram** (like those we looked at [in lecture](https://61040-fa23.github.io/assets/lecture-notes/L7.pdf)) showing the state of the entire app, with contours showing which subdiagrams belong to which concepts. (With the exception of the diagram, all of this was included in the previous assignment. This task gives you an opportunity to refine your previous work.) 4. **Data Representation.** Convert each of your data models into concrete representations (in TypeScript, these are denoted with the keyword `interface`). Your representation should comprise, for each concept, one or more documents (more properly, document collections) that extend the `BaseDoc` provided in the starter code. 5. **RESTful Routes.** For each of your concepts, expose their actions as routes (in `server/routes.ts`) that follow the RESTful principles discussed in lecture. In particular, URL paths should correspond to different _resources_ and [HTTP methods](https://restfulapi.net/http-methods/) should indicate the _operations_ that can be performed on the resource. When designing and implementing your routes, consider how to make your web service robust to malformed or erroneous requests, or access violations. Remember, too, that your web service is itself an interface (i.e., for frontend developers). So, how might you use appropriate [HTTP status codes](https://en.wikipedia.org/wiki/List_of_HTTP_status_codes) and error messages (found in `server/concepts/errors.ts`) to communicate why a request was rejected? 6. **Synchronizations**. For each of your routes, define a controller function that supports the route by calling actions in your concepts. These functions are the implementations of your concept synchronization, along with some that support querying of concept states (often by combining queries of multiple concepts). In addition to implementing your routes in `server/routes.ts`, enumerate your routes in `public/util.ts` to automatically extend the lightweight frontend interface for testing your implementation. 8. **Deployment.** Deploy your code so that your backend service (and the provided GUI) can be accessed at a public URL. See the deployment guide in the `README.md` file for more instructions. 9. **Design Reflection.** Once you have a working backend service, reflect on how implementing it affected your original conceptual designs. What ambiguities or omissions did you discover in your designs that needed to be resolved? What design decisions did you make to resolve them, and what was your rationale? What alternatives did you consider, and why did you reject them? Would you have done anything differently? Write a succinct summary (i.e., no more than 300 words) of your reflection, and post it to your portfolio. ## Deliverables You have two weeks to work on this assignment. After two weeks (i.e., by 11:59pm on Tue Oct 10), you should have a fully implemented and deployed backend service that is accessible at a public URL. However, one week in (i.e., by 11:59pm on Tue Oct 3), we would like you to make a milestone submission to signal you are making adequate progress. This milestone will only be graded for completion (i.e., only to determine that you have submitted the required materials). Your milestone materials should include the following: * Complete abstract data models for _all_ concepts in your design posted to your portfolio. * A full, working implementation for _two_ concepts in your design beyond the four we provide you with. * An initial deployment of your web service to Vercel. It is fine if you do not get things to work completely or correctly by the milestone deadline, but we would like to see you make a good faith attempt at deployment. In past years, deployment has proven trickier than students anticipated, so we're eager to surface any problems early on so we can help you. * An initial outline of the design of your RESTful routes for your remaining concepts. This outline need only comprise function declarations in `server/routes.ts` and associated documentation/comments—you may leave the function bodies (i.e., the controllers/concept synchronizations) empty. To help make all parts of this assignment accessible, your portfolio should also provide prominent links to your backend code repository and deployed service. **Slack days may be used only to extend the final deadline; you must turn your milestone in by the associated deadline.** ## Submission For the milestone submission, follow the two-step process from previous assignments (i.e., post necessary material to your portfolio, and submit the [Google form](https://docs.google.com/forms/d/e/1FAIpQLSey6hPGEUilxzpOMjG_mI43wf83o0WxQP-6pO3pddS9U0e4WA/viewform) to confirm your Git commit hash). For the final submission, update or add new material to your portfolio. Then, submit the [Google form](https://docs.google.com/forms/d/e/1FAIpQLSey6hPGEUilxzpOMjG_mI43wf83o0WxQP-6pO3pddS9U0e4WA/viewform) **_twice_**: once with your portfolio URL and its Git commit hash, and second with your deployed backend service URL and the corresponding Git commit hash for your backend repo. ## Rubric | Component | Excellent | Satisfactory | Poor | ----- | ----- |----- |----- | | **Data models** | Simple and compact relational model of state for each concept that has no redundancies, and is sufficient to support actions | Relational model of state for each concept that is sufficient to support actions but may be needlessly complicated and include small redundancies | Models of state are insufficient to support actions or not clearly relational | | **Genericity** | Concepts are generic when possible, and genericity is clearly indicated by parameterized data models, and instantiated appropriately | Concepts are generic when possible and genericity is clearly indicated, but some opportunities for genericity are missing or instantiation is unclear | Concepts are not generic when they might be, or genericity is not clearly indicated | | **Functionality** | The deployed web service reflects all the functionality described by the operational principles and actions of your conceptual design | Most of the functionality described the operational principles and actions can be found in the deployed web service, but some actions or other parts are missing | Even the operational principles are not fully implemented in the deployed web service | | **RESTful Design** | All API endpoints are well-designed: paths map to resources and reflect appropriate hierarchical relationships, and HTTP methods indicate actions that can be performed resources | Most API endpoints follow RESTful principles, but some paths or HTTP methods are used in ways that might violate a developer's expectations about RESTful endpoints | Several API endpoints violate RESTful principles | | **Synchronizations** | Synchronizations and queries that implement routes make appropriate use of concept actions, including actions that act as validators | Routes are implemented using concept actions but may be more complex than needed | Routes are not implemented appropriately in terms of concepts | | **Robustness** | Where appropriate, API endpoints anticipate malformed or erroneous input, or access violations; informative error messages and corresponding HTTP status codes are returned | API endpoints largely account for erroneous input or access violations, but some missed opportunities to improve robustness. Error messages and status codes are returned, but could be better chosen or more informative | Several API endpoints are not robust against malformed input or access violations (e.g., web service may crash). Custom error messages and appropriate HTTP status codes are not used, or are uninformative | **Design Reflection** | A crisp and thoughtful summary of design issues that surfaced during implementation, discussing why they occurred, how they were resolved, and/or any tradeoffs or tensions involved | A clear identification of non-trivial design ambiguities or omissions, with a brief discussion of how they were addressed. However, design tradeoffs and/or tensions are not richly described. | A terse reflection that describes strawman issues or poorly explains design decisions ## Advice ### Concept design **Refining your concepts**. Make sure to use this opportunity to refine your concept design as your understanding of concepts has deepened. Perhaps you can focus the purpose of a concept more clearly, for example. Or perhaps you notice flaws that can be fixed, such as a concept having an [intrinsic dependency](https://essenceofsoftware.com/tutorials/concept-basics/dependency/#intrinsic-dependencies) on another concept (for example because it uses a type defined in the other concept). ### Abstract data models **Reviewing materials**. You may want to review the data model lecture slides for examples of state variable declarations and global data diagrams. See also the resource guide [article on data modeling](https://61040-fa23.github.io/pages/data-modeling.html), and the [tutorial on concept state](https://essenceofsoftware.com/tutorials/concept-basics/state/). **Relations over more than two sets**. You don't need to have relations that involve three or more sets, because you can always introduce a "tuple set." For example, to model the fact that a person has a salary at a company (a three-way relation), you could introduce a set of *Job* objects, each of which is mapped to a person, company and salary. **Multiplicities**. A relation can map an object in one set to any number of objects in another set: exactly one (in which case it represents a total function); zero or one (a partial function); or any number (a general relation). Use the keywords `one`, `lone` and `set` for these three cases. **Sequences**. There's no need for a special sequence constructor. A sequence of objects of some type `T` can be viewed as an ordering (a relation `T -> T`), or as a mapping from indexes to `T` (a relation Int -> T). **Instantiaton of generics**. In your application declaration, you should list each concept in the app, along with a list of types corresponding to its parameters. These types should be types that come from other concepts, and should be referred to as `C.T`, where `C` is the concept and `T` is the type. For example, if your app included a generic Favorite concept in which the items being favorited were the tweets from the Tweet concept, and a Follower concept in which the parties following and being followed were the users of the User concept, and the published items were tweets, you might write something like: ``` app Twitter concepts Tweet User Favorite [Tweet.Tweet] Follower [User.User, Tweet.Tweet] ``` ### Web Service Implementation **Collaboration and ChatGPT.** As a reminder, our [class guide](https://61040-fa23.github.io/guide) encourages you to collaborate with other students as long as you actually write up your work by yourself and note the set of people you collaborated with. Moreover, you're welcome to use ChatGPT (or other generative AIs) to help with this assignment; if you do so, however, you should include a brief note in your portfolio describing how you used it. **Third-party code.** Similarly, as per our class guide, you are free to use any third-party code (whether as libraries, [Node packages](https://www.npmjs.com) or code snippets) provided that it is publicly available and appropriately cited (see the [section on code](http://integrity.mit.edu/handbook/writing-code) in the MIT [handbook](https://integrity.mit.edu/) on academic integrity for more details). **Consult documentation.** [Express](https://expressjs.com) and [MongoDB](https://www.mongodb.com/docs/drivers/node/current/fundamentals/crud/) are both widely used packages, with extensive documentation that provide useful references. **Code quality.** While we will not be grading your code, we expect you to organize your code thoughtfully, with appropriate structure, names, comments, etc. If you write sloppy code, you will likely find it harder to achieve reliable functionality (which we _will_ be grading). **Code modularity.** Following the structure of the starter code, ensure that each concept is implemented in its own module, and that concept modules have no dependences on each other. **Keep detailed notes.** In our experience, it's often hard to look back on your design and implementation process and "un-see" the solution you've crafted. Once you're done with your implementation, your web service will feel like the only or most obvious way to address any design problems that cropped up. And, chances are, you will have a difficult time remembering the alternatives you had considered. Consider keeping a lightweight notebook to document your progress. This might comprise just a collection of bullet points that describe what you're currently working on, what issues you are hoping to address, why you believe an idea might work, and what limitations or problems you encounter along the way. You can then synthesize your design reflection from your notebook, and doing so will feel easier, more productive, and yield a more compelling reflection.

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully