|
1 | 1 | # COC-API |
2 | | -An API for call of code centralized database |
| 2 | + |
| 3 | +This repository contains the Express.js API for our Coding Club backends, backed by PostgreSQL (via Prisma) and Supabase storage. We’re using **Bun** as our runtime. |
| 4 | + |
| 5 | +## 📂 Folder Structure |
| 6 | + |
| 7 | +``` |
| 8 | +/ |
| 9 | +├── prisma/ # Prisma schema and migration files |
| 10 | +│ ├── schema.prisma |
| 11 | +│ ├── .env # your DATABASE_URL, etc. |
| 12 | +│ └── migrations/ # auto‑generated by `bun prisma migrate` |
| 13 | +│ |
| 14 | +├── src/ |
| 15 | +│ ├── config/ # environment/configuration loaders |
| 16 | +│ │ └── index.ts # loads process.env and exports typed config |
| 17 | +│ │ |
| 18 | +│ ├── db/ # database client initialization |
| 19 | +│ │ └── client.ts # `export const prisma = new PrismaClient()` |
| 20 | +│ │ |
| 21 | +│ ├── routes/ # Express route definitions |
| 22 | +│ │ ├── index.ts # main router that mounts sub‑routers |
| 23 | +│ │ ├── members.ts |
| 24 | +│ │ ├── projects.ts |
| 25 | +│ │ ├── achievements.ts |
| 26 | +│ │ ├── topics.ts |
| 27 | +│ │ ├── questions.ts |
| 28 | +│ │ ├── interviews.ts |
| 29 | +│ │ └── progress.ts |
| 30 | +│ │ |
| 31 | +│ ├── controllers/ # controllers: take req → call services → send res |
| 32 | +│ │ ├── member.controller.ts |
| 33 | +│ │ ├── project.controller.ts |
| 34 | +│ │ ├── achievement.controller.ts |
| 35 | +│ │ ├── topic.controller.ts |
| 36 | +│ │ ├── question.controller.ts |
| 37 | +│ │ ├── interview.controller.ts |
| 38 | +│ │ └── progress.controller.ts |
| 39 | +│ │ |
| 40 | +│ ├── services/ # business logic / Prisma queries |
| 41 | +│ │ ├── member.service.ts |
| 42 | +│ │ ├── project.service.ts |
| 43 | +│ │ ├── achievement.service.ts |
| 44 | +│ │ ├── topic.service.ts |
| 45 | +│ │ ├── question.service.ts |
| 46 | +│ │ ├── interview.service.ts |
| 47 | +│ │ └── progress.service.ts |
| 48 | +│ │ |
| 49 | +│ ├── utils/ # shared helpers (e.g. error wrappers, validators) |
| 50 | +│ │ └── apiError.ts |
| 51 | +│ │ |
| 52 | +│ ├── app.ts # configure Express app, mount routes, error handler |
| 53 | +│ └── server.ts # start HTTP server (calls `app.listen`) |
| 54 | +│ |
| 55 | +├── tests/ # integration and unit tests (Jest or Mocha) |
| 56 | +│ ├── members.test.ts |
| 57 | +│ └── ... |
| 58 | +│ |
| 59 | +├── .env.example # template for environment variables |
| 60 | +├── package.json |
| 61 | +└── tsconfig.json # TypeScript configuration |
| 62 | +``` |
| 63 | + |
| 64 | +## 🚀 Getting Started |
| 65 | + |
| 66 | +### Prerequisite |
| 67 | + |
| 68 | +* Install [Bun](https://bun.sh/) on your machine. |
| 69 | + |
| 70 | +### 1. Clone the repo |
| 71 | + |
| 72 | +```bash |
| 73 | +git clone https://github.com/your-org/coding-club-api.git |
| 74 | +cd coding-club-api |
| 75 | +``` |
| 76 | + |
| 77 | +### 2. Install dependencies |
| 78 | + |
| 79 | +```bash |
| 80 | +bun install |
| 81 | +``` |
| 82 | + |
| 83 | +### 3. Configure environment |
| 84 | + |
| 85 | +* Copy `.env.example` to `.env` |
| 86 | +* Update `.env` with your Supabase/PostgreSQL connection URL and any other variables: |
| 87 | + |
| 88 | +### 4. Initialize Prisma & Database |
| 89 | + |
| 90 | +```bash |
| 91 | +bun prisma migrate dev --name init |
| 92 | +bun prisma generate |
| 93 | +``` |
| 94 | + |
| 95 | +### 5. Run in development |
| 96 | + |
| 97 | +```bash |
| 98 | +bun run dev |
| 99 | +``` |
| 100 | + |
| 101 | +* By default, the server listens on `http://localhost:3000` |
| 102 | +* `app.ts` sets up your Express instance; `server.ts` starts the HTTP listener |
| 103 | + |
| 104 | +### 6. Run tests |
| 105 | + |
| 106 | +```bash |
| 107 | +bun test |
| 108 | +``` |
| 109 | + |
| 110 | +## 📦 Scripts |
| 111 | + |
| 112 | +| Command | Description | |
| 113 | +| ------------------------------- | --------------------------------------- | |
| 114 | +| `bun run dev` | Start the dev server with hot reloading | |
| 115 | +| `bun prisma migrate dev --name` | Apply migrations in development | |
| 116 | +| `bun prisma generate` | Generate Prisma client | |
| 117 | +| `bun test` | Run tests (Jest or Mocha) | |
| 118 | + |
| 119 | +--- |
| 120 | + |
| 121 | +## 🤝 Contributing |
| 122 | + |
| 123 | +1. Fork the repo |
| 124 | +2. Create your feature branch (`git checkout -b feature/XYZ`) |
| 125 | +3. Commit your changes (`git commit -m "feat: add XYZ"`) |
| 126 | +4. Push to the branch (`git push origin feature/XYZ`) |
| 127 | +5. Open a Pull Request |
| 128 | + |
| 129 | +--- |
| 130 | + |
| 131 | +## 📜 License |
| 132 | + |
| 133 | +[MIT](LICENSE) |
| 134 | + |
| 135 | +Happy coding! |
0 commit comments