Sup Pratik! 👋 Here's a guide.
Getting started is easy. Just follow these steps:
-
Clone the repository to your local machine.
-
Set up your environment variables:
- Use
.env.localfor any env variables - Fill in the values (we'll explain more about this later).
- Use
-
Install node modules: Run
npm installin the root directory -
Start the Docker containers:
npm run docker:upThis command sets up your database and any other services we need.
-
Run database migrations:
npm run migrate:upThis sets up your database schema.
-
Start the development server:
npm run dev:server
Voila! Your server should now be running at http://localhost:3000. 🎉
We use JWT (JSON Web Tokens) for authentication. Here's what you need to know:
- When a user registers or logs in, they receive a JWT token.
- For authenticated requests, include this token in the
Authorizationheader:Authorization: Bearer your-jwt-token-here - Our server will automatically check this token for protected routes.
We've set up a nifty tool called tRPC Panel to help you explore and test the API:
- Make sure your server is running in development mode.
- Visit
http://localhost:3000/panelin your browser. - You'll see a list of all available API procedures.
- Click on a procedure, fill in the required inputs, and hit "Run" to test it out.
It's a great way to familiarize yourself with the API without writing any code!
- Entity files are in the
src/modulesdirectory. Each module (likeuser) has its own entity file (e.g.,user.entity.ts). - Our entities extend
CoreEntity, which provides common fields likeidand timestamps. - After modifying an entity, create a new migration:
npm run migrate:create - This uses the MikroORM CLI to generate a migration file based on your changes.
- Review the generated migration in the
src/migrationsdirectory. - Apply the migration with
npm run migrate:up.
We use envalid for type-safe environment variables:
- Environment variables are defined in the
env.tsfile. We usedotenvto connect the env.ts to your .env.* files (which has the actual data) - We access them using
$envthroughout the codebase. For example:import { $env } from './env'; console.log($env.DB_NAME);
- This approach gives us autocomplete and type checking for env variables!
If you're stuck or have questions, don't hesitate to reach out to Shrey.
Happy coding! 🚀👩💻👨💻