Skip to content

Latest commit

Β 

History

History
135 lines (107 loc) Β· 4.07 KB

File metadata and controls

135 lines (107 loc) Β· 4.07 KB

COC-API

This repository contains the common Express.js API for the backends of our Coding Club's websites , backed by PostgreSQL (via Prisma) and Supabase storage. We’re using Bun as our runtime.

πŸ“‚ Folder Structure

/
β”œβ”€β”€ prisma/                  # Prisma schema and migration files
β”‚   β”œβ”€β”€ schema.prisma
β”‚   β”œβ”€β”€ .env                 # your DATABASE_URL, etc.
β”‚   └── migrations/          # auto‑generated by `bun prisma migrate`
β”‚
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ config/              # environment/configuration loaders
β”‚   β”‚   └── index.ts         # loads process.env and exports typed config
β”‚   β”‚
β”‚   β”œβ”€β”€ db/                  # database client initialization
β”‚   β”‚   └── client.ts        # `export const prisma = new PrismaClient()`
β”‚   β”‚
β”‚   β”œβ”€β”€ routes/              # Express route definitions
β”‚   β”‚   β”œβ”€β”€ index.ts         # main router that mounts sub‑routers
β”‚   β”‚   β”œβ”€β”€ members.ts
β”‚   β”‚   β”œβ”€β”€ projects.ts
β”‚   β”‚   β”œβ”€β”€ achievements.ts
β”‚   β”‚   β”œβ”€β”€ topics.ts
β”‚   β”‚   β”œβ”€β”€ questions.ts
β”‚   β”‚   β”œβ”€β”€ interviews.ts
β”‚   β”‚   └── progress.ts
β”‚   β”‚
β”‚   β”œβ”€β”€ controllers/         # controllers: take req β†’ call services β†’ send res
β”‚   β”‚   β”œβ”€β”€ member.controller.ts
β”‚   β”‚   β”œβ”€β”€ project.controller.ts
β”‚   β”‚   β”œβ”€β”€ achievement.controller.ts
β”‚   β”‚   β”œβ”€β”€ topic.controller.ts
β”‚   β”‚   β”œβ”€β”€ question.controller.ts
β”‚   β”‚   β”œβ”€β”€ interview.controller.ts
β”‚   β”‚   └── progress.controller.ts
β”‚   β”‚
β”‚   β”œβ”€β”€ services/            # business logic / Prisma queries
β”‚   β”‚   β”œβ”€β”€ member.service.ts
β”‚   β”‚   β”œβ”€β”€ project.service.ts
β”‚   β”‚   β”œβ”€β”€ achievement.service.ts
β”‚   β”‚   β”œβ”€β”€ topic.service.ts
β”‚   β”‚   β”œβ”€β”€ question.service.ts
β”‚   β”‚   β”œβ”€β”€ interview.service.ts
β”‚   β”‚   └── progress.service.ts
β”‚   β”‚
β”‚   β”œβ”€β”€ utils/               # shared helpers (e.g. error wrappers, validators)
β”‚   β”‚   └── apiError.ts
β”‚   β”‚
β”‚   β”œβ”€β”€ app.ts               # configure Express app, mount routes, error handler
β”‚   └── server.ts            # start HTTP server (calls `app.listen`)
β”‚
β”œβ”€β”€ tests/                   # integration and unit tests (Jest or Mocha)
β”‚   β”œβ”€β”€ members.test.ts
β”‚   └── ...
β”‚
β”œβ”€β”€ .env.example             # template for environment variables
β”œβ”€β”€ package.json
└── tsconfig.json            # TypeScript configuration

πŸš€ Getting Started

Prerequisite

  • Install Bun on your machine.

1. Clone the repo

git clone https://github.com/your-org/coding-club-api.git
cd coding-club-api

2. Install dependencies

bun install

3. Configure environment

  • Copy .env.example to .env
  • Update .env with your Supabase/PostgreSQL connection URL and any other variables:

4. Initialize Prisma & Database

bun prisma migrate dev --name init
bun prisma generate

5. Run in development

bun run dev
  • By default, the server listens on http://localhost:3000
  • app.ts sets up your Express instance; server.ts starts the HTTP listener

6. Run tests

bun test

πŸ“¦ Scripts

Command Description
bun run dev Start the dev server with hot reloading
bun prisma migrate dev --name Apply migrations in development
bun prisma generate Generate Prisma client
bun test Run tests (Jest or Mocha)

🀝 Contributing

  1. Fork the repo
  2. Create your feature branch (git checkout -b feature/XYZ)
  3. Commit your changes (git commit -m "feat: add XYZ")
  4. Push to the branch (git push origin feature/XYZ)
  5. Open a Pull Request

πŸ“œ License

GNU General Public License v3.0

Happy coding!