Skip to content

Commit 9b43d44

Browse files
committed
fix(backend): removed useless comment
1 parent 66811b4 commit 9b43d44

File tree

15 files changed

+48
-125
lines changed

15 files changed

+48
-125
lines changed

apps/backend/.gitignore

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Dependencies
1+
22
node_modules/
33
npm-debug.log*
44
yarn-debug.log*
@@ -8,54 +8,52 @@ package-lock.json
88
yarn.lock
99
pnpm-lock.yaml
1010

11-
# Build outputs
1211
dist/
1312
build/
1413
*.tsbuildinfo
1514

16-
# Environment variables
15+
1716
.env
1817
.env.local
1918
.env.*.local
2019
.env.production
2120
.env.development
2221
.env.test
2322

24-
# IDE and editor files
23+
2524
.vscode/
2625
.idea/
2726
*.swp
2827
*.swo
2928
*~
3029
.DS_Store
3130

32-
# Logs
3331
logs/
3432
*.log
3533
npm-debug.log*
3634
yarn-debug.log*
3735
yarn-error.log*
3836
lerna-debug.log*
3937

40-
# Testing
38+
4139
coverage/
4240
.nyc_output/
4341
*.lcov
4442

45-
# Temporary files
43+
4644
tmp/
4745
temp/
4846
*.tmp
4947

50-
# Database
48+
5149
*.db
5250
*.sqlite
5351
*.sqlite3
5452

55-
# OS files
53+
5654
Thumbs.db
5755
.DS_Store
5856

59-
# Drizzle
57+
6058
drizzle/
6159

apps/backend/src/application/use-cases/create-tape.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@ export class CreateTapeUseCase {
1313
* Default: tape "______1", state "A", final "HALT"
1414
*/
1515
async execute(): Promise<{ id: string }> {
16-
// Default unary machine configuration
17-
// Note: Machine halts when no matching transition is found
1816
const defaultTransitions = [
1917
{ currentState: "A", readSymbol: "_", writeSymbol: "_", moveDirection: "R" as const, nextState: "A" },
2018
{ currentState: "A", readSymbol: "1", writeSymbol: "1", moveDirection: "R" as const, nextState: "B" },

apps/backend/src/application/use-cases/execute-step.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,12 @@ export class ExecuteStepUseCase {
1717
* @returns Updated tape record or null if not found
1818
*/
1919
async execute(id: string): Promise<TapeRecord | null> {
20-
// Load tape from database
2120
const record = await this.repository.findById(id);
2221
if (!record) {
2322
return null;
2423
}
2524

26-
// Reconstruct domain objects
25+
2726
const tape = new Tape(record.content, record.headPosition);
2827
const machine = new TuringMachine(
2928
tape,
@@ -32,10 +31,8 @@ export class ExecuteStepUseCase {
3231
record.finalStates
3332
);
3433

35-
// Execute one step
3634
machine.executeStep();
3735

38-
// Save updated state back to database
3936
const updated = await this.repository.update(id, {
4037
content: tape.getContent(),
4138
headPosition: tape.getHeadPosition(),

apps/backend/src/application/use-cases/reset-tape.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export class ResetTapeUseCase {
2323
return null;
2424
}
2525

26-
// Reconstruct domain objects
26+
2727
const tape = new Tape(record.content, record.headPosition);
2828
const machine = new TuringMachine(
2929
tape,
@@ -32,10 +32,8 @@ export class ResetTapeUseCase {
3232
record.finalStates
3333
);
3434

35-
// Reset to initial state using stored initialContent
3635
machine.reset(record.initialContent, 0);
3736

38-
// Save updated state back to database
3937
const updated = await this.repository.update(id, {
4038
content: tape.getContent(),
4139
headPosition: tape.getHeadPosition(),

apps/backend/src/application/use-cases/run-machine.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export class RunMachineUseCase {
3131
return null;
3232
}
3333

34-
// Reconstruct domain objects
34+
3535
const tape = new Tape(record.content, record.headPosition);
3636
const machine = new TuringMachine(
3737
tape,
@@ -40,11 +40,9 @@ export class RunMachineUseCase {
4040
record.finalStates
4141
);
4242

43-
// Execute multiple steps
4443
const maxSteps = options.maxSteps ?? 1000;
4544
const stepsExecuted = machine.run(maxSteps);
4645

47-
// Save updated state back to database
4846
const updated = await this.repository.update(id, {
4947
content: tape.getContent(),
5048
headPosition: tape.getHeadPosition(),

apps/backend/src/domain/tape.ts

Lines changed: 9 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -18,65 +18,47 @@ export class Tape {
1818
this.headPosition = Math.max(0, headPosition);
1919
}
2020

21-
/**
22-
* Reads the symbol at the current head position
23-
* Returns blank "_" if position is out of bounds
24-
*/
21+
2522
read(): string {
2623
if (this.headPosition < 0 || this.headPosition >= this.cells.length) {
2724
return "_";
2825
}
2926
return this.cells[this.headPosition] || "_";
3027
}
3128

32-
/**
33-
* Writes a symbol at the current head position
34-
* Expands the tape if necessary
35-
*/
29+
3630
write(symbol: string): void {
37-
// Expand tape if head is beyond current bounds
3831
while (this.headPosition >= this.cells.length) {
3932
this.cells.push("_");
4033
}
4134
this.cells[this.headPosition] = symbol;
4235
}
4336

44-
/**
45-
* Moves the head left (decrements position)
46-
* Prevents negative positions
47-
*/
37+
4838
moveLeft(): void {
4939
if (this.headPosition > 0) {
5040
this.headPosition--;
5141
}
5242
}
5343

54-
/**
55-
* Moves the head right (increments position)
56-
*/
44+
5745
moveRight(): void {
5846
this.headPosition++;
5947
}
6048

61-
/**
62-
* Gets the current head position
63-
*/
49+
6450
getHeadPosition(): number {
6551
return this.headPosition;
6652
}
6753

68-
/**
69-
* Gets the tape content as a string
70-
*/
54+
7155
getContent(): string {
7256
return this.cells.join("");
7357
}
7458

75-
/**
76-
* Gets the tape content as an array
77-
*/
59+
7860
getCells(): string[] {
79-
return [...this.cells]; // Return defensive copy
61+
return [...this.cells];
8062
}
8163

8264
/**
@@ -89,9 +71,7 @@ export class Tape {
8971
this.headPosition = Math.max(0, headPosition);
9072
}
9173

92-
/**
93-
* Creates a copy of the tape (for immutability patterns)
94-
*/
74+
9575
clone(): Tape {
9676
const cloned = new Tape(this.getContent(), this.headPosition);
9777
return cloned;

apps/backend/src/domain/turing-machine.ts

Lines changed: 17 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@
66

77
import { Tape } from "./tape.js";
88

9-
/**
10-
* Transition rule for the Turing machine
11-
*/
9+
1210
export interface Transition {
1311
currentState: string;
1412
readSymbol: string;
@@ -44,59 +42,50 @@ export class TuringMachine {
4442
this.finalStates = new Set(finalStates);
4543
}
4644

47-
/**
48-
* Gets the current state
49-
*/
45+
5046
getCurrentState(): string {
5147
return this.currentState;
5248
}
5349

54-
/**
55-
* Gets the tape
56-
*/
50+
5751
getTape(): Tape {
5852
return this.tape;
5953
}
6054

61-
/**
62-
* Checks if the machine is in a final state
63-
*/
55+
6456
isInFinalState(): boolean {
6557
return this.finalStates.has(this.currentState);
6658
}
6759

68-
/**
69-
* Executes a single step of the machine
70-
* @returns true if step was executed, false if machine is halted
71-
*/
60+
7261
executeStep(): boolean {
73-
// Check if already in final state
62+
7463
if (this.isInFinalState()) {
7564
return false;
7665
}
7766

78-
// Read current symbol
67+
7968
const readSymbol = this.tape.read();
8069

81-
// Find matching transition
70+
8271
const transition = this.transitions.find(
8372
(t) => t.currentState === this.currentState && t.readSymbol === readSymbol
8473
);
8574

8675
if (!transition) {
87-
// No transition found - machine halts
76+
8877
return false;
8978
}
9079

91-
// Execute transition: write, move, change state
80+
9281
this.tape.write(transition.writeSymbol);
9382

9483
if (transition.moveDirection === "L") {
9584
this.tape.moveLeft();
9685
} else if (transition.moveDirection === "R") {
9786
this.tape.moveRight();
9887
}
99-
// If direction is neither L nor R, don't move (for "no move" behavior)
88+
10089

10190
this.currentState = transition.nextState;
10291

@@ -126,23 +115,19 @@ export class TuringMachine {
126115
this.currentState = this.initialState;
127116
}
128117

129-
/**
130-
* Gets all transitions
131-
*/
118+
119+
120+
132121
getTransitions(): Transition[] {
133-
return [...this.transitions]; // Return defensive copy
122+
return [...this.transitions];
134123
}
135124

136-
/**
137-
* Gets initial state
138-
*/
125+
139126
getInitialState(): string {
140127
return this.initialState;
141128
}
142129

143-
/**
144-
* Gets final states
145-
*/
130+
146131
getFinalStates(): string[] {
147132
return Array.from(this.finalStates);
148133
}

apps/backend/src/index.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,15 @@
1-
/**
2-
* Entry Point
3-
* Starts the Fastify server with database connection
4-
*/
1+
52

63
import { createServer } from "./server.js";
74
import { validateEnv } from "./infrastructure/config/env.js";
85
import { ConfigurationError } from "./domain/errors.js";
96

107
async function start() {
118
try {
12-
// Validate environment variables
139
const config = validateEnv();
1410

15-
// Create and configure server
1611
const server = await createServer(config.DATABASE_URL);
1712

18-
// Start listening
1913
await server.listen({ port: config.PORT, host: config.HOST });
2014

2115
console.log(`Server listening at http://${config.HOST}:${config.PORT}`);

apps/backend/src/infrastructure/config/env.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,8 @@ const envSchema = z.object({
3232
.default("development"),
3333
});
3434

35-
/**
36-
* Validated environment configuration
37-
*/
3835
export type EnvConfig = z.infer<typeof envSchema>;
3936

40-
/**
41-
* Validates and returns environment configuration
42-
* Throws ConfigurationError if validation fails
43-
*/
4437
export function validateEnv(): EnvConfig {
4538
try {
4639
return envSchema.parse({

apps/backend/src/infrastructure/database/client.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,12 @@ import * as schema from "./schema.js";
1010
* @returns Drizzle database instance
1111
*/
1212
export function createDatabaseClient(connectionString: string) {
13-
// Create postgres connection
1413
const queryClient = postgres(connectionString);
1514

16-
// Create Drizzle instance with schema
1715
const db = drizzle(queryClient, { schema });
1816

1917
return db;
2018
}
2119

22-
/**
23-
* Type for the database client
24-
*/
2520
export type DatabaseClient = ReturnType<typeof createDatabaseClient>;
2621

0 commit comments

Comments
 (0)