diff --git a/cofounder/api/.gitignore b/cofounder/api/.gitignore index 18a2a5b..4bc8e0c 100644 --- a/cofounder/api/.gitignore +++ b/cofounder/api/.gitignore @@ -1,3 +1,2 @@ node_modules/ -db/ dump/ \ No newline at end of file diff --git a/cofounder/api/db/README.md b/cofounder/api/db/README.md new file mode 100644 index 0000000..e69de29 diff --git a/cofounder/api/db/index/README.md b/cofounder/api/db/index/README.md new file mode 100644 index 0000000..e69de29 diff --git a/cofounder/api/db/projects/README.md b/cofounder/api/db/projects/README.md new file mode 100644 index 0000000..e69de29 diff --git a/cofounder/api/db/storage/README.md b/cofounder/api/db/storage/README.md new file mode 100644 index 0000000..e69de29 diff --git a/cofounder/api/system/functions/db/postgres.js b/cofounder/api/system/functions/db/postgres.js new file mode 100644 index 0000000..893d940 --- /dev/null +++ b/cofounder/api/system/functions/db/postgres.js @@ -0,0 +1,132 @@ +import utils from "@/utils/index.js"; +import yaml from "yaml"; + +async function dbPostgresGenerate({context,data}) { + /* ;; DB:POSTGRES::GENERATE + make {DRD, db{schemas,seed} } details -> postgres exec commands to {create tables , insert seed examples} + + + out : ["db"] + */ + const { pm , db } = data + const { drd } = pm + // const {text , attachments} = details + const messages = [ + { + "role": "system", + "content": `- you are a genius Postgresql expert + +- your role is to write the POSTGRESQL commands that create the DB tables and seed the DB with a good amount of example seed entries, according to the provided details +- your answer should be in this format : + +\`\`\`postgresql +[... POSTGRESQL COMMANDS TO CREATE TABLES ...] +[... POSTGRESQL COMMANDS TO SEED THE DB ...] +\`\`\` + + +ask yourself: +* am i creating all the tables in the required formats ? +* am i seeding the database with enough data ? + +give a final, super comprehensive answer in valid, extend POSTGRESQL command to execute +which will be perfectly ready for production and pushed to prod to thousands of users instantly (in a nodejs + POSTGRES ) and work flawlessly + +--- + +important: +> when making seed data , if some field is meant to store an image url, use a https://picsum.photos/ url with a random seed +> important : for seed data, if some entry needs to store an image url, use a https://picsum.photos/ url instead of example.com !! +--- + +use snake_case for any naming you do + +--- + +very important : + > avoid any postgres-hardcoded methods ie. for generating UIDs etc... ; logic for that stuff will come from nodejs functions ! + > do not generate UUIDs or similar inside postgres ! logic for that stuff will come from nodejs functions ! + > in case of UUIds or similar, make them normal strings ! + +your reply should start with : "\`\`\`postgresql" and end with "\`\`\`" + +you will be tipped $99999 + major company shares for nailing it perfectly off the bat +you are a genius` + }, + { + "role": "user", + "content": `\`\`\`DRD:database-requirements-document +${drd} +\`\`\`` + }, + { + "role": "user", + "content": `\`\`\`DB:schemas +${yaml.stringify({ schemas: db.schemas })} +\`\`\`` + }, + /*db.seed && { + "role": "user", + "content": `\`\`\`DB:seed +${yaml.stringify({ schemas: db.seed })} +\`\`\`` + },*/ + { + "role": "user", + "content": `Generate the POSTGRES command in one single comprehensive answer +it is expected to be very comprehensive and detailed and cover all the provided details + +--- + +very important : + > avoid any postgres-hardcoded methods ie. for generating UIDs etc... or similar ; logic for that stuff will come from nodejs functions ! + > do not generate UUIDs or similar inside postgres ! that stuff will come from nodejs functions ! + > in case of UUIDs, make them normal strings and not generated inside postgres by postgres methods ! + + +> aim for it to work on any default light postgres without any extra configs or plugins ! +> only use basic primitives like numbers, strings, json, etc ... no uuid types or special types etc +> very important : only use basic primitives like numbers, strings, json, etc ... no uuid types or any special types etc ! very basic primitives only ! + +reply in \`\`\`postgresql\`\`\` + +you're a genius` + }, + ] + + const postgres = ( + await context.run({ + id: "op:LLM::GEN", + context, + data: { + model: `chatgpt-4o-latest`,//`gpt-4o`, + messages, + preparser: `backticks`, + parser: false, + } + }) + ).generated + + await context.run({ + id: "op:PROJECT::STATE:UPDATE", + context, + data: { + operation: { + id: "db:postgres", + }, + type: `end`, + content: { + key: "db.postgres", + data: postgres, + }, + } + }) + + return { db: { ...db, postgres } } +} + + +export default { + //"DB:POSTGRES::TABLES": dbPostgresTables, + "DB:POSTGRES::GENERATE": dbPostgresGenerate, +} diff --git a/cofounder/api/system/functions/db/schemas.js b/cofounder/api/system/functions/db/schemas.js new file mode 100644 index 0000000..2cfe210 --- /dev/null +++ b/cofounder/api/system/functions/db/schemas.js @@ -0,0 +1,146 @@ +import utils from "@/utils/index.js"; +import yaml from "yaml"; + +async function dbSchemasGenerate({context,data}) { + /* ;; DB:SCHEMAS::GENERATE + make {DRD} -> db {schemas} ;; specify that for auth tables, password not hashed ! for mockup + + + out : ["db"] + */ + + + const { pm } = data + const { prd, frd, fjmd, drd } = pm + // const {text , attachments} = details + const messages = [ + { + "role": "system", + "content": `- you are a genius Product Manager and DB designer + +- your role is to make the database schemas for the provided app in development's MVP +- your DB schemas should be comprehensive and cover EVERYTHING required by the app MVP, and nothing more - no shiny secondary features, but nothing less than 100% comprehensive for every single expected functionality in production + +- your answer should be in ~SQL-like format meant for Postgres, in this format : + +\`\`\`yaml +[TableName]: + - name: [columnName] + type: [ js-parseable types like String, Number, Boolean ...] + unique: [true || false] + nullable: [true || false] + default?: [...] + primaryKey?: [...] + foreignKey?: [{table : [...] , column : []}] + - [...] +[...] +\`\`\` + +- use a \`uid\` approach whenever possible rather than incremented Ids ; and make them normal strings ! +very important : + > avoid any postgres-hardcoded methods ie. for generating UIDs etc... ; logic for that stuff will come from nodejs functions ! + > do not generate UUIDs inside postgres ! that stuff will come from nodejs functions ! + +- your current role is to make use of the provided task and analysis in order to design a perfect DB schemas for the app's MVP + +try to outdo yourself by thinking of what might be omitted, +and design super critically in order to make a comprehensive work for this app's MVP DB schemas + +--- + +> note : if auth functionalities are present, use an architecture that will be compatible with a simple jwt auth system, which is very simply user and/or email strings(s) and password hash string ! + +> very important : for the current purpose of the DB Schemas design, the environment will be a mock prototype environment +do not bother with security details etc, have the DB schema requirements for the mock prototype + +> if some ie. media entry types requires some path (ie. images, media, ...), assume usage of urls not local + +> aim for it to work on any default light postgres without any extra configs or plugins ! + +--- + +use snake_case for any naming you do + +--- + +give a final, super comprehensive answer in strict, parseable YAML format, +which will be perfectly ready for production and pushed to prod to thousands of users instantly and work flawlessly +your reply should start with : "\`\`\`yaml" and end with "\`\`\`" + +you will be tipped $99999 + major company shares for nailing it perfectly off the bat +you are a genius` + }, + { + "role": "user", + "content": `\`\`\`PRD:product-requirements-document +${prd} +\`\`\`` + }, + /*{ + "role": "user", + "content": `\`\`\`FRD:features-requirements-document +${yaml.stringify(frd)} +\`\`\`` + }, + { + "role": "user", + "content": `\`\`\`FJMD:features-journeys-map-document +${yaml.stringify(fjmd)} +\`\`\`` + },*/ + { + "role": "user", + "content": `\`\`\`DRD:database-requirements-document +${drd} +\`\`\`` + }, + { + "role": "user", + "content": `Design the DB schemas in a comprehensive answer +it is expected to be very comprehensive and detailed ; in a VALID PARSEABLE YAML format + +very important : +- avoid any postgres-hardcoded methods ie. for generating UIDs etc... make them normal strings +- logic for that stuff will come from nodejs functions ! +- only use basic primitives like numbers, strings, json, etc ... no uuid types or special types etc +- very important : only use basic primitives like numbers, strings, json, etc ... no uuid types or any special types etc ! very basic primitives only ! + +you're a genius` + }, + ] + + const schemas = ( + await context.run({ + id: "op:LLM::GEN", + context, + data: { + model: `chatgpt-4o-latest`,//`gpt-4o`, + messages, + preparser: `backticks`, + parser: `yaml`, + } + }) + ).generated + + await context.run({ + id: "op:PROJECT::STATE:UPDATE", + context, + data: { + operation: { + id: "db:schemas", + }, + type: `end`, + content: { + key: "db.schemas", + data: schemas, + }, + } + }) + + return { db : { schemas } } +} + + +export default { + "DB:SCHEMAS::GENERATE": dbSchemasGenerate, +} diff --git a/cofounder/api/system/structure/nodes/db/postgres.yaml b/cofounder/api/system/structure/nodes/db/postgres.yaml new file mode 100644 index 0000000..7c48028 --- /dev/null +++ b/cofounder/api/system/structure/nodes/db/postgres.yaml @@ -0,0 +1,6 @@ +nodes: + DB:POSTGRES::GENERATE: + desc: make {DRB, db{schemas,seed} } details -> postgres exec commands to {create + tables , insert seed examples} + out: + - db diff --git a/cofounder/api/system/structure/nodes/db/schemas.yaml b/cofounder/api/system/structure/nodes/db/schemas.yaml new file mode 100644 index 0000000..3180895 --- /dev/null +++ b/cofounder/api/system/structure/nodes/db/schemas.yaml @@ -0,0 +1,6 @@ +nodes: + DB:SCHEMAS::GENERATE: + desc: make {DRB} -> db {schemas} ;; specify that for auth tables, password not + hashed ! for mockup + out: + - db