Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/Avendaosander/Plataforma-social/llms.txt

Use this file to discover all available pages before exploring further.

Plataforma Social persists all of its data — users, posts, comments, ratings, and follower relationships — in a MySQL database managed through Prisma ORM. The Prisma schema lives at server/prisma/schema.prisma and uses the mysql provider. Before starting the server for the first time you need a running MySQL instance, a dedicated database, and a successful migration run.

Requirements

  • MySQL 8+ running locally (e.g. via Homebrew, Docker, or a native installer) or hosted remotely (e.g. PlanetScale, Railway, or AWS RDS).
  • Node.js 18+ with the server dependencies installed (npm install inside server/).
  • A DATABASE_URL value configured in server/.env — see the Environment Variables page for the correct format.

Setup steps

1

Create the MySQL database

Connect to your MySQL instance and create a dedicated database for the project. The name can be anything — plataforma_social is used throughout this guide.
CREATE DATABASE plataforma_social;
2

Set DATABASE_URL in server/.env

Open (or create) server/.env and add your connection string, replacing the placeholder values with your actual MySQL credentials and host.
server/.env
DATABASE_URL="mysql://root:password@localhost:3306/plataforma_social"
3

Generate the Prisma client

From inside the server/ directory, run the generate script to compile the Prisma client from your schema. You must re-run this step any time you modify schema.prisma.
npm run generate
This executes npx prisma generate and writes the typed client into node_modules/@prisma/client.
4

Run the initial migration

Apply the initial migration to create all tables in your database:
npm run migrate
This runs npx prisma migrate dev --name init, which reads the SQL in server/prisma/migrations/20240611205243_init/migration.sql, applies it to the database, and records the migration in the _prisma_migrations table. On subsequent schema changes you can run the same command with a new --name value.

Available npm scripts

All database-related commands (and the other server lifecycle scripts) are defined in server/package.json:
ScriptCommandPurpose
npm run generatenpx prisma generateRegenerates the Prisma client after schema changes
npm run migratenpx prisma migrate dev --name initApplies pending migrations to the development database
npm run devnodemonStarts the dev server with hot-reload via ts-node/esm (config: server/nodemon.json)
npm run buildtscCompiles TypeScript source to dist/
npm run startnpm run build && node dist/index.jsBuilds then starts the production server

Database schema overview

The schema defines eight models across server/prisma/schema.prisma. Every model uses a UUID primary key generated with @default(uuid()).
ModelDescription
UserPlatform account. Stores email (unique), username (unique), bcrypt-hashed password, optional bio, and avatar URL.
SettingOne-to-one privacy and notification preferences per user. Controls profile visibility and in-app/email notification toggles.
PostA shared UI component entry authored by a User. Contains a title, description, and timestamps.
CommentA text comment left by a User on a Post.
TechnologyA named technology tag (e.g. “React”, “Tailwind”). Names are globally unique.
StackJoin table linking a Post to one or more Technology entries. Composite primary key (idPost, idTechnology).
RatingA numeric (Float) rating given by a User to a Post.
FollowerDirected follow relationship between two User records. Composite primary key (idFollower, idFollowing).

Cascade behavior

Most child records are configured with onDelete: Cascade, meaning they are automatically removed when their parent is deleted:
  • Deleting a User cascades to: Setting, Post, Comment, Rating.
  • Deleting a Post cascades to: Comment, Stack, Rating.
  • The Stack join table also cascades on Technology deletion.
  • Follower records use RESTRICT — a user with followers or following relationships cannot be deleted until those rows are removed first.
The exact foreign-key constraints are defined in the initial migration file at server/prisma/migrations/20240611205243_init/migration.sql. You can inspect that file to see the raw ALTER TABLE … ADD CONSTRAINT statements applied to MySQL.

Resetting the database

If you need to start completely fresh — for example, to resolve a corrupted migration state — drop and recreate the database in MySQL, then run the migration again:
DROP DATABASE plataforma_social;
CREATE DATABASE plataforma_social;
npm run migrate
Dropping the database permanently deletes all data. Only do this in a local development environment. Never run these commands against a staging or production database.

Build docs developers (and LLMs) love