CASHPOCKET is one TypeScript codebase that serves a browser and a phone. This page lays the system out once: what runs where, how a request is checked, where state lives, how third parties are kept at arm's length, and the decisions behind that shape.
The system on one page

| Component | Technology | Responsibility |
|---|---|---|
| Web client | Next.js App Router, React 19, TypeScript, Tailwind, TanStack Query | Tester, advertiser and admin surfaces, each under its own layout |
| Mobile app | React Native 0.81, Expo 54, React Navigation 7 | Tester surface on iOS and Android, with web views for flows that live on the web |
| Server entry | A custom Node HTTP server in CommonJS | Loads the environment, checks it, refuses unsafe staging boots, then hands requests to Next |
| API routes | Next route handlers under one /api tree | One API for both clients, grouped by domain: account, campaigns, points, payments, notifications, admin |
| Services | TypeScript modules | Point kernel, campaign approval and closure, rewards, notifications, chatbot, ad insights |
| Scheduler | node-cron, started inside the server | Daily and periodic jobs, on one instance |
| Database | MongoDB replica set, Prisma plus the native driver | All durable state. The driver is used where a transaction or a pipeline update is needed |
| Cache | Redis | Account status in front of MongoDB, refresh-token hashes, short locks |
| Media | S3 and CloudFront | Presigned uploads from the client, delivery through the CDN |
| Process manager | pm2 in cluster mode, two instances | Restarts, reloads, memory ceiling |
| Monitoring | Sentry on server, edge, browser and app | Errors tagged by failing provider and route |
The life of a request

Both clients send an access token in the Authorization header. A route verifies the signature, rejects tokens that were issued for another purpose, and then asks a second question that the token cannot answer: is this account still allowed in? An admin may have blocked it a minute ago.
That answer comes from a Redis hash holding the account’s blocked, withdrawn and login-allowed flags, its user type and its role. The request check reads the blocked and login-allowed flags. On a miss the route loads the user from MongoDB and stores the hash for an hour. When an admin blocks an account or converts it to an advertiser, or the user logs out, the entry is deleted, so the next request reads fresh state. The admin checks also require the cached user type to be admin and the withdrawn flag to be clear, then load the admin’s user document from MongoDB.
Refresh works through the same store. The details are in Account checks from Redis, and refresh tokens that rotate.
Two processes, one scheduler
pm2 runs the server in cluster mode with two instances. Both accept requests. Scheduled work is different: a job that pays rewards must run once, so the scheduler is started only by the instance whose id is 0. The other instance skips it at boot.
Most jobs do not contain business logic. They call the server’s own API with a job key, and the route does the work. That keeps one implementation for a job whether a schedule or an admin triggers it, and puts every job behind the same authentication check. Scheduled jobs on one of two instances has the schedule.
Where state lives
MongoDB holds everything durable. It runs as a replica set because multi-document transactions require one, and points need transactions. Most of the application reads and writes through Prisma. The point kernel and the payment routes use the native driver, because they need a session shared across several writes and conditional pipeline updates.
Redis holds nothing that cannot be rebuilt. If it is unreachable the service keeps answering.
Media goes to S3. A client asks the server for a presigned upload URL, which is issued only for an allowed content type and extension and expires in minutes. The server records a tracking row for every file it signs. Files are soft-deleted first and removed for good by a nightly job 30 days later. Images are compressed on the device before upload, and the server slices very tall product-detail images into tiles.
Providers behind adapters
The product depends on many third parties: card payments, bank-account verification, identity verification, KakaoTalk alert messages, SMS, email, push, mobile-coupon issuing, parcel tracking, social logins, social-media data and language models. Each is reached through an adapter, and a policy module decides per service whether the adapter talks to the real provider or to a mock.
The policy forces mocks in tests and in CI, and in staging unless a service is switched on deliberately. A test that checks the S3 adapter asserts that mock mode is refused in production outside CI. The policy is there so that a test run or a staging deploy does not send a real KakaoTalk message, issue a real coupon or move real money.
Observability
Sentry runs in four places: the server, the edge runtime, the browser and the app. On the server a hook strips the authorization and cookie headers before an event leaves, drops the framework’s control-flow errors, and tags each event with the provider that failed and the API route it failed in. An alert therefore names the provider and the route before anyone opens the trace, which is where the incident path on the Delivery page starts.
Logs go through the console to pm2’s log files. In production the console is patched at start-up to mask emails, phone numbers and IP addresses. A health route with no authentication and no database call is what the deploy script polls before it decides whether to keep a release.
Decisions
1. One backend for both clients. A separate API for the app was the alternative. The app calls the same routes as the browser and identifies itself by its user agent. The cost is that the API has to stay compatible with app versions that are already installed. The server therefore keeps answering API paths on the address that shipped apps were built with, while browsers on that address are redirected to the canonical host.
2. A custom server entry. It replaces the framework’s default start command. The entry point validates the environment name against an allow-list and runs a staging guard that refuses to boot a staging server pointed at the production database or Redis. It starts the scheduler only after the HTTP server is listening, and loads it lazily so the monitoring hooks are in place before the database driver is first used.
3. The scheduler inside the server, on instance 0. A separate worker service was the alternative. One deployable unit is simpler to operate for a small team, and the jobs are thin calls into the API. The one-instance rule is what makes that safe.
4. A stored balance with a ledger row in the same transaction. The alternative is a balance computed by summing the ledger. A debit is a single conditional update that states the balance it needs, so the database itself refuses an overdraft. The ledger row records the balance before and after, which lets an audit script compare the stored number with the history. The trade-offs are on the point ledger page.
5. A replica set from the start. Transactions were a requirement of the point design, and MongoDB only offers them on a replica set. The local development stack starts one as well, so the same code path runs on a laptop.
6. Account status from a cache. Claims cannot be revoked, and a database read per request is the most frequent query the system would make. A cached status that is deleted when an admin blocks the account makes the block take effect at the next request, for the price of one Redis read.
7. Adapters with a mock policy. Route code does not call provider SDKs directly. The policy is what allows end-to-end tests, an agent opening a draft fix, and a staging server to run the real code paths without real side effects.
