Tutorial#
Build Your First Social Media App with Jaseci#
You'll build LittleX, a Twitter-like application, in just 200 lines of code. This tutorial guides you through each step, from installation to deployment.
What You'll Learn#
By the end of this tutorial, you'll understand how to:
- Store data in connected graph structures
- Navigate through relationships between data
- Add AI features to your application
- Deploy a working social media platform
What You'll Build: LittleX#
LittleX lets users:
- Create accounts and profiles
- Post messages (tweets)
- Follow other users
- View a personalized feed
Complete Code Preview#
Here's what you'll build - just 200 lines of code for a full social media platform:

graph TD
%% Root Nodes
Root1((Root1)):::root --> P1[Profile]:::profile
%% Tweets
P1 -->|Post| T1(Tweet):::tweet
P1 -->|Post| T2(Tweet):::tweet
%% Comments for P1's Tweet
T1 --> C1(Comment):::comment
C1 --> C1a(Comment):::comment
C1 --> C1b(Comment):::comment
graph TD
%% Subgraph 1: Root1
subgraph Cluster1[ ]
direction TB
Root1((Root1)):::root
Root1 --> P1[Profile]:::profile
P1 -->|Post| T1(Tweet):::tweet
P1 -->|Post| T2(Tweet):::tweet
T2 --> C4(Comment):::comment
Root1 -- Follow --> P2
Root1 -- Like --> T3
end
%% Subgraph 2: Root2
subgraph Cluster2[ ]
direction TB
Root2((Root2)):::root
Root2 --> P2[Profile]:::profile
P2 -->|Post| T3(Tweet):::tweet
P2 -->|Post| T4(Tweet):::tweet
T3 --> C1(Comment):::comment
C1 --> C1a(Comment):::comment
C1 --> C1b(Comment):::comment
Root2 --> T7(Tweet):::tweet
T7 --> C5(Comment):::comment
P2 -- Follow --> P3
end
%% Subgraph 3: Root3
subgraph Cluster3[ ]
direction TB
Root3((Root3)):::root
Root3 --> P3[Profile]:::profile
P3 -->|Post| T5(Tweet):::tweet
P3 -->|Post| T6(Tweet):::tweet
T5 --> C2(Comment):::comment
T6 --> C3(Comment):::comment
end
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 | |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 | |
Before You Start#
You'll need:
- 15 minutes to complete this tutorial
- Python 3.12 or later installed
- A text editor or IDE
Step 1: Install Jaseci#
Install the required libraries:
If the install is successful, you'll see:
You're ready to start building!
Step 2: Get the Code#
Clone the repository:
Install dependencies:
# Backend dependencies
pip install -r littleX_BE/requirements.txt
# Frontend dependencies
cd littleX_FE
npm install
cd ..
Understanding Jaseci's Building Blocks#
Jaseci uses three main components to build applications. Let's see how they work together:
File Structure: Three Files, One Application#
Jaseci organizes code into three files that work together automatically:
littleX.jac - What Your App Has#
littleX.impl.jac - How Your App Works#
littleX.test.jac - Proving It Works#
# Test functionality
test create_tweet {
root spawn create_tweet(content = "Hello World");
tweet = [root --> (?Profile) --> (?Tweet)][0];
check tweet.content == "Hello World";
}
Running Your Code#
Jaseci automatically links these files:
# Run the application
jac run littleX.jac
# Run tests
jac test littleX.jac
# Start API server
jac serve littleX.jac
1. Nodes: Store Your Data#
Nodes hold information. In LittleX:
- Profile nodes store user information
- Tweet nodes store message content
- Comment nodes store replies
Simple Example:
This creates a user object with a username.
2. Edges: Connect Your Data#
Edges create relationships between nodes. In LittleX:
- Follow edges connect users who follow each other
- Post edges connect users to their tweets
- Like edges connect users to tweets they liked
Simple Example:
This creates a "Follow" connection between users.
3. Walkers: Make Things Happen#
Walkers move through your graph and perform actions. They make your app interactive.
Simple Example:
This walker creates new tweets when users post messages.
Build LittleX Step by Step#
Now let's build your social media app by combining these pieces:
Step 3: Create User Profiles#
When someone signs up, we create their profile:
walker visit_profile {
can visit_profile with `root entry;
}
impl visit_profile.visit_profile {
visit [-->(`?Profile)] else {
new_profile = here ++> Profile();
grant(new_profile[0], level=ConnectPerm);
visit new_profile;
}
}
What this does: Creates a new profile if one doesn't exist, or visits the existing profile.
Step 4: Post Messages#
Users can create and share posts:
walker create_tweet(visit_profile) {
has content: str;
can tweet with Profile entry;
}
impl create_tweet.tweet {
embedding = vectorizer.fit_transform([self.content]).toarray().tolist();
tweet_node = here +>:Post():+> Tweet(content=self.content, embedding=embedding);
grant(tweet_node[0], level=ConnectPerm);
report tweet_node;
}
What this does: Creates a new tweet with the user's message and connects it to their profile.
Step 5: Follow Other Users#
Build your network by following others:
walker follow_request {}
impl Profile.follow {
current_profile = [root-->(`?Profile)];
current_profile[0] +>:Follow():+> self;
report self;
}
What this does: Creates a follow relationship between the current user and another user.
Step 6: View Your Feed#
See posts from people you follow:
walker load_feed(visit_profile) {
has search_query: str = "";
has results: list = [];
can load with Profile entry;
}
impl load_feed.load {
visit [-->(`?Tweet)];
for user_node in [->:Follow:->(`?Profile)] {
visit [user_node-->(`?Tweet)];
}
report self.results;
}
What this does: Collects tweets from the current user and everyone they follow.
Step 7: Run Your App#
Let's see your social media platform in action:
Start the Backend#
You should see:
Your backend is running!
Start the Frontend#
Open a new terminal:
You should see:
Your frontend is ready!
Try Your App#
-
Open your browser to:
http://localhost:5173 -
Test these features
- Create an account
- Post a message
- Follow someone
- Check your feed
If everything works, you've successfully built a social media platform!
Key Code Components#
Let's examine the main parts of your LittleX app:
Profile Node#
node Profile {
has username: str = "";
can update with update_profile entry;
can get with get_profile entry;
can follow with follow_request entry;
can un_follow with un_follow_request entry;
}
This stores user information and defines what users can do.
Tweet Node#
node Tweet {
has content: str;
has embedding: list;
has created_at: str = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S");
can update with update_tweet exit;
can delete with remove_tweet exit;
can like_tweet with like_tweet entry;
can remove_like with remove_like entry;
can comment with comment_tweet entry;
def get_info() -> TweetInfo;
can get with load_feed entry;
}
This stores tweet content and handles all tweet interactions.
Follow Implementation#
impl Profile.follow {
current_profile = [root-->(`?Profile)];
current_profile[0] +>:Follow():+> self;
report self;
}
This creates the follow relationship between users.
Try These Extensions#
Ready to add more features? Try implementing:
- Like system for posts
- User search by username
- Comment replies for deeper conversations
- Profile pages showing user-specific content
What You've Accomplished#
You've built a complete social media application. You now understand:
- Nodes for storing data
- Edges for connecting information
- Walkers for creating functionality
Jaseci's graph-based approach works well for social networks where relationships between data are essential.
Happy coding with Jaseci! 🚀