Kodospace is now Uny of the Unyverse: a social networking application founded & developed by Emmanuel Moore (Immanuel Taylor) in 2020 using PHP/JS. The application underwent redevelopment on 03/31/2024 using various JavaScript technologies.
The development (Aviyon/Unyverse) team, coming in Q4 2024/Q1 2025, will assist in the continued development of Kodospace and the Kodoverse, making it available to the public.
- React.js
- Next.js
- Node.js
- TypeScript
- Tailwind CSS
- Sass
- Motoko
- Node.js
- Python
- PostgreSQL
- Node.js (version 14 or higher)
- Python (version 3.6 or higher)
- PostgreSQL (version 12 or higher)
- DFINITY Canister SDK
git clone https://github.com/the-real-kodoninja/kodospace.git
cd kodospaceNavigate to the client directory and install the necessary dependencies:
cd client
npm installCreate a .env.local file in the root of your project and add the necessary environment variables. An example .env.local file might look like this:
# .env.local
# PostgreSQL connection string
DATABASE_URL=postgresql://kodospace_user:yourpassword@localhost:5432/kodospace
# Node.js server port
PORT=3000-
Initialize a new PostgreSQL data directory:
initdb -D ~/pgdata -
Start the PostgreSQL server using the new data directory:
pg_ctl -D ~/pgdata start -
Create the PostgreSQL database and user:
createdb kodospace psql -d kodospace -c "CREATE USER kodospace_user WITH PASSWORD 'yourpassword';" psql -d kodospace -c "GRANT ALL PRIVILEGES ON DATABASE kodospace TO kodospace_user;"
-
Open the
psqlterminal:psql -U kodospace_user -d kodospace
-
Run the SQL script to set up the database and tables:
-- Create the posts table CREATE TABLE posts ( id SERIAL PRIMARY KEY, content TEXT NOT NULL, created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ); -- Insert dummy data into the posts table INSERT INTO posts (content) VALUES ('This is the first post.'), ('Here is another post.'), ('This is yet another post.'); -- Create the users table CREATE TABLE users ( id SERIAL PRIMARY KEY, username VARCHAR(255) NOT NULL, balance INTEGER DEFAULT 0 ); -- Insert dummy data into the users table INSERT INTO users (username, balance) VALUES ('user1', 100), ('user2', 200), ('user3', 300); -- Create the transactions table CREATE TABLE transactions ( id SERIAL PRIMARY KEY, user_id INTEGER REFERENCES users(id), amount INTEGER NOT NULL, created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ); -- Insert dummy data into the transactions table INSERT INTO transactions (user_id, amount) VALUES (1, 50), (2, -30), (3, 70);
Navigate to the client directory and start the development server:
npm run devThe application will be accessible at http://localhost:3000.
Navigate to the backend directory and start the Python backend service:
cd backend
python app.pyCreate a new Motoko project using the DFINITY SDK:
dfx new server
cd serverWhen prompted to select a backend language, choose "Motoko".
When prompted to select a frontend framework, choose "None".
When prompted to add extra features, you can leave them unchecked unless you need specific features.
Write your backend logic in the main.mo file located in the src/server/ directory. Here is an example of a simple Motoko actor:
import Debug "mo:base/Debug";
import Nat "mo:base/Nat";
import Text "mo:base/Text";
actor Kodospace {
// A simple user structure
type User = {
id: Nat;
username: Text;
balance: Nat;
};
// A mapping from user ID to User
stable var users: Trie.Trie<Nat, User> = Trie.empty();
// A counter for generating user IDs
stable var userIdCounter: Nat = 0;
// Register a new user
public func register(username: Text) : async User {
let newUser: User = {
id = userIdCounter;
username = username;
balance = 0;
};
users := Trie.put(users, userIdCounter, newUser);
userIdCounter += 1;
return newUser;
};
// Get user by ID
public query func getUser(id: Nat) : async ?User {
return Trie.find(users, id);
};
// Add tokens to a user's balance
public func addTokens(userId: Nat, amount: Nat) : async ?User {
let maybeUser = Trie.find(users, userId);
switch maybeUser {
case (?user) {
let updatedUser = { user with balance = user.balance + amount };
users := Trie.put(users, userId, updatedUser);
return ?updatedUser;
};
case null {
return null;
};
}
};
// Deduct tokens from a user's balance
public func deductTokens(userId: Nat, amount: Nat) : async ?User {
let maybeUser = Trie.find(users, userId);
switch maybeUser {
case (?user) {
if (user.balance < amount) {
return null;
};
let updatedUser = { user with balance = user.balance - amount };
users := Trie.put(users, userId, updatedUser);
return ?updatedUser;
};
case null {
return null;
};
}
};
// Greet function
public query func greet(name: Text) : async Text {
Debug.print("Hello, " # name # "!");
return "Hello, " # name # "!";
};
};Make sure to configure your project in the dfx.json file. Here's an example configuration:
{
"canisters": {
"server": {
"main": "src/server/main.mo",
"type": "motoko"
}
},
"networks": {
"local": {
"bind": "127.0.0.1:8000",
"type": "ephemeral"
}
},
"version": 1
}Start the DFINITY local replica and deploy your canister:
dfx start --background
dfx deployUpdate your client-side code to interact with the deployed Motoko backend. You can use the Internet Computer's JavaScript library (@dfinity/agent) to communicate with your canister.
- Install the
@dfinity/agentlibrary:
npm install @dfinity/agent- Update your client-side code to call the backend:
Here is an example of how to call the greet function from your client:
import { Actor, HttpAgent } from '@dfinity/agent';
import { idlFactory as kodospace_idl, canisterId as kodospace_id } from 'dfx-generated/server';
const agent = new HttpAgent();
const kodospace = Actor.createActor(kodospace_idl, { agent, canisterId: kodospace_id });
async function greet(name) {
const greeting = await kodospace.greet(name);
console.log(greeting);
}
greet('World');# Clone the repository
git clone https://github.com/the-real-kodoninja/kodospace.git
cd kodospace
# Install Node.js dependencies
cd client
npm install
# Set up environment variables
# Create a .env.local file in the client directory with the necessary variables
# Initialize and start PostgreSQL server
initdb -D ~/pgdata
pg_ctl -D ~/pgdata start
createdb kodospace
psql -d kodospace -c "CREATE USER kodospace_user WITH PASSWORD 'yourpassword';"
psql -d kodospace -c "GRANT ALL PRIVILEGES ON DATABASE kodospace TO kodospace_user;"
# Create the database and tables
psql -U kodospace_user -d kodospace
# Run the provided SQL script to create tables and insert dummy data
# Start the development server
npm run dev
# Run the Python backend service
cd backend
python app.py
# Set up the Motoko backend
dfx new server
cd server
dfx start --background
dfx deployFor any questions or support, please contact the-real-kodoninja.