My name is Jelani (jeh-lah-nee)
We're going to learn domain modeling.
To practice those skills we will building functional prototype applications.
When prototyping, we'll touch on different software development concepts and technologies so you're familiar with the parts of the entire development process.
This is an experimental and new course.
We're trying more new things this quarter.
Inevitably, there will still be some rough edges and things that don't work well. I apologize in advance 🙏
This course is question-driven.
"This course will allow MMMs to bring usable prototypes to life, no matter their level of technical expertise"
"This course is not about finding one right answer, but elegant solutions to complex problems"
Domain modeling
Building prototypes
You
Key Learning Takeaways:
We're excited to get there!
Our goal is to achieve 95% of the learning of the original course:
in a much shorter time frame
with a lot less friction
"More and more major businesses and industries are being run on software and delivered as online services — from movies to agriculture to national defense.
Many of the winners are Silicon Valley-style entrepreneurial technology companies that are invading and overturning established industry structures.
Over the next 10 years, I expect many more industries to be disrupted by software, with new world-beating Silicon Valley companies doing the disruption in more cases than not."
— Marc Andreesen, "Why Software Is Eating the World" (2011)
✔
Uniform
Resource
Locator
(or the equivalents: click on a link, submit a form, tap on something, etc)
(get back information that is relevant and valuable to me)
(how the heck does this work?)
A row in a table
We're going to start with the data.
We (the developers) figure out the main things, or nouns, in our problem space and make a table for each.
We add columns to each table for each attribute of the thing we need to keep track of.
Our users create (or read, or update, or delete) rows.
We say "create, read, update, or delete" so often — these are the fundamental 4 operations that all user actions map to — that we abbreviate it to CRUD.
80%+ of the functionality of most SaaS applications is CRUD. This is what we will focus on learning how to build.
We will only store one value per cell.
A value can be a long blob of text, like a bio; but it can't be multiple bios for different people.
Okay, this is all pretty abstract. Let's look at some examples.
Lets examine an application that we'll build in class. It's a very simplified version of the iMDB (the Internet Movie Database).
Click around it for a minute and then try to imagine — if you had to design tables to store all of the information required to power that app, what would they be? What columns would they have? Think of questions.
id | title | desc | director_name | director_bio | director_dob |
---|---|---|---|---|---|
22 | Shawshank | ...(long) | Darabont | ...(long) | 28-Jan-1959 |
23 | Godfather | ...(long) | Coppola | ...(long) | 07-Apr-1939 |
26 | Godfather II | ...(long) | Coppola | ...(long) | 07-Apr-1939 |
28 | Dark Knight | ...(long) | Nolan | ...(long) | 30-Jul-1970 |
id | title | desc | director_name | director_bio | director_dob | actors |
---|---|---|---|---|---|---|
22 | Shawshank | ...(long) | Darabont | ...(long) | 28-Jan-1959 | Freeman, Robbins |
23 | Godfather | ...(long) | Coppola | ...(long) | 07-Apr-1939 | Pacino, Keaton |
26 | Godfather II | ...(long) | Coppola | ...(long) | 07-Apr-1939 | Pacino |
28 | Dark Knight | ...(long) | Nolan | ...(long) | 30-Jul-1970 | Freeman |
id | title | desc | director_name | director_bio | director_dob | actors | actor_bios? |
---|---|---|---|---|---|---|---|
22 | Shawshank | ...(long) | Darabont | ...(long) | 28-Jan-1959 | Freeman, Robbins |
😭 |
23 | Godfather | ...(long) | Coppola | ...(long) | 07-Apr-1939 | Pacino, Keaton |
😭 |
26 | Godfather II | ...(long) | Coppola | ...(long) | 07-Apr-1939 | Pacino | 😭 |
28 | Dark Knight | ...(long) | Nolan | ...(long) | 30-Jul-1970 | Freeman | 😭 |
id | name | bio | dob |
---|---|---|---|
12 | Darabont | ... | ... |
15 | Coppola | ... | ... |
18 | Nolan | ... | ... |
20 | Gerwig | ... | ... |
id | title | desc |
---|---|---|
22 | Shawshank | ... |
23 | Godfather | ... |
26 | Godfather II | ... |
28 | Dark Knight | ... |
12
15
15
18
id | name | bio | dob |
---|---|---|---|
12 | Darabont | ... | ... |
15 | Coppola | ... | ... |
18 | Nolan | ... | ... |
20 | Gerwig | ... | ... |
id | title | desc | director_id |
---|---|---|---|
22 | Shawshank | ... | |
23 | Godfather | ... | |
26 | Godfather II | ... | |
28 | Dark Knight | ... |
Primary Key
Foreign Key
Primary Key
id | name | bio |
---|---|---|
87 | Freeman | ... |
88 | Pacino | ... |
89 | Robbins | ... |
91 | Keaton | ... |
id | title | desc |
---|---|---|
22 | Shawshank | ... |
23 | Godfather | ... |
26 | Godfather II | ... |
28 | Dark Knight | ... |
id | name | bio |
---|---|---|
87 | Freeman | ... |
88 | Pacino | ... |
89 | Robbins | ... |
91 | Keaton | ... |
id | title | desc |
---|---|---|
22 | Shawshank | ... |
23 | Godfather | ... |
26 | Godfather II | ... |
28 | Dark Knight | ... |
id | movie_id | actor_id |
---|---|---|
48 | ||
49 | ||
53 | ||
57 | ||
59 |
22
22
23
23
26
87
89
88
88
91
Join Table
id | name | bio |
---|---|---|
87 | Freeman | ... |
88 | Pacino | ... |
89 | Robbins | ... |
91 | Keaton | ... |
id | title | desc |
---|---|---|
22 | Shawshank | ... |
23 | Godfather | ... |
26 | Godfather II | ... |
28 | Dark Knight | ... |
id | movie_id | actor_id | character |
---|---|---|---|
48 | 22 | 87 | Red |
49 | 22 | 89 | Andy |
53 | 23 | 88 | Michael |
57 | 23 | 91 | Kay |
59 | 26 | 88 | Michael |
id | movie_id | actor_id |
---|---|---|
48 | ||
49 | ||
53 | ||
57 | ||
59 |
22
22
23
23
26
87
89
88
88
91
Check assignment in Canvas
One-to-Many or Many-to-Many?
When you're deciding, ask yourself: "Can one x have many y? Can one y have many x?"
(The answer is usually: it depends on what you're building. Justify it.)
If One-to-Many, which table gets the foreign key column?
If Many-to-Many, what’s a good name for the join table?
On paper, we could write down more than one value in each box.
But in our database, we will only store one value per cell.
A value can be a long blob of text, like a bio; but it can't be multiple bios for different people.
For one thing, this will save a lot of trouble when it comes to retrieving the values later, and having to figure out where one value ends and the next one begins.
There are other important reasons to avoid multiple values in a single cell as well.
(Click down ( ⌄ ) in the bottom-right corner of this slide to see the tables .)
Directors | |||
---|---|---|---|
id | dob | name | bio |
17 | 1966 | Kátia Lund | |
5 | July 30, 1970 | Christopher Nolan | Best known for his cerebral... |
2 | April 7, 1939 | Francis Ford Coppola | He was born in 1939 in Detr... |
1 | January 28, 1959 | Frank Darabont | Three-time Oscar nominee Fr... |
Movies | |||
---|---|---|---|
id | title | year | director_id |
3 | The Godfather: Part II | 1974 | 2 |
6 | The Dark Knight | 2008 | 5 |
21 | City of God | 2002 | 17 |
2 | The Godfather | 1972 | 2 |
1 | The Shawshank Redemption | 1994 | 1 |
Actors | |||
---|---|---|---|
id | dob | name | bio |
271 | April 15, 1983 | Alice Braga | |
269 | June 8, 1970 | Seu Jorge | |
263 | May 21, 1983 | Alexandre Rodrigues | |
79 | May 25, 1976 | Cillian Murphy | Striking Irish actor Cillia... |
77 | September 7, 1977 | Monique Gabriela Curnen | Monique Gabriela Curnen is ... |
76 | March 21, 1958 | Gary Oldman | Gary Oldman, the son of a w... |
75 | November 16, 1977 | Maggie Gyllenhaal | Academy Award-nominated act... |
72 | April 4, 1979 | Heath Ledger | When a young, hunky 20 year... |
71 | January 30, 1974 | Christian Bale | Christian Charles Philip Ba... |
31 | August 17, 1943 | Robert De Niro | Robert De Niro, who is thou... |
27 | April 25, 1946 | Talia Shire | |
25 | January 5, 1946 | Diane Keaton | Diane Keaton was a Californ... |
24 | February 24, 1928 | Al Lettieri | Menacing looking Italian Am... |
20 | January 5, 1931 | Robert Duvall | Veteran actor and director ... |
17 | April 25, 1940 | Al Pacino | Known for his forceful dram... |
2 | June 1, 1937 | Morgan Freeman | With an authoritative voice... |
1 | October 16, 1958 | Tim Robbins | Born in West Covina, Califo... |
Roles | |||
---|---|---|---|
id | character_name | movie_id | actor_id |
306 | Angélica | 21 | 271 |
304 | Mané Galinha - Knockout Ned | 21 | 269 |
298 | Buscapé - Rocket | 21 | 263 |
85 | Scarecrow | 6 | 79 |
83 | Ramirez | 6 | 77 |
82 | Lucius Fox | 6 | 2 |
81 | Gordon | 6 | 76 |
80 | Rachel | 6 | 75 |
77 | Joker | 6 | 72 |
76 | Bruce Wayne | 6 | 71 |
36 | Connie Corleone | 3 | 27 |
34 | Vito Corleone | 3 | 31 |
33 | Kay | 3 | 25 |
32 | Tom Hagen | 3 | 20 |
31 | Michael | 3 | 17 |
27 | Connie | 2 | 27 |
25 | Kay Adams | 2 | 25 |
24 | Sollozzo | 2 | 24 |
20 | Tom Hagen | 2 | 20 |
17 | Michael Corleone | 2 | 17 |
2 | Ellis Boyd 'Red' Redding | 1 | 2 |
1 | Andy Dufresne | 1 | 1 |
Please visit this application.
You can sign in with any of the following (all of their passwords are password):
This is a simple clone of Twitter, but with photos. Itʼs a public social network where anyone can follow anyone (and they donʼt have to follow you back)
Accounts are all public.
If you had to design 2D tables to store all of the information required by Photogram, what would they look like?
Test your design by adding some "sample data" (a few users e.g. "alice", "bob"; a few photos; etc) to your tables, and verify that the following operations are possible:
After you've come up with a set of tables, compare your solution with the one below
(click down to see the tables). Are there any gaps in the data model?
How many followers does the user have?
Which photos has the user liked?
Which photos would be on the users' wall (the users' own posted photos)?
Which photos would be in the user's feed (the photos posted by the people that the user follows)?
If the user wanted to follow "carol", could we do it? How — i.e., which CRUD (Create, Read, Update, Delete) operation(s) would we perform, and on which table(s)? If not, how would you upgrade the database to allow for it?
If the user wanted to unlike a photo, could we do it? How? If not, how would you upgrade the database to allow for it?
If the user wanted to leave a comment of "Intense!" on a photo, could we do it? How? If not, how would you upgrade the database to allow for it?
Photos | ||||
---|---|---|---|---|
id | created_at | caption | image | user_id |
224 | 2016-11-01 | Bridge | bridge.jpg | 42 |
226 | 2016-08-25 | Horses | horses.jpg | 45 |
235 | 2016-07-22 | Tower | tower.jpg | 42 |
222 | 2016-07-01 | Aurora | aurora.jpg | 41 |
231 | 2016-05-05 | Squirel | squirrel.jpg | 41 |
236 | 2016-05-03 | Turtles | turtles.jpg | 45 |
233 | 2016-05-02 | Sun | sun.jpg | 43 |
234 | 2016-02-21 | Telescope | telescope.jpg | 45 |
228 | 2015-10-08 | Lightbulb | lightbulb.jpg | 42 |
227 | 2015-06-27 | Lake | lake.jpg | 44 |
221 | 2015-06-19 | Astronaut | astronaut.jpg | 44 |
225 | 2015-06-17 | Firebreather | firebreather.jpg | 43 |
229 | 2015-06-16 | Penguins | penguins.jpg | 44 |
230 | 2015-06-11 | Pluto | pluto.jpg | 42 |
223 | 2015-04-13 | Birds | birds.jpg | 44 |
232 | 2015-02-28 | Stained glass | stained_glass.jpg | 42 |
Users | ||
---|---|---|
id | username | |
41 | alice | alice@example.com |
42 | bob | bob@example.com |
43 | carol | carol@example.com |
44 | dave | dave@example.com |
45 | ellen | ellen@example.com |
Likes | ||
---|---|---|
id | photo_id | user_id |
439 | 235 | 41 |
441 | 222 | 45 |
442 | 231 | 44 |
443 | 231 | 42 |
444 | 236 | 41 |
445 | 236 | 44 |
446 | 236 | 43 |
447 | 233 | 45 |
448 | 233 | 44 |
449 | 234 | 43 |
450 | 228 | 45 |
451 | 228 | 44 |
452 | 228 | 42 |
453 | 227 | 45 |
455 | 225 | 41 |
456 | 225 | 43 |
457 | 225 | 44 |
458 | 225 | 42 |
459 | 230 | 43 |
460 | 230 | 41 |
461 | 230 | 44 |
462 | 223 | 41 |
463 | 232 | 44 |
Follow Requests | ||
---|---|---|
id | sender_id | recipient_id |
83 | 42 | 41 |
85 | 44 | 41 |
86 | 43 | 41 |
87 | 41 | 42 |
88 | 43 | 42 |
89 | 45 | 43 |
90 | 45 | 44 |
91 | 41 | 44 |
93 | 43 | 44 |
94 | 41 | 45 |
95 | 44 | 45 |